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

Font Size Mismatch and Minor Discrepancies in egui 0.22.0 #3127

Closed
rustbasic opened this issue Jun 30, 2023 · 4 comments
Closed

Font Size Mismatch and Minor Discrepancies in egui 0.22.0 #3127

rustbasic opened this issue Jun 30, 2023 · 4 comments
Milestone

Comments

@rustbasic
Copy link
Contributor

rustbasic commented Jun 30, 2023

Dear emilk,

In egui 0.21.0, the font size was aligned correctly in TextEdit (multiline) with the following code:

let row_height = ui.fonts(|f| f.row_height(&font_id));

Therefore, it worked well with ui.scroll_with_delta() as well. Additionally, the sizes of TextEdit and ui.label() were aligned properly when using ui.spacing_mut().item_spacing.y = 0.0 with matching font sizes.

However, in egui 0.22.0, there is a significant mismatch in sizes. To mitigate this, I tried the following code to adjust the row height:

let row_height = ui.fonts(|f| f.row_height(&font_id)) + 0.14;

But even with this adjustment, there is still a slight discrepancy in ui.scroll_with_delta() and other functions.

Moreover, in egui 0.22.0, when trying to align the sizes of TextEdit and ui.label(), I used the following code:

let font_id = egui::FontId::monospace( font_size );
let row_height = ui.fonts(|f| f.row_height(&font_id));
ui.spacing_mut().item_spacing.y = row_height * 0.0043;

However, even with this adjustment, there are minor discrepancies in sizes. Please note that you may need to have more than 1000 lines to observe these small discrepancies.

And depending on the font size, the magnitude of the minor discrepancy varies.

Although these discrepancies are very small, they can cause issues in practical applications, even though egui can be used to create simple programs without problems.

If you haven't already addressed these issues, I kindly request you to make the necessary adjustments to resolve them.

Thanks.

@rustbasic
Copy link
Contributor Author

How to fix egui:
(1) row_height() returns the same value as TextEdit, or
Create a new function so you can get the row_height value.
(2) And, make the size of row_height of TextEdit and row_height of ui.label().

I create a function to get row_height directly in my program,
I solved it by using ui.add_sized() in ui.label().

@emilk
Copy link
Owner

emilk commented Aug 10, 2023

This is likely an effect of #2724

@emilk emilk added this to the 0.23.0 milestone Aug 10, 2023
@emilk
Copy link
Owner

emilk commented Aug 12, 2023

The height of a row of text is not fixed, but depends on the characters in it. If you want to know the sizes of the rows in the TextEdit, use TextEditOutput::galley. There you will find all the rows of text and where they are.

@emilk emilk closed this as completed Aug 12, 2023
@rustbasic
Copy link
Contributor Author

The height of a row of text is not fixed, but depends on the characters in it. If you want to know the sizes of the rows in the TextEdit, use TextEditOutput::galley. There you will find all the rows of text and where they are.

Thanks emilk.
I solved it the way you told me.

    content.editor_row_height_vec.clear();
    for i in 0..output.galley.rows.len() {
        content.editor_row_height_vec.push( output.galley.rows[i].height() );
    }

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

2 participants