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

Give TextEdit a min_size and a gap, via a shared LayoutStyle

`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) <noreply@anthropic.com>
This commit is contained in:
Lucas Meurer
2026-08-25 10:40:35 +02:00
parent 0fb7875251
commit a3ffa117ac
2 changed files with 11 additions and 0 deletions

View File

@@ -156,6 +156,10 @@ impl StyleProvider<TextEditStyle> 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()
},

View File

@@ -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)