1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 13:50:04 -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 a9315ea8ba
commit c9af1d12e3
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

@@ -101,6 +101,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 {
@@ -112,7 +115,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);

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:17b27f7233fcdff6dd3c024048555254d43ef757e221f43a949dce15811aec4c
size 101376
oid sha256:6264f32d3323d0d499ba0da9d379e562c06a7f50930dbec424039549ce7f50f9
size 101414

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7ba5217ee5c79b94aaf1536b3df9cd644e6211f7fa32915d518c899f43f811bd
size 76762
oid sha256:6df3c0a298d48a5f2e1b36207909e20ea545a72a97461a3ae0792d21e0554f93
size 76567

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:77aab95cb94e59200ef783fe155b73d93934144694e8c1486ca14eff526506e1
size 100793
oid sha256:611b18575d2768d40b89f28427bd987d90393e886da2a2c4e09ea6503f85acdd
size 100303

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:999582994fc04dce17ceede45e1026c1079af6e8d95cef923d1a0c5d329ebe86
size 26324
oid sha256:68351659df756ce331a4eeb147be8d1b4fed39dbbb54a0d6f685997b54dc07a7
size 26327

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:da51643768d29df05ed33544899514b5cf0bcb4a5da2bbdd42098cf910948e79
size 118822
oid sha256:ad81eeb593663cb26295e7fc51987b85a7084b32504e26364f54f9c2129cb790
size 118048

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:361d8aa66ceea5608ea33f527d3fad3b297d3420a1938765e353e99b059b1ccf
size 62344
oid sha256:ccac475bb38e76dc044d34f0a48e73b61e9d4734d02105c5635e02bcdaa19c63
size 62104

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:293a8c23ffe0522b97e3544de20e15b754f99a438acf3de84cb32c8b9c84105c
oid sha256:a62ed81b1693cd7eea2099c0840d82318d27e382f88ca1dd15ba9e2a59e3cf4b
size 46677

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1612ad2e668247778d23007cf941f25bfcbca6e05af60ac1729516efb133766e
size 88492
oid sha256:d9139bb87beac6bdb91f0e48f5cabba61ca7ba5344a8fcefd094d2efb98e7056
size 88246

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a93ba134a073ae4bae85351b6976fee3cda91fb0d989c6d0937b75794f3b9a3f
size 120580
oid sha256:5ad40e8b41882e3456569c8cb2e831d33fafa910989674e05b20568798528154
size 120579

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d7dd3f32d27da6539b722f525b7f4c332a1fbb1b991103ae5e487cbb0989d358
size 53035
oid sha256:a596437f8274a87525ce107f94d6c8394166c3aa26d06737f1abdc2ae894f77b
size 52790

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:fdcf88cd4d1d74035491898679350d7e7ce097d4709e04ee5de2cff66b7948be
size 56227
oid sha256:001c89ba338b51d48f1e471e17306e84e74b0f952a856b65532ffeacbf52f2cb
size 55982

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:66c36df9e3c80e282ab393cc8b94548657fc07e18bacf1cd7af144bd0d2242d7
size 56711
oid sha256:bf299c3c52250b1a17411e3e1aef57a4293787c9a9777da6fda01bb6a0e387c1
size 56466

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9268448bc552683af44bb7e6377b490fba1c6f41243407f8939e34f9af51689e
size 37596
oid sha256:ea03f6b0e0071910cf2b4279549fb0347cd6a9f8d0334830ce4f34f5824a1ef9
size 37595

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7781e5da0fe0ebf9d0966e61b2d880cd8160c606209cfa5a1793acce209248e7
size 37616
oid sha256:db4795c68fffb20f74d46664be9b7c4bfcaf941a8b3e27a7315f9525dd90d5c4
size 37340

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1310b73a60026639619f18d19e43833410b103658e17c86a45cf90933d78a146
size 66046
oid sha256:952df0869c400d8b1f5dc0a33cb7a8be1fa30d91929e57b7c33af0cfbc9cead4
size 66043

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5dad86ee015f57b1f146af10a60ba7c1e072bde7a5d77711c2de0df9bc001a9d
size 153591
oid sha256:066067e34d47aa8d2631e64b2ea37d94bae77bdfb1af9337f34f724e1ff14cb6
size 153589

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b6d9a1ccee0d91e358115726bfb0f91d9b7e9913be4b58a7cc65641a9a014ebd
size 60816
oid sha256:0d79861c18cbaf2f2ab738d0a5633f354c11a52b8a8e87c623e624ecdfcc6965
size 60813

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:693fc1cc1705b9cae330300060359c72901679aff10fc10f0870065e7e3210d4
size 148238
oid sha256:cde27ba5614f4bd5553d609b23e6dd78aea113c88443de42fa47aa85929c9455
size 148235