Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrolling to a particular line in a TextEdit is very awkward #5588

Open
JohnEmhoff opened this issue Jan 6, 2025 · 0 comments
Open

Scrolling to a particular line in a TextEdit is very awkward #5588

JohnEmhoff opened this issue Jan 6, 2025 · 0 comments

Comments

@JohnEmhoff
Copy link

JohnEmhoff commented Jan 6, 2025

Is your feature request related to a problem? Please describe.
It is somewhat awkward to programmatically scroll a large multiline TextEdit to a specific line. After some head scratching and looking through the text layout code, I came up with this:

let line_height = egui::Context::fonts(ui.ctx(), |f| {
    f.row_height(&egui::TextStyle::Monospace.resolve(ui.style()))
});
let pixels_per_point = ui.ctx().pixels_per_point();
let rounded_line_height = (line_height * pixels_per_point).round() / pixels_per_point;
let offset = rounded_line_height * scroll_to_line_number;

The issue is that the developer needs to exactly, precisely reproduce how the layout code works -- tiny errors become big errors when scrolling to a large enough offset.

Describe the solution you'd like
It would be nice if a TextEdit had a scroll_to_line() method or something similar.

Describe alternatives you've considered
Is there currently a simpler way to accomplish what I wrote above? I certainly might have missed a method that would give me the pixel-perfect line height for a font, for example.

Additional context
<3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant