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

Add Frame::expand_in_place, Frame::invisible and TextVisuals constructors

The expansion/stroke correction on a widget's margins was written out by
hand. Move it into `Frame::expand_in_place`, which knows the frame's own
stroke width, so a caller states the intent instead of the arithmetic.
`Frame::invisible` goes with it: a frame that keeps its layout but drops
its paint.

Two fixes fall out of it in the button style:

* A small button zeroed its vertical padding after the correction, which
  left the frame a `stroke.width - expansion` tall. Zeroing before the
  correction makes it exactly zero in every state, which is what "must
  not add any height" means.
* The invisible frame of a button that hides its frame when inactive
  dropped the outer margin and the stroke width, so it was not, in fact,
  as big as the painted one. It now keeps the whole frame and only drops
  the paint.

Also give `TextVisuals` a `new` and a `from_widget_visuals`, replacing the
local `text_visuals` helper, and add `HasClasses::add_classes` and
`HasClasses::with_classes`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lucas Meurer
2026-08-31 13:49:10 +02:00
parent 2c856e335d
commit 64470b2d40
5 changed files with 85 additions and 36 deletions

View File

@@ -65,11 +65,8 @@ impl StyleProvider<ButtonStyle> for MyTheme {
.fill(fill)
.corner_radius(self.corner_radius)
.inner_margin(8),
text_style: TextVisuals {
color: Color32::WHITE,
// Resolve the font from the style, so we follow the user's font sizes:
font_id: TextStyle::Button.resolve(style),
},
// Resolve the font from the style, so we follow the user's font sizes:
text_style: TextVisuals::new(style, TextStyle::Button, Color32::WHITE),
}
}
}