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

Text size is smaller than it should be #2068

Closed
emilk opened this issue Sep 21, 2022 · 1 comment · Fixed by #2069
Closed

Text size is smaller than it should be #2068

emilk opened this issue Sep 21, 2022 · 1 comment · Fixed by #2069
Labels
bug Something is broken text Problems related to text

Comments

@emilk
Copy link
Owner

emilk commented Sep 21, 2022

Here is Ubuntu-Light (the default egui font) in the official Mac Font Book app (upper) and in egui (lower):

Screen Shot 2022-09-21 at 16 02 57

The text in egui is obviously much smaller, even though both should be size 12.


Repro:

use eframe::egui;

fn main() {
    let options = eframe::NativeOptions::default();
    eframe::run_native(
        "Font test",
        options,
        Box::new(|_cc| Box::new(MyApp::default())),
    );
}

#[derive(Default)]
struct MyApp {}

impl eframe::App for MyApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(ctx, |ui| {
            for size in [12, 16, 24] {
                ui.horizontal(|ui| {
                    ui.monospace(format!("{size}px"));
                    ui.label(
                        egui::RichText::from(
                            "The quick brown fox jumps over the lazy dog and runs away.",
                        )
                        .size(size as f32)
                        .color(egui::Color32::WHITE),
                    )
                });
            }
        });
    }
}
@emilk emilk added bug Something is broken text Problems related to text labels Sep 21, 2022
@emilk
Copy link
Owner Author

emilk commented Sep 21, 2022

emilk added a commit that referenced this issue Sep 21, 2022
Closes #2068

Before this PR, the default font, Ubuntu-Light, was ~11% smaller
than it should have been, and the default monospace font, Hack,
was ~14% smaller. This means that setting the font size `12` in egui
would yield smaller text than using that font size in any other app.
Ooops!

The change is that this PR now takes into account the ttf properties
`units_per_em` and `height_unscaled`.

If your egui application has specified you own font sizes or text styles
you will see the text in your application grow
larger, unless you go in and compensate by dividing all font sizes by
~1.21 for Ubuntu-Light/Proportional and ~1.16 for Hack/Monospace,
and with something else if you are using a custom font!
This effects any use of `FontId`, `RichText::size`, etc.

This PR changes the default `Style::text_styles` to compensate,
so the default egui style should look the same before and after this PR.
emilk added a commit that referenced this issue Sep 21, 2022
Closes #2068

Before this PR, the default font, Ubuntu-Light, was ~11% smaller
than it should have been, and the default monospace font, Hack,
was ~14% smaller. This means that setting the font size `12` in egui
would yield smaller text than using that font size in any other app.
Ooops!

The change is that this PR now takes into account the ttf properties
`units_per_em` and `height_unscaled`.

If your egui application has specified you own font sizes or text styles
you will see the text in your application grow
larger, unless you go in and compensate by dividing all font sizes by
~1.21 for Ubuntu-Light/Proportional and ~1.16 for Hack/Monospace,
and with something else if you are using a custom font!
This effects any use of `FontId`, `RichText::size`, etc.

This PR changes the default `Style::text_styles` to compensate,
so the default egui style should look the same before and after this PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken text Problems related to text
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant