From b3bd1897a4d7c83ae17dd0e288eb4ad602d0e1b9 Mon Sep 17 00:00:00 2001 From: aiongg Date: Wed, 11 Nov 2026 21:45:17 +0000 Subject: [PATCH] Overview: a settled card repaints its last run Each card sits in a settling Lazy inside its row: a settled frame of the Overview runs no card. Lazy::settles notes that a settled reader needs a binding that stays in place between frames. --- crates/ui-contract/src/contract/lazy.rs | 4 ++++ crates/ui-gallery/src/chrome/overview.rs | 19 ++++++++++++------- crates/ui-gallery/tests/it/overview.rs | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/crates/ui-contract/src/contract/lazy.rs b/crates/ui-contract/src/contract/lazy.rs index 6bbde21fe..121d98f97 100644 --- a/crates/ui-contract/src/contract/lazy.rs +++ b/crates/ui-contract/src/contract/lazy.rs @@ -66,6 +66,10 @@ impl Lazy { /// - the frame or the one before had input other than pointer motion, the app asked for a repaint, or a given /// value was edited: the framework cannot see which children show plain app data, so every child runs then; /// - its last run showed an overlay or painted on another layer. + /// + /// A bound value is known by where it lives, so a settled reader needs a binding that stays in place between + /// frames: a value copied into a local each frame and bound there is a new place each frame, and an edit of it + /// does not reach the reader until the next frame with input. pub fn settles(mut self, settles: bool) -> Lazy { self.settles = settles; self diff --git a/crates/ui-gallery/src/chrome/overview.rs b/crates/ui-gallery/src/chrome/overview.rs index 5794848c5..089f9419f 100644 --- a/crates/ui-gallery/src/chrome/overview.rs +++ b/crates/ui-gallery/src/chrome/overview.rs @@ -143,8 +143,9 @@ pub(super) fn on_background(ui: &mut Ui, key: &str, mut add: impl FnMut(&mut Ui, .show(ui, &mut ()); } -/// The cards in one or two columns, scrolling vertically; each row is as tall as its tallest card. A card out of view -/// does not run (`Lazy`); the card of the component `reveal` names glides to the top of the view. The selected card of +/// The cards in one or two columns, scrolling vertically; each row is as tall as its tallest card. A row out of view +/// does not run (`Lazy`), and a settled card in view repaints its last run (`Lazy::settles`); the card of the component +/// `reveal` names glides to the top of the view. The selected card of /// `tab` is inspected while the inspector is on. The cards report into `reported`. pub(super) fn grid( ui: &mut Ui, @@ -171,11 +172,15 @@ pub(super) fn grid( Lazy::new((generation, columns, keys), estimate).reveal(revealed).show(ui, |ui| { Grid::new(if columns == 1 { ONE } else { TWO }).gap(Gap::CardColumn).fill_width().show(ui, |ui, _| { for (at, spec) in chunk.iter().enumerate() { - let stories = spec.card_stories(); - let mut card = spec.card(&stories, format!("{}-{generation}", spec.key), room); - card.inspect = p.inspect.of(tab, spec.selected); - let events = card.show(ui, p.cells); - reported.push(Reported { spec: row * columns + at, events }); + // A settled card repaints its last run; a card that does not run reports nothing, as it took + // no press and ran no command. + Lazy::new((generation, spec.key.as_str()), spec.estimate()).settles(true).show(ui, |ui| { + let stories = spec.card_stories(); + let mut card = spec.card(&stories, format!("{}-{generation}", spec.key), room); + card.inspect = p.inspect.of(tab, spec.selected); + let events = card.show(ui, p.cells); + reported.push(Reported { spec: row * columns + at, events }); + }); } }); }); diff --git a/crates/ui-gallery/tests/it/overview.rs b/crates/ui-gallery/tests/it/overview.rs index b57af0738..4f76849e4 100644 --- a/crates/ui-gallery/tests/it/overview.rs +++ b/crates/ui-gallery/tests/it/overview.rs @@ -128,6 +128,24 @@ fn a_settled_form_rows_card_runs_one_pass_per_frame() { } } +/// A settled card repaints its last run: a settled frame of the Slider cards runs no Slider and no card chrome, and still +/// shows the Maximum story's value text. +#[trial] +fn a_settled_overview_card_runs_no_component() { + let mut gallery = gallery_filtered("Controls", "Slider"); + let mut fixture = Fixture::new(move |ui| gallery.ui(ui)); + fixture.room(Vec2::new(1400.0, 900.0)).settle(); + for frame in 0..4 { + fixture.idle(1); + let runs = last_pass_runs(fixture.ctx()); + // Type names carry their generics: the path before them names the component. + let named = |ty: &str, name: &str| ty.split('<').next().is_some_and(|path| path.ends_with(name)); + let card: Vec<_> = runs.iter().filter(|(ty, _)| ["::Slider", "::Panel", "::TitleRow"].iter().any(|name| named(ty, name))).collect(); + assert!(card.is_empty(), "settled frame {frame} ran the card: {card:?}"); + assert!(painted(&fixture, "100.0"), "settled frame {frame} shows the Maximum story's value text"); + } +} + /// The registered type name of the component listed as `name`. fn type_of(name: &str) -> &'static str { Catalog::linked().components.iter().find(|component| component.name == name).unwrap_or_else(|| panic!("{name} is listed")).type_name