mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 14:20:04 -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:
@@ -157,6 +157,10 @@ impl StyleProvider<TextEditStyle> for DefaultStyle {
|
|||||||
outer_margin: Margin::same(-(widget_visuals.expansion as i8)),
|
outer_margin: Margin::same(-(widget_visuals.expansion as i8)),
|
||||||
..Default::default()
|
..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,
|
text_style: text,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -494,12 +494,18 @@ impl TextEdit<'_> {
|
|||||||
atom_layout:
|
atom_layout:
|
||||||
AtomLayoutStyle {
|
AtomLayoutStyle {
|
||||||
frame: styled_frame,
|
frame: styled_frame,
|
||||||
|
min_size: style_min_size,
|
||||||
|
gap,
|
||||||
text_style: text_visuals,
|
text_style: text_visuals,
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
hint_text_color,
|
hint_text_color,
|
||||||
} = ui.widget_style(id, &classes);
|
} = 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
|
let text_color = text_color
|
||||||
.or_else(|| ui.visuals().override_text_color)
|
.or_else(|| ui.visuals().override_text_color)
|
||||||
.unwrap_or(text_visuals.color);
|
.unwrap_or(text_visuals.color);
|
||||||
@@ -743,6 +749,7 @@ impl TextEdit<'_> {
|
|||||||
|
|
||||||
let allocated = AtomLayout::new(atoms)
|
let allocated = AtomLayout::new(atoms)
|
||||||
.id(id)
|
.id(id)
|
||||||
|
.fallback_gap(gap)
|
||||||
.min_size(Vec2::new(allocate_width, min_height.at_least(min_size.y)))
|
.min_size(Vec2::new(allocate_width, min_height.at_least(min_size.y)))
|
||||||
.max_width(allocate_width)
|
.max_width(allocate_width)
|
||||||
.sense(sense)
|
.sense(sense)
|
||||||
|
|||||||
Reference in New Issue
Block a user