1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 06:10:06 -04:00

Fix text sizes being too small (#2069)

Closes https://github.com/emilk/egui/issues/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.
This commit is contained in:
Emil Ernerfeldt
2022-09-21 21:31:08 +02:00
committed by GitHub
parent 990a8c8b44
commit 29fa63317e
14 changed files with 87 additions and 65 deletions

View File

@@ -14,7 +14,7 @@ pub fn font_family_ui(ui: &mut Ui, font_family: &mut FontFamily) {
pub fn font_id_ui(ui: &mut Ui, font_id: &mut FontId) {
let families = ui.fonts().families();
ui.horizontal(|ui| {
ui.add(Slider::new(&mut font_id.size, 4.0..=40.0).max_decimals(0));
ui.add(Slider::new(&mut font_id.size, 4.0..=40.0).max_decimals(1));
for alternative in families {
let text = alternative.to_string();
ui.radio_value(&mut font_id.family, alternative, text);

View File

@@ -213,7 +213,7 @@ impl Painter {
rect.min,
Align2::LEFT_TOP,
text.to_string(),
FontId::monospace(14.0),
FontId::monospace(12.0),
color,
);
}
@@ -232,7 +232,7 @@ impl Painter {
color: Color32,
text: impl ToString,
) -> Rect {
let galley = self.layout_no_wrap(text.to_string(), FontId::monospace(14.0), color);
let galley = self.layout_no_wrap(text.to_string(), FontId::monospace(12.0), color);
let rect = anchor.anchor_rect(Rect::from_min_size(pos, galley.size()));
let frame_rect = rect.expand(2.0);
self.add(Shape::rect_filled(

View File

@@ -602,25 +602,16 @@ pub struct DebugOptions {
/// The default text styles of the default egui theme.
pub fn default_text_styles() -> BTreeMap<TextStyle, FontId> {
let mut text_styles = BTreeMap::new();
text_styles.insert(
TextStyle::Small,
FontId::new(10.0, FontFamily::Proportional),
);
text_styles.insert(TextStyle::Body, FontId::new(14.0, FontFamily::Proportional));
text_styles.insert(
TextStyle::Button,
FontId::new(14.0, FontFamily::Proportional),
);
text_styles.insert(
TextStyle::Heading,
FontId::new(20.0, FontFamily::Proportional),
);
text_styles.insert(
TextStyle::Monospace,
FontId::new(14.0, FontFamily::Monospace),
);
text_styles
use FontFamily::{Monospace, Proportional};
[
(TextStyle::Small, FontId::new(9.0, Proportional)),
(TextStyle::Body, FontId::new(12.5, Proportional)),
(TextStyle::Button, FontId::new(12.5, Proportional)),
(TextStyle::Heading, FontId::new(18.0, Proportional)),
(TextStyle::Monospace, FontId::new(12.0, Monospace)),
]
.into()
}
impl Default for Style {