From 7f30623cff45d91f4fd025aa25bd472442e49e71 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 2 Aug 2026 12:25:32 -0700 Subject: [PATCH] Add `WidgetText::size` (#8377) ## Summary - Add `WidgetText::size` for sizing plain, rich, and layout-job text uniformly. - Preserve already-laid-out galleys. ## Test - `cargo clippy -p egui --all-features --all-targets` - `cargo test -p egui --all-features` * [x] I have followed the instructions in the PR template --- crates/egui/src/widget_text.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/egui/src/widget_text.rs b/crates/egui/src/widget_text.rs index 8670398fa..37018c0b2 100644 --- a/crates/egui/src/widget_text.rs +++ b/crates/egui/src/widget_text.rs @@ -558,6 +558,25 @@ impl Default for WidgetText { } impl WidgetText { + /// Override the font size. + /// + /// For [`Self::Galley`], this does nothing because it has already been laid out. + #[must_use] + pub fn size(self, size: f32) -> Self { + match self { + Self::Text(text) => RichText::new(text).size(size).into(), + Self::RichText(text) => Self::RichText(Arc::new(Arc::unwrap_or_clone(text).size(size))), + Self::LayoutJob(job) => { + let mut job = Arc::unwrap_or_clone(job); + for section in &mut job.sections { + section.format.font_id.size = size; + } + Self::LayoutJob(Arc::new(job)) + } + Self::Galley(galley) => Self::Galley(galley), + } + } + #[inline] pub fn is_empty(&self) -> bool { match self {