Skip to content

Commit d468565

Browse files
committed
Improve default font height based on #5809
1 parent d2e18fe commit d468565

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

crates/egui/src/widget_layout.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::{Frame, Id, Image, Response, Sense, Style, TextStyle, Ui, Widget, WidgetText};
1+
use crate::{
2+
FontSelection, Frame, Id, Image, Response, Sense, Style, TextStyle, Ui, Widget, WidgetText,
3+
};
24
use ahash::HashMap;
35
use emath::{Align2, NumExt, Rect, Vec2};
46
use epaint::{Color32, Fonts, Galley};
@@ -112,6 +114,12 @@ impl<'a> WidgetLayout<'a> {
112114
preferred_width += gap_space;
113115
}
114116

117+
let default_font_height = || {
118+
let font_selection = FontSelection::default();
119+
let font_id = font_selection.resolve(ui.style());
120+
ui.fonts(|f| f.row_height(&font_id))
121+
};
122+
115123
let max_font_size = ui
116124
.fonts(|fonts| {
117125
atomics
@@ -120,7 +128,7 @@ impl<'a> WidgetLayout<'a> {
120128
.filter_map(|a| a.get_min_height_for_image(fonts, ui.style()))
121129
.max_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal))
122130
})
123-
.unwrap_or_else(|| ui.text_style_height(&TextStyle::Body));
131+
.unwrap_or_else(default_font_height);
124132

125133
for ((idx, item)) in atomics.0.into_iter().enumerate() {
126134
if item.shrink {

0 commit comments

Comments
 (0)