From d468565e5605b31d15f2178aae39621406c3ecf4 Mon Sep 17 00:00:00 2001 From: lucasmerlin Date: Thu, 17 Apr 2025 00:00:44 +0200 Subject: [PATCH] Improve default font height based on https://github.com/emilk/egui/pull/5809 --- crates/egui/src/widget_layout.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/egui/src/widget_layout.rs b/crates/egui/src/widget_layout.rs index 6a8bc3912..b77e4a7df 100644 --- a/crates/egui/src/widget_layout.rs +++ b/crates/egui/src/widget_layout.rs @@ -1,4 +1,6 @@ -use crate::{Frame, Id, Image, Response, Sense, Style, TextStyle, Ui, Widget, WidgetText}; +use crate::{ + FontSelection, Frame, Id, Image, Response, Sense, Style, TextStyle, Ui, Widget, WidgetText, +}; use ahash::HashMap; use emath::{Align2, NumExt, Rect, Vec2}; use epaint::{Color32, Fonts, Galley}; @@ -112,6 +114,12 @@ impl<'a> WidgetLayout<'a> { preferred_width += gap_space; } + let default_font_height = || { + let font_selection = FontSelection::default(); + let font_id = font_selection.resolve(ui.style()); + ui.fonts(|f| f.row_height(&font_id)) + }; + let max_font_size = ui .fonts(|fonts| { atomics @@ -120,7 +128,7 @@ impl<'a> WidgetLayout<'a> { .filter_map(|a| a.get_min_height_for_image(fonts, ui.style())) .max_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal)) }) - .unwrap_or_else(|| ui.text_style_height(&TextStyle::Body)); + .unwrap_or_else(default_font_height); for ((idx, item)) in atomics.0.into_iter().enumerate() { if item.shrink {