From 336f9a69d1ea8ef61eb5d01edcc1421e245feeed Mon Sep 17 00:00:00 2001 From: Lucas Meurer Date: Tue, 25 Aug 2026 10:40:35 +0200 Subject: [PATCH] Give TextEdit a min_size and a gap, via a shared LayoutStyle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `ButtonStyle` carried a `min_size` and a gap; `TextEditStyle` carried neither, so a themed text edit could set its padding but not its height or the gap to its prefix — the height had to travel separately on the widget, and the gap fell back to the ambient `spacing.icon_spacing`. A theme decides the two together, so they move into a `LayoutStyle` that both styles embed. `TextEdit` now honors both, with defaults that keep today's rendering: no floor of egui's own, and the gap `AtomLayout` was already falling back to. Co-Authored-By: Claude Opus 5 (1M context) --- crates/egui/src/theme/default_style.rs | 4 ++++ crates/egui/src/widgets/text_edit/builder.rs | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/crates/egui/src/theme/default_style.rs b/crates/egui/src/theme/default_style.rs index 8c6e2cc21..e4cb8d9d3 100644 --- a/crates/egui/src/theme/default_style.rs +++ b/crates/egui/src/theme/default_style.rs @@ -157,6 +157,10 @@ impl StyleProvider for DefaultStyle { outer_margin: Margin::same(-(widget_visuals.expansion as i8)), ..Default::default() }, + // A text edit sizes itself from the rows it holds; egui's own theme adds no floor + // of its own. + min_size: Vec2::ZERO, + gap: style.spacing.icon_spacing, text_style: text, ..Default::default() }, diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index 3742d4b75..66c08e6c2 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -494,12 +494,18 @@ impl TextEdit<'_> { atom_layout: AtomLayoutStyle { frame: styled_frame, + min_size: style_min_size, + gap, text_style: text_visuals, .. }, hint_text_color, } = ui.widget_style(id, &classes); + // The theme sets a floor on the size; the builder's own `min_size` can only raise it, + // the same way it does for a button. + let min_size = min_size.max(style_min_size); + let text_color = text_color .or_else(|| ui.visuals().override_text_color) .unwrap_or(text_visuals.color); @@ -743,6 +749,7 @@ impl TextEdit<'_> { let allocated = AtomLayout::new(atoms) .id(id) + .fallback_gap(gap) .min_size(Vec2::new(allocate_width, min_height.at_least(min_size.y))) .max_width(allocate_width) .sense(sense)