Overview: a row out of view does not run

Each row of the Overview's grid is a Lazy child of the scroll body, keyed by
its cards and the column count, so only the rows in view run their Grid and
cards. The per-card Lazy goes. A card's Panel takes its id from the card's
key, so a change of the column count keeps each card's state.

Trial: a settled pass of a short view runs as many Grids for the whole
Controls level as for a filter that lists the same cards in view.
This commit is contained in:
aiongg
2026-11-12 14:32:40 +00:00
parent 86f91ac95d
commit af4791df71
3 changed files with 61 additions and 12 deletions
+3
View File
@@ -137,7 +137,10 @@ impl Card<'_> {
// A story on the card's own surface sits inside the card's padding; any other surface runs edge to edge under the
// header band.
let pad = if self.surface == Surface::Panel { Pad::Regular } else { Pad::None };
// Its id comes from its key, not from its place: a change of the column count regroups the cards, and each
// keeps its state and its stories' ids.
let mut panel = Panel::new(self.title.to_owned())
.id(craft_ui::testing::memory::global("gallery.card", &self.key))
.sizing(Sizing::Fill)
.command_scope(CardCommands::SCOPE)
.selected(self.selected)
+13 -12
View File
@@ -22,9 +22,9 @@ use egui::Ui;
/// story drawn in less is no longer what the apps show.
const CARD_MIN_WIDTH: f32 = 290.0;
/// A card's height before it ran, for the cards out of view (`Lazy`'s estimate): its header band, and a story row
/// as tall as a story of one control under its caption. Cards in view run, so the guess only places the cards past
/// them until those scroll in.
/// A card's height before it ran, for the rows out of view (`Lazy`'s estimate is the tallest of the row's): its header
/// band, and a story row as tall as a story of one control under its caption. Rows in view run, so the guess only
/// places the rows past them until those scroll in.
const HEADER_GUESS: f32 = 48.0;
const STORY_ROW_GUESS: f32 = 120.0;
@@ -163,20 +163,21 @@ pub(super) fn grid(
Stack::new().fill().scroll(Scroll::vertical()).gap(Gap::CardRow).id_salt(scroll_id).show(ui, |ui, _| {
reported.clear();
for (row, chunk) in cards.chunks(columns).enumerate() {
Grid::new(if columns == 1 { ONE } else { TWO }).gap(Gap::CardColumn).fill_width().show(ui, |ui, _| {
for (at, spec) in chunk.iter().enumerate() {
// Keyed by the card alone: a change of the column count regroups the rows, and the cards out of
// view keep their extents.
let lazy = Lazy::new((generation, spec.key.as_str()), spec.estimate()).reveal(reveal == Some(spec.type_name));
lazy.show(ui, |ui| {
// A row out of view does not run. Keyed by its cards: a change of the column count regroups the rows into
// new ones, which take their estimate until they run.
let keys: Vec<&str> = chunk.iter().map(|spec| spec.key.as_str()).collect();
let estimate = chunk.iter().map(Spec::estimate).fold(0.0, f32::max);
let revealed = chunk.iter().any(|spec| reveal == Some(spec.type_name));
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();
// Each card is its own id scope: a story's `id_salt` and auto ids must not meet another card's.
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 });
});
}
}
});
});
}
});
+45
View File
@@ -69,6 +69,51 @@ fn a_settled_overview_pass_runs_no_shell_per_story() {
assert_eq!(all, one, "the shell regions grow with the stories in view: {one} with the Slider cards, {all} with the level");
}
/// The `Grid` runs and the cards run (their `Open` buttons) of a settled Overview pass in a view as tall as `height`.
fn grid_runs(level: &str, filter: &str, height: f32) -> (u32, usize) {
let mut gallery = gallery_filtered(level, filter);
let mut fixture = Fixture::new(move |ui| gallery.ui(ui));
fixture.room(Vec2::new(1400.0, height)).settle().idle(1);
let grids = last_pass_runs(fixture.ctx()).iter().filter(|(ty, _)| ty.ends_with("::Grid")).map(|(_, runs)| runs).sum();
let opens = fixture.by_role(Role::BUTTON).into_iter().filter(|button| fixture.tree().name_of(button.node) == Some("Open")).count();
(grids, opens)
}
/// The cards of `level` that `filter` lists, in the Overview's order.
fn listed(level: &str, filter: &str) -> Vec<String> {
let catalog = Catalog::linked();
by_level(&catalog, filter)
.into_iter()
.find(|(at, _)| at.title() == level)
.map_or_else(Vec::new, |(_, cards)| cards.into_iter().map(|component| component.name.clone()).collect())
}
/// A row of the Overview out of view does not run: a settled pass of a short view runs as many `Grid`s for the whole
/// Controls level as for a filter that lists the same cards in view and fewer rows after them.
#[trial]
fn a_settled_overview_pass_runs_no_row_out_of_view() {
const HEIGHT: f32 = 220.0;
let level = listed("Controls", "");
let (all, in_view) = grid_runs("Controls", "", HEIGHT);
assert!((1..level.len()).contains(&in_view), "the view shows some of the level's {} cards, not {in_view}", level.len());
// The filter: the part of the first card's name that every card in view matches too, and that lists the fewest
// cards. The level is in name order, so the filter lists the cards in view first.
let first = level[0].to_lowercase();
let filter = (0..first.len())
.flat_map(|start| (start + 2..=first.len()).map(move |end| (start, end)))
.filter_map(|(start, end)| first.get(start..end))
.map(|part| (part, listed("Controls", part)))
.filter(|(_, cards)| cards.len() >= in_view && cards[..in_view] == level[..in_view])
.min_by_key(|(_, cards)| cards.len())
.map(|(part, _)| part.to_owned())
.unwrap_or_else(|| panic!("a part of {first:?} lists the {in_view} cards in view first"));
let fewer = listed("Controls", &filter).len();
assert!(fewer < level.len(), "the filter {filter:?} lists fewer cards than the level: {fewer} of {}", level.len());
let (some, some_in_view) = grid_runs("Controls", &filter, HEIGHT);
assert_eq!(in_view, some_in_view, "the level and the filter {filter:?} run the same cards");
assert_eq!(all, some, "the Grid runs grow with the rows out of view: {some} with {fewer} cards, {all} with {}", level.len());
}
/// A card in form rows shows each story's value text beside it, as the story's run found it: a settled frame of the
/// Slider card, whose bodies take their kept measurements in place of running the stories, runs one pass.
#[trial]