1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 14:50:03 -04:00

Don't let AtomLayoutStyle override a per-widget atom gap

`AtomLayout::gap` is an `Option`, where `None` means "use the theme value".
`AtomLayoutStyle::apply` set it unconditionally, so it clobbered the gap a
widget had asked for. `DragValue` sets `gap(0.0)` to keep its prefix, value and
suffix flush, and lost it, which widened every `DragValue` in the demos.

`apply` now fills the gap in only when the widget left it unset. This also
reverts the snapshot updates that had captured the wider gap.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lucas Meurer
2026-08-31 10:32:29 +02:00
parent 81ab7ab77b
commit 1d755e7906
20 changed files with 49 additions and 36 deletions

View File

@@ -107,6 +107,16 @@ impl<'a> AtomLayout<'a> {
self
}
/// Set the gap between atoms, unless the caller already set one.
///
/// Used to apply a [`crate::widget_style::AtomLayoutStyle`] without overriding a per-widget
/// [`Self::gap`].
#[inline]
pub(crate) fn gap_if_unset(mut self, gap: f32) -> Self {
self.gap = self.gap.or(Some(gap));
self
}
/// Set the [`Frame`].
#[inline]
pub fn frame(mut self, frame: Frame) -> Self {

View File

@@ -92,6 +92,9 @@ impl Default for AtomLayoutStyle {
impl AtomLayoutStyle {
/// Apply this style to an [`AtomLayout`].
///
/// A per-widget [`AtomLayout::gap`] wins over [`Self::gap`], so widgets like
/// [`crate::DragValue`] can pack their atoms tighter than the theme does.
pub fn apply<'a>(&self, mut layout: AtomLayout<'a>) -> AtomLayout<'a> {
layout.map_images(|image| {
if image.image_options().tint == Color32::WHITE {
@@ -103,7 +106,7 @@ impl AtomLayoutStyle {
let layout = layout
.min_size(self.min_size)
.gap(self.gap)
.gap_if_unset(self.gap)
.frame(self.frame)
.fallback_font(self.text_style.font_id.clone())
.fallback_text_color(self.text_style.color);