diff --git a/crates/ui-contract/src/contract/body.rs b/crates/ui-contract/src/contract/body.rs index d9bc3efb85..3e988a0551 100644 --- a/crates/ui-contract/src/contract/body.rs +++ b/crates/ui-contract/src/contract/body.rs @@ -88,6 +88,9 @@ pub(super) struct BodyHooks<'b> { /// The scroll position named by content, kept with an offset the framework holds (`ScrollState`). anchor: Option, anchor_at_read: Option, + /// The glide to a revealed `Lazy` child, kept with the offset (`ScrollState`). + glide: Option, + glide_at_read: Option, scroll_bound: bool, moved: bool, last: BodyView, @@ -153,6 +156,8 @@ impl<'b> BodyHooks<'b> { view_offset: ScrollPos::default(), anchor: None, anchor_at_read: None, + glide: None, + glide_at_read: None, scroll_bound: false, moved: false, last: BodyView::default(), diff --git a/crates/ui-contract/src/contract/body/hooks.rs b/crates/ui-contract/src/contract/body/hooks.rs index 247f9d5252..346897c7e5 100644 --- a/crates/ui-contract/src/contract/body/hooks.rs +++ b/crates/ui-contract/src/contract/body/hooks.rs @@ -8,7 +8,7 @@ use super::regions::{ shared_line, }; use super::reorder::REORDER_BAND; -use super::scroll::{Jumps, ScrollState, follow_anchor, jump_frame, overflow_inset, scroll_of}; +use super::scroll::{Glide, Jumps, ScrollState, aim_glide, follow_anchor, jump_frame, overflow_inset, scroll_of}; use super::window::{WindowMode, os_window, window_instance}; use super::{BodyHooks, BodyView}; use crate::contract::cx::{BodyCx, BodyOwner}; @@ -20,7 +20,7 @@ use crate::primitives::SurfaceSlot; use crate::runtime::access::scope; use crate::runtime::access::{self, Politeness, Role}; use crate::runtime::commands; -use crate::runtime::egui::{alloc, areas, child, response, style, viewports}; +use crate::runtime::egui::{alloc, areas, child, repaint, response, style, viewports}; use crate::runtime::env::{AppValues, ArenaId, Env}; use crate::runtime::focus::FocusPolicy; use crate::runtime::memory::{MemoryStage, sub}; @@ -243,6 +243,29 @@ impl ShapeHooks for BodyHooks<'_> { self.moved = true; } } + // A move of the area's own ends a glide; a child reveal starts one. A running glide moves the offset toward + // its aim. + self.glide = if self.moved { None } else { stage.session::(sub(id, "scroll")).glide }; + if let Some(child) = crate::contract::child_reveal(&ctx, id, quiet) { + self.glide = Some(Glide { child, to: None, running: false }); + } + self.glide_at_read = self.glide; + if let Some(glide) = self.glide.as_mut() + && let Some(to) = glide.to + && (glide.running || !quiet) + { + let driver = Driver { stage: &*stage, base: id, policy: env.motion }; + if !glide.running { + driver.jump("glide", Vec2::new(self.offset.x as f32, self.offset.y as f32)); + glide.running = true; + } + let at = driver.anim("glide", to, spec::FOLLOW); + self.offset = ScrollPos { x: f64::from(at.x), y: f64::from(at.y) }; + self.moved = true; + if at == to { + self.glide = None; + } + } let follows = stage.session::(sub(id, "scroll")).follow_end.unwrap_or(true); self.follows_end = scroll.anchor == crate::contract::ScrollAnchor::End && follows; if self.follows_end && !self.moved { @@ -789,6 +812,7 @@ impl ShapeHooks for BodyHooks<'_> { axes: (scroll.horizontal_on(), scroll.vertical_on()), rtl, anchor: self.anchor.map(|anchor| anchor.child), + reveal: self.glide.map(|glide| glide.child), }; // Only the run that lays the content out for the view places its children; a measure lays it // out for its own question. @@ -804,14 +828,19 @@ impl ShapeHooks for BodyHooks<'_> { Env::restore(&ctx, region_env); let extent = region_ui.min_rect().size(); if lays_out { + let placed = crate::runtime::lazy::placed(&ctx, id); let keeps = !self.scroll_bound && !self.follows_end; follow_anchor( &ctx, - (id, scroll, keeps), + (&placed, scroll, keeps), (extent, seen.size()), (&mut self.offset, self.offset_at_read), &mut self.anchor, ); + aim_glide(&mut self.glide, placed.reveal, shown, (extent, seen.size()), scroll); + if self.glide.is_some_and(|glide| glide.to != Some(Vec2::new(shown.x as f32, shown.y as f32))) { + repaint::request(&ctx); + } } if real { crate::runtime::egui::widgets::note_scroll_region(&ctx, region_ui.clip_rect(), region_ui.min_rect().intersect(max)); @@ -1020,6 +1049,10 @@ impl ShapeHooks for BodyHooks<'_> { self.offset_at_read = self.offset; self.anchor_at_read = self.anchor; } + if self.glide != self.glide_at_read { + cx.core.memory.session::(sub(cx.core.id, "scroll")).glide = self.glide; + self.glide_at_read = self.glide; + } } fn record(&mut self, stage: &mut MemoryStage, ctx: &Context, id: Id) { diff --git a/crates/ui-contract/src/contract/body/scroll.rs b/crates/ui-contract/src/contract/body/scroll.rs index 7966a0fba8..2875a63410 100644 --- a/crates/ui-contract/src/contract/body/scroll.rs +++ b/crates/ui-contract/src/contract/body/scroll.rs @@ -28,11 +28,23 @@ pub(super) struct ScrollState { pub(super) follow_end: Option, /// The same position named by content: the offset follows it while extents before its child change. pub(super) anchor: Option, + /// The glide to a `Lazy` child a reveal asked for, until the offset reaches it or something else moves it. + pub(super) glide: Option, /// The content's extent from the last run that laid it out: it bounds the offset, so it is kept as long, a hidden /// body's included. pub(super) extent: (f32, f32), } +/// A glide of the offset to the `Lazy` child `child` (`Lazy::reveal`). `to` is the offset that puts the child at the +/// view's start, from the last real run that placed it; it moves while extents before the child resolve, so the +/// offset follows it (`spec::FOLLOW`). `running` once the glide's tween started from the offset shown. +#[derive(Clone, Copy, Debug, PartialEq)] +pub(super) struct Glide { + pub(super) child: Id, + pub(super) to: Option, + pub(super) running: bool, +} + /// The offsets `scroll_input` moved scroll bodies to, with the frame that queued each, for step 4 of each body's next /// pass. An entry no body took in that frame or the next belongs to a body that is no longer shown: it is dropped. #[derive(Default)] @@ -62,17 +74,16 @@ pub(super) fn scroll_of(props: &ContainerProps) -> Option { props.scroll.or_else(|| overlay_of(props).filter(|overlay| overlay.body_scroll).map(|_| Scroll::vertical())) } -/// After the real run of the scroll body `id` laid out content of `extent` behind a view of `view`: the anchor rule -/// (`lazy::follow`) moves the offset, and the pass runs again at it. A body that `keeps` no anchor (its offset is bound -/// to the app, or it follows its end) has none. +/// After the real run of a scroll body laid out content of `extent` behind a view of `view`, from what its children +/// reported (`placed`): the anchor rule (`lazy::follow`) moves the offset, and the pass runs again at it. A body that +/// `keeps` no anchor (its offset is bound to the app, or it follows its end) has none. pub(super) fn follow_anchor( ctx: &Context, - (id, scroll, keeps): (Id, Scroll, bool), + (placed, scroll, keeps): (&lazy::Placed, Scroll, bool), (extent, view): (Vec2, Vec2), (offset, read): (&mut ScrollPos, ScrollPos), anchor: &mut Option, ) { - let placed = lazy::placed(ctx, id); if !keeps { *anchor = None; return; @@ -81,7 +92,7 @@ pub(super) fn follow_anchor( let moved = Vec2::new(short(offset.x - read.x), short(offset.y - read.y)); let back = Vec2::new(short(offset.x), short(offset.y)); let ahead = (extent - view) - back; - if let Some(shift) = lazy::follow(anchor, &placed, moved, view, (back, ahead), (scroll.horizontal_on(), scroll.vertical_on())) { + if let Some(shift) = lazy::follow(anchor, placed, moved, view, (back, ahead), (scroll.horizontal_on(), scroll.vertical_on())) { offset.x += f64::from(shift.x); offset.y += f64::from(shift.y); sizing::request_discard(ctx, sizing::Rerun::Layout); @@ -245,3 +256,20 @@ impl<'b> BodyHooks<'b> { } } } + +/// After the real run of a scroll body that glides: the offset that puts the glide's child at the view's start, from +/// its place in this run (`at`, from the view shown at `shown`), within the offsets the content allows. A run that did +/// not reach the child ends the glide. +pub(super) fn aim_glide(glide: &mut Option, at: Option, shown: ScrollPos, (extent, view): (Vec2, Vec2), scroll: Scroll) { + let Some(aim) = glide.as_mut() else { return }; + let Some(at) = at else { + *glide = None; + return; + }; + let most = (extent - view).max(Vec2::ZERO); + let to = Vec2::new( + if scroll.horizontal_on() { (shown.x as f32 + at.x).clamp(0.0, most.x) } else { shown.x as f32 }, + if scroll.vertical_on() { (shown.y as f32 + at.y).clamp(0.0, most.y) } else { shown.y as f32 }, + ); + aim.to = Some(to); +} diff --git a/crates/ui-contract/src/contract/lazy.rs b/crates/ui-contract/src/contract/lazy.rs index 0612f4146f..4616d12a0d 100644 --- a/crates/ui-contract/src/contract/lazy.rs +++ b/crates/ui-contract/src/contract/lazy.rs @@ -14,9 +14,9 @@ use std::hash::Hash; /// extent it had in the last pass that showed it, at any room, and its stops from that pass keep their place in Tab /// order. A child no pass showed yet takes its estimate: that long along the axes the area scrolls and nothing across /// them, as a collection places the rows it never built by its item layout's estimate. It runs when that extent -/// meets the view, while one of the stops of its last run holds keyboard focus or is the target of a focus request, -/// and when `keep` asks. Content that was never shown has no stops to find: Tab reaches it once it was shown, and a -/// child an app focuses or scrolls to before it was ever in view needs `keep`. Outside a scroll area it always runs. +/// meets the view, and while one of the stops of its last run holds keyboard focus or is the target of a focus +/// request. Content that was never shown has no stops to find: Tab reaches it once it was shown, and an app brings +/// it into view with `reveal`. Outside a scroll area it always runs. /// /// It is a child in flow of its body. In a `Grid` or spread `Row` body it holds one cell: its content is the one child /// in flow that takes the cell, and out of view it takes the cell at its remembered extent, so the cell's row counts @@ -29,7 +29,7 @@ use std::hash::Hash; pub struct Lazy { key: u64, estimate: f32, - keep: bool, + reveal: bool, } impl Lazy { @@ -39,12 +39,14 @@ impl Lazy { use std::hash::Hasher; let mut hasher = std::collections::hash_map::DefaultHasher::new(); key.hash(&mut hasher); - Lazy { key: hasher.finish(), estimate, keep: false } + Lazy { key: hasher.finish(), estimate, reveal: false } } - /// Runs the child out of view too, while `keep` holds: the target of a scroll the app asks for. - pub fn keep(mut self, keep: bool) -> Lazy { - self.keep = keep; + /// When `reveal` holds, the scroll area glides until the child starts at the view's start (as far as the + /// content lets it), whether or not the child ran yet: a request of the pass that sets it, as an app's jump to + /// an item is. A wheel, drag or other move of the area ends the glide. + pub fn reveal(mut self, reveal: bool) -> Lazy { + self.reveal = reveal; self } @@ -69,7 +71,10 @@ impl Lazy { Rect::from_min_size(Pos2::new(x, available.min.y), size) }; let estimate = view.estimate(self.estimate); - if let Decision::Skip(size) = lazy::decide(&ctx, id, &view, at, sizing, self.keep, estimate) { + if self.reveal { + crate::contract::queue_child_reveal(&ctx, view.owner, id); + } + if let Decision::Skip(size) = lazy::decide(&ctx, id, &view, at, sizing, estimate) { let (took, _) = take_in_flow(ui, size); if real { layout_memory::backstop(&ctx, id, size); diff --git a/crates/ui-contract/src/contract/mod.rs b/crates/ui-contract/src/contract/mod.rs index 4c7a7f2e63..fa02b69302 100644 --- a/crates/ui-contract/src/contract/mod.rs +++ b/crates/ui-contract/src/contract/mod.rs @@ -115,7 +115,7 @@ pub(crate) use run::measure_under; pub(crate) use steps::keeping_ids; #[cfg(feature = "testing")] pub(crate) use steps::queue_reveal; -pub(crate) use steps::{peek_reveal, take_reveal}; +pub(crate) use steps::{child_reveal, peek_reveal, queue_child_reveal, take_reveal}; /// Adds the runtime to `ctx`: `runtime::install` with the overlay host's ghost-layer painter in the end hook. pub fn install(ctx: &egui::Context, spec: crate::runtime::InstallSpec) -> Result<(), crate::runtime::InstallError> { diff --git a/crates/ui-contract/src/contract/steps.rs b/crates/ui-contract/src/contract/steps.rs index 79b74bc7c6..ee4961e050 100644 --- a/crates/ui-contract/src/contract/steps.rs +++ b/crates/ui-contract/src/contract/steps.rs @@ -36,7 +36,7 @@ pub(crate) use place::place; pub(crate) use report::{ReportIn, report, report_inert}; #[cfg(feature = "testing")] pub(crate) use scroll_owner::queue_reveal; -pub(crate) use scroll_owner::{peek_reveal, peek_scroll_moves, take_reveal, take_scroll_moves}; +pub(crate) use scroll_owner::{child_reveal, peek_reveal, peek_scroll_moves, queue_child_reveal, take_reveal, take_scroll_moves}; pub(crate) use sense::{part_state, register_wheel}; pub(crate) use settle::settle; pub(crate) use state::{register_reset, state}; diff --git a/crates/ui-contract/src/contract/steps/scroll_owner.rs b/crates/ui-contract/src/contract/steps/scroll_owner.rs index 2a8aafde81..35d62b89bb 100644 --- a/crates/ui-contract/src/contract/steps/scroll_owner.rs +++ b/crates/ui-contract/src/contract/steps/scroll_owner.rs @@ -22,38 +22,76 @@ pub(super) fn route_to_scroll_owner(core: &mut CxCore<'_>) { let Some(owner) = core.env.scroll_owner().or_else(|| wheel::nearest_scroll_owner(&core.ctx, core.rect)) else { return }; pass_state::with::(&core.ctx, |queue| queue.0.extend(moves.into_iter().map(|mv| (owner, mv)))); if reveal { - pass_state::with::(&core.ctx, |reveals| reveals.0.push(Reveal { owner, rect: core.rect })); + pass_state::with::(&core.ctx, |reveals| reveals.0.push(Reveal { owner, to: RevealTo::Rect(core.rect) })); } repaint::request(&core.ctx); } -/// A request to bring a rect into view, read by the scroll owner that step 4 of its next pass names. +/// A request to bring something into view, read by the scroll owner that step 4 of its next pass names. #[derive(Clone, Copy, Debug, PartialEq)] pub(crate) struct Reveal { pub owner: Id, - pub rect: Rect, + pub to: RevealTo, +} + +/// What a reveal brings into view. +#[derive(Clone, Copy, Debug, PartialEq)] +pub(crate) enum RevealTo { + /// A rect, by the least move that shows it, at once: a focused or AccessKit-shown component. + Rect(Rect), + /// A `Lazy` child of the owner's body, by its id: the body glides until the child starts at the view's start. + Child(Id), } #[derive(Default)] pub(crate) struct Reveals(pub(super) Vec); -/// The reveal request addressed to `owner`, once. +/// The rect reveal addressed to `owner`, once. pub(crate) fn take_reveal(ctx: &Context, owner: Id) -> Option { pass_state::with::(ctx, |reveals| { - let at = reveals.0.iter().position(|reveal| reveal.owner == owner)?; - Some(reveals.0.remove(at).rect) + let at = reveals.0.iter().position(|reveal| reveal.owner == owner && matches!(reveal.to, RevealTo::Rect(_)))?; + match reveals.0.remove(at).to { + RevealTo::Rect(rect) => Some(rect), + RevealTo::Child(_) => None, + } }) } /// Queues a reveal request for `owner`. #[cfg(feature = "testing")] pub(crate) fn queue_reveal(ctx: &Context, owner: Id, rect: Rect) { - pass_state::with::(ctx, |reveals| reveals.0.push(Reveal { owner, rect })); + pass_state::with::(ctx, |reveals| reveals.0.push(Reveal { owner, to: RevealTo::Rect(rect) })); } -/// The reveal request addressed to `owner`, left queued. +/// The rect reveal addressed to `owner`, left queued. pub(crate) fn peek_reveal(ctx: &Context, owner: Id) -> Option { - pass_state::with::(ctx, |reveals| reveals.0.iter().find(|reveal| reveal.owner == owner).map(|reveal| reveal.rect)) + pass_state::with::(ctx, |reveals| { + reveals.0.iter().find_map(|reveal| match reveal.to { + RevealTo::Rect(rect) if reveal.owner == owner => Some(rect), + _ => None, + }) + }) +} + +/// Asks the scroll body `owner` to bring its `Lazy` child `child` to the view's start; a later request replaces it. +pub(crate) fn queue_child_reveal(ctx: &Context, owner: Id, child: Id) { + pass_state::with::(ctx, |reveals| { + reveals.0.retain(|reveal| !(reveal.owner == owner && matches!(reveal.to, RevealTo::Child(_)))); + reveals.0.push(Reveal { owner, to: RevealTo::Child(child) }); + }); + repaint::request(ctx); +} + +/// The child reveal addressed to `owner`: taken, or left queued when `quiet`. +pub(crate) fn child_reveal(ctx: &Context, owner: Id, quiet: bool) -> Option { + pass_state::with::(ctx, |reveals| { + let at = reveals.0.iter().position(|reveal| reveal.owner == owner && matches!(reveal.to, RevealTo::Child(_)))?; + let reveal = if quiet { reveals.0[at] } else { reveals.0.remove(at) }; + match reveal.to { + RevealTo::Child(child) => Some(child), + RevealTo::Rect(_) => None, + } + }) } /// A page or end move a focused component left untaken, addressed to the scroll owner around it (9.2 rule 5). diff --git a/crates/ui-contract/src/contract/steps/settle.rs b/crates/ui-contract/src/contract/steps/settle.rs index 6521add5c2..62c34e211b 100644 --- a/crates/ui-contract/src/contract/steps/settle.rs +++ b/crates/ui-contract/src/contract/steps/settle.rs @@ -1,7 +1,7 @@ //! Step 15, settle. use super::apply::{ValueEdit, apply_values}; -use super::scroll_owner::{Reveal, Reveals}; +use super::scroll_owner::{Reveal, RevealTo, Reveals}; use crate::contract::{Component, Cx, ValueOf}; use crate::runtime::egui::repaint; use crate::runtime::focus::{self}; @@ -28,7 +28,7 @@ pub(crate) fn settle(comp: &mut C, cx: &mut Cx<'_, C>) -> ValueEdi if let Some(rect) = cx.core.reveal.take() && let Some(owner) = cx.core.env.scroll_owner().or_else(|| wheel::nearest_scroll_owner(&cx.core.ctx, rect)) { - pass_state::with::(&cx.core.ctx, |reveals| reveals.0.push(Reveal { owner, rect })); + pass_state::with::(&cx.core.ctx, |reveals| reveals.0.push(Reveal { owner, to: RevealTo::Rect(rect) })); repaint::request(&cx.core.ctx); } edit diff --git a/crates/ui-contract/src/runtime/lazy.rs b/crates/ui-contract/src/runtime/lazy.rs index 3135a608aa..ed10b6c4bd 100644 --- a/crates/ui-contract/src/runtime/lazy.rs +++ b/crates/ui-contract/src/runtime/lazy.rs @@ -30,6 +30,8 @@ pub(crate) struct View { pub(crate) rtl: bool, /// The child the area's scroll position names. pub(crate) anchor: Option, + /// The child the area glides to (`Lazy::reveal`). + pub(crate) reveal: Option, } impl View { @@ -62,6 +64,8 @@ pub(crate) struct Placed { pub(crate) anchor: Option<(Vec2, Vec2)>, /// The first child, in flow order, that starts at or after the view's start, and its place. pub(crate) first: Option<(Id, Vec2)>, + /// The place of the child the area glides to, when the run reached it. + pub(crate) reveal: Option, } impl Placed { @@ -146,10 +150,10 @@ fn with(ctx: &Context, f: impl FnOnce(&mut Store, u64, u64) -> R) -> R { } /// Decides whether the child `id`, whose content starts at `at` in this run, runs this pass. It runs when its extent -/// placed at `at` meets the view, when one of its stops holds focus or is the target of a focus request, or when -/// `keep` asks for it. Its extent is the one a run showed it at, else `estimate`. The first run of a pass decides; -/// every later run of the pass gets the same answer, so a measuring run and the real run lay out the same children. -pub(crate) fn decide(ctx: &Context, id: Id, view: &View, at: impl FnOnce(Vec2) -> Rect, sizing: bool, keep: bool, estimate: Vec2) -> Decision { +/// placed at `at` meets the view, or when one of its stops holds focus or is the target of a focus request. Its +/// extent is the one a run showed it at, else `estimate`. The first run of a pass decides; every later run of the +/// pass gets the same answer, so a measuring run and the real run lay out the same children. +pub(crate) fn decide(ctx: &Context, id: Id, view: &View, at: impl FnOnce(Vec2) -> Rect, sizing: bool, estimate: Vec2) -> Decision { let targets = crate::runtime::focus::targets(ctx); with(ctx, |store, pass_nr, frame| { let entry = store.touch(view.owner, id, frame); @@ -160,7 +164,7 @@ pub(crate) fn decide(ctx: &Context, id: Id, view: &View, at: impl FnOnce(Vec2) - Some((decided_in, skip)) if decided_in == pass_nr => skip, _ => { let focus = entry.focus.stop_ids().any(|stop| targets.contains(&Some(stop))); - let skip = !keep && !focus && !at(size).intersects(view.rect); + let skip = !focus && !at(size).intersects(view.rect); entry.decided = Some((pass_nr, skip)); skip } @@ -224,6 +228,9 @@ pub(crate) fn place(ctx: &Context, view: &View, id: Id, rect: Rect) { with(ctx, |store, _, _| { if let Some(placed) = store.placed.get_mut(&view.owner) { placed.note((view.anchor, view.axes), id, at, rect.size()); + if view.reveal == Some(id) { + placed.reveal = Some(at); + } } }); } diff --git a/crates/ui-contract/src/runtime/motion.rs b/crates/ui-contract/src/runtime/motion.rs index d7211a2824..dabc3d7777 100644 --- a/crates/ui-contract/src/runtime/motion.rs +++ b/crates/ui-contract/src/runtime/motion.rs @@ -328,7 +328,12 @@ impl Driver<'_> { tween = Tween::at(target); } else { if tween.target() != target { - tween.retarget(target, now); + // A follow steps from its last evaluation toward wherever its target is now; restarting its clock + // would hold it still for a frame each time the target moves. + match spec.curve { + Curve::Tween => tween.retarget(target, now), + Curve::Follow => tween.to = target, + } } tween.step(now, spec.motion(&self.policy), spec.curve); } diff --git a/crates/ui-gallery/src/chrome/card.rs b/crates/ui-gallery/src/chrome/card.rs index 58a4f479b6..b3d8ec08f4 100644 --- a/crates/ui-gallery/src/chrome/card.rs +++ b/crates/ui-gallery/src/chrome/card.rs @@ -112,8 +112,6 @@ pub struct CardEvents { pub reset: bool, /// Use was run. pub used: bool, - /// The card's rect. - pub rect: Option, } /// The narrowest a column of stories may be, as the old gallery's story grids kept their cases. @@ -155,7 +153,7 @@ impl Card<'_> { if away { commands.push(HeaderCommand::new(IconId::new("undo"), CardCommands::Reset).size(ControlSize::Sm)); } - let shown = panel.commands(commands).show(ui, |ui, cx| { + panel.commands(commands).show(ui, |ui, cx| { while let Some((command, _)) = cx.take_command::() { match command { CardCommands::Open => events.opened = true, @@ -166,7 +164,6 @@ impl Card<'_> { events.pressed |= cx.surface_pressed(); self.stories_in(ui, cells); }); - events.rect = Some(shown.response.rect); events } diff --git a/crates/ui-gallery/src/chrome/overview.rs b/crates/ui-gallery/src/chrome/overview.rs index e5106d0f9e..182c0d07b1 100644 --- a/crates/ui-gallery/src/chrome/overview.rs +++ b/crates/ui-gallery/src/chrome/overview.rs @@ -16,7 +16,7 @@ use craft_ui::runtime::env::WindowKey; use craft_ui::shell::AppShell; use craft_ui::style::SurfaceKind; use craft_ui::testing::StoryRegistration; -use egui::{Align, Ui}; +use egui::Ui; /// The narrowest a card may be before the cards go to one column: a dock panel of the apps is about this wide, and a /// story drawn in less is no longer what the apps show. @@ -143,13 +143,15 @@ pub(super) fn on_background(ui: &mut Ui, key: &str, mut add: impl FnMut(&mut Ui, } /// 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`), except the one the selection scrolls to. The cards report into `reported`. +/// does not run (`Lazy`); the card of the component `reveal` names glides to the top of the view. The cards report +/// into `reported`. pub(super) fn grid( ui: &mut Ui, scroll_id: impl std::hash::Hash + std::fmt::Debug, cards: &[Spec], p: &mut Panels<'_>, one_column: bool, + reveal: Option<&'static str>, ) -> Vec { let mut reported = Vec::new(); let columns = if one_column || ui.available_width() < 2.0 * CARD_MIN_WIDTH { 1 } else { 2 }; @@ -161,10 +163,10 @@ pub(super) fn grid( 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() { - let target = *p.scroll_to == Some(spec.type_name); // Keyed by the card alone: a change of the column count regroups the rows, and the cards out of // view keep their extents. - Lazy::new((generation, spec.key.as_str()), spec.estimate()).keep(target).show(ui, |ui| { + let lazy = Lazy::new((generation, spec.key.as_str()), spec.estimate()).reveal(reveal == Some(spec.type_name)); + lazy.show(ui, |ui| { 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 events = spec.card(&stories, format!("{}-{generation}", spec.key), room).show(ui, p.cells); @@ -178,11 +180,8 @@ pub(super) fn grid( } /// Applies what the cards reported: a press selects the card's component and picks the card's first story unless the -/// picked one is on the card, Open -/// opens its tab, Reset gives the card's stories their start values. -pub(super) fn apply(ui: &mut Ui, p: &mut Panels<'_>, cards: &[Spec], reported: Vec) { - let scroll = *p.scroll_to; - let mut scrolled = false; +/// picked one is on the card, Open opens its tab, Reset gives the card's stories their start values. +pub(super) fn apply(p: &mut Panels<'_>, cards: &[Spec], reported: Vec) { for Reported { spec, events } in reported { let Some(spec) = cards.get(spec) else { continue }; if events.reset { @@ -203,32 +202,20 @@ pub(super) fn apply(ui: &mut Ui, p: &mut Panels<'_>, cards: &[Spec], reported: V p.story_of.insert(spec.type_name, first.story.story.name); } } - if scroll == Some(spec.type_name) - && let Some(rect) = events.rect - { - ui.scroll_to_rect(rect, Some(Align::TOP)); - scrolled = true; - } - } - if scrolled { - *p.scroll_to = None; } } -/// The level the selected component sits on, and a request to bring its card into view, when the selection changed -/// since the last pass of the Overview. -fn follow_selection(p: &mut Panels<'_>) { +/// The selection, when it changed since the Overview's cards last followed it, and its component's level as the shown +/// one. +fn follow_selection(p: &mut Panels<'_>) -> Option> { let selected = selected_type(p); if *p.followed == Some(selected) { - return; + return None; } - *p.followed = Some(selected); - if let Some(type_name) = selected - && let Some(entry) = entry_of(type_name) - { + if let Some(entry) = selected.and_then(entry_of) { *p.level = entry.level.title().to_owned(); - *p.scroll_to = Some(type_name); } + Some(selected) } /// The Overview: the level select over the cards of the level's components. @@ -236,7 +223,7 @@ pub(super) fn overview(ui: &mut Ui, p: &mut Panels<'_>) { if variants::show(ui, p, PanelId::Overview) { return; } - follow_selection(p); + let follow = follow_selection(p); let groups = by_level(p.catalog, p.filter); let Some(shown) = groups.iter().position(|(level, _)| level.title() == p.level.as_str()).or(if groups.is_empty() { None } else { Some(0) }) else { @@ -251,17 +238,23 @@ pub(super) fn overview(ui: &mut Ui, p: &mut Panels<'_>) { let cards: Vec = groups[shown].1.iter().filter_map(|component| component_card(p, component, selected)).collect(); let mut chosen = level; let mut reported = Vec::new(); + // The cards follow the selection in the pass they run: its card glides into view, and only then is it followed. + let mut ran = false; on_background(ui, "overview", |ui, _| { + ran = true; Row::new().show(ui, |ui, _| { Text::new("Level:").shade(Shade::Muted).show(ui); Select::new("Level", Bind::bound(&mut chosen), &entries).show(ui); }); - reported = grid(ui, level.title(), &cards, p, false); + reported = grid(ui, level.title(), &cards, p, false, follow.flatten()); }); + if ran && let Some(selected) = follow { + *p.followed = Some(selected); + } if chosen != level { *p.level = chosen.title().to_owned(); } - apply(ui, p, &cards, reported); + apply(p, &cards, reported); } /// The stories of group `group` of the component registered as `type_name`, under their captions. @@ -340,6 +333,6 @@ pub(super) fn component_tab(ui: &mut Ui, p: &mut Panels<'_>, type_name: &'static }) .collect(); let mut reported = Vec::new(); - on_background(ui, "component", |ui, _| reported = grid(ui, ("component", type_name), &cards, p, true)); - apply(ui, p, &cards, reported); + on_background(ui, "component", |ui, _| reported = grid(ui, ("component", type_name), &cards, p, true, None)); + apply(p, &cards, reported); } diff --git a/crates/ui-gallery/src/chrome/panels.rs b/crates/ui-gallery/src/chrome/panels.rs index 82a36a814b..1c23153f66 100644 --- a/crates/ui-gallery/src/chrome/panels.rs +++ b/crates/ui-gallery/src/chrome/panels.rs @@ -39,9 +39,7 @@ pub struct Panels<'a> { pub cells: &'a mut Cells, /// The component whose tab the tree asked to open in this pass. pub open_request: &'a mut Option<&'static str>, - /// The component whose card the Overview brings into view when it is drawn. - pub scroll_to: &'a mut Option<&'static str>, - /// The selected component the Overview last followed to its level. + /// The selection the Overview's cards last followed. pub followed: &'a mut Option>, /// The selected component the tree last opened the level of. pub tree_seen: &'a mut Option>, diff --git a/crates/ui-gallery/src/chrome/shell.rs b/crates/ui-gallery/src/chrome/shell.rs index ebdda80e77..5f961a7ff2 100644 --- a/crates/ui-gallery/src/chrome/shell.rs +++ b/crates/ui-gallery/src/chrome/shell.rs @@ -78,8 +78,7 @@ fn body(ui: &mut Ui, _: &mut BodyCx<'_>, viewer: &mut Viewer) { let Viewer { env, workspace, preview, browser, themes, theme_dock, mock, variants, variants_tab, .. } = viewer; let subject = ThemeSubject::new(theme_of(&env.theme), env.appearance(ui.ctx())); let in_theme = *workspace == Workspace::Theme; - let Browser { catalog, filter, selection, open, dock, story_of, generation, cells, open_request, scroll_to, followed, tree_seen, level, .. } = - browser; + let Browser { catalog, filter, selection, open, dock, story_of, generation, cells, open_request, followed, tree_seen, level, .. } = browser; let dock: &mut Dock<_> = if in_theme { theme_dock } else { dock }; let panels = Panels { catalog, @@ -89,7 +88,6 @@ fn body(ui: &mut Ui, _: &mut BodyCx<'_>, viewer: &mut Viewer) { story_of, cells, open_request, - scroll_to, followed, tree_seen, generation: *generation, diff --git a/crates/ui-gallery/src/chrome/variants.rs b/crates/ui-gallery/src/chrome/variants.rs index bc8d1059a9..975d79b399 100644 --- a/crates/ui-gallery/src/chrome/variants.rs +++ b/crates/ui-gallery/src/chrome/variants.rs @@ -167,12 +167,12 @@ pub(super) fn show(ui: &mut Ui, p: &mut Panels<'_>, tab: PanelId) -> bool { }; let _ = Notice::new(Tone::Info, text).show(ui); } else { - reported = grid(ui, "variants", &cards, p, false); + reported = grid(ui, "variants", &cards, p, false, None); } closed |= cx.take_cancel(); }); let used = reported.iter().find(|reported| reported.events.used).map(|reported| reported.spec); - apply(ui, p, &cards, reported); + apply(p, &cards, reported); if let Some(card) = used.and_then(|spec| values(axis).and_then(|values| values.into_iter().nth(spec))) { if let Some(mode) = card.look.mode { p.env.mode = mode.into(); diff --git a/crates/ui-gallery/src/viewer/state.rs b/crates/ui-gallery/src/viewer/state.rs index 0c12864935..8b5e0a38ca 100644 --- a/crates/ui-gallery/src/viewer/state.rs +++ b/crates/ui-gallery/src/viewer/state.rs @@ -45,9 +45,8 @@ pub struct Browser { pub cells: Cells, /// The component whose tab a panel asked to open in this pass. pub open_request: Option<&'static str>, - /// The component whose card the Overview brings into view when it is drawn, by its registered name. - pub scroll_to: Option<&'static str>, - /// The selected component the Overview last followed to its level; the outer `None` before the first pass. + /// The selection the Overview's cards last followed: its level shown and its card brought into view; the outer `None` + /// before they first ran. pub followed: Option>, /// The selected component the tree last opened the level of; the outer `None` before the first pass. Applying settings /// sets it to the restored selection, so a level closed before a restart stays closed. @@ -117,7 +116,6 @@ impl Viewer { generation: 0, cells: Cells::new(), open_request: None, - scroll_to: None, followed: None, tree_seen: None, }; diff --git a/crates/ui-gallery/tests/it/overview.rs b/crates/ui-gallery/tests/it/overview.rs index 47cd725b65..19fd5fc177 100644 --- a/crates/ui-gallery/tests/it/overview.rs +++ b/crates/ui-gallery/tests/it/overview.rs @@ -164,3 +164,43 @@ fn the_wheel_over_a_card_scrolls_the_overview() { let after = fixture.by_label("Open").expect("a card header has Open").rect.min.y; assert!(after < title, "the wheel over a canvas card scrolled the Overview: {title} -> {after}"); } + +/// A selection of a component whose card is far down another level, here the one the gallery opens with, shows that +/// level and glides its card to the top of the view over several frames, as the old gallery's jump did. Regression: +/// the request went to egui's scroll target, which no scroll body reads, so the card never moved. +#[trial] +fn selecting_a_component_glides_its_card_to_the_top() { + const GLIDE_FRAMES: usize = 120; + let catalog = Catalog::linked(); + let controls = by_level(&catalog, "").into_iter().find(|(level, _)| level.title() == "Controls").expect("Controls has cards").1; + // Far enough down to be out of view, with enough cards after it to scroll it to the top. + let target = controls[controls.len() / 2]; + let (mut store, report) = SettingsStore::::open_with(OpenOptions::new(Location::Memory)); + let mut settings = store.get().clone(); + settings.level = "Primitives".to_owned(); + settings.selected = target.type_name.to_owned(); + store.set(settings); + let mut gallery = Gallery::new(Catalog::linked(), Persisted::new(store, &report)); + let mut fixture = Fixture::new(move |ui| gallery.ui(ui)); + fixture.room(Vec2::new(1400.0, 900.0)); + let mut frames = 0; + let arrived = loop { + fixture.frame(Vec::new()); + frames += 1; + let window = fixture.shown(); + let top = fixture + .by_role(Role::BUTTON) + .into_iter() + .filter(|button| fixture.tree().name_of(button.node) == Some("Open") && window.contains_rect(button.rect)) + .min_by(|a, b| a.rect.top().total_cmp(&b.rect.top())); + // The target's card heads the view: its title sits in the band of the topmost card's Open. + let heads = top.is_some_and(|open| { + fixture.texts().iter().any(|run| run.text == target.name && (run.rect.center().y - open.rect.center().y).abs() < open.rect.height()) + }); + if heads || frames == GLIDE_FRAMES { + break heads; + } + }; + assert!(arrived, "{}'s card reached the top of the view", target.name); + assert!(frames > 2, "the card glided over several frames, not in one: {frames}"); +} diff --git a/crates/ui-widgets/tests/it/body/scroll.rs b/crates/ui-widgets/tests/it/body/scroll.rs index b00e846142..aaccc3e6ed 100644 --- a/crates/ui-widgets/tests/it/body/scroll.rs +++ b/crates/ui-widgets/tests/it/body/scroll.rs @@ -23,6 +23,8 @@ const JUMP_VIEWS: f32 = 3.0; /// What the gaps between lines add to a body's height, at most. const GAPS: f32 = 20.0; const VIEW: Vec2 = Vec2::new(300.0, 200.0); +/// How far a wheel step reaches into the child above the view. +const STEP: f32 = 10.0; const ORIGIN: Pos2 = Pos2::new(10.0, 10.0); /// What a frame of the body saw. @@ -121,14 +123,14 @@ fn a_focus_request_into_an_out_of_view_child_runs_it_and_scrolls_it_in() { let runs: Vec> = (0..CHILDREN).map(|_| Cell::new(0)).collect(); let buttons: Vec> = (0..CHILDREN).map(|_| Cell::new((Id::NULL, Rect::NOTHING))).collect(); let view = Cell::new(Rect::NOTHING); - // Every child runs once first, so each has stops to name. - let warm = Cell::new(true); + // Every child runs once first, in a room that shows them all, so each has stops to name. + let room = Cell::new(Vec2::new(VIEW.x, CHILDREN as f32 * 2.0 * HUNDRED)); let mut show = |ui: &mut Ui| { - in_region(ui, Rect::from_min_size(ORIGIN, VIEW), |ui| { + in_region(ui, Rect::from_min_size(ORIGIN, room.get()), |ui| { Slab::new(ContainerProps::new().scroll(Scroll::vertical())).id_salt("panel").show(ui, |ui, cx| { view.set(cx.rect); for (at, (count, button)) in runs.iter().zip(&buttons).enumerate() { - craft_ui::contract::Lazy::new(at, HUNDRED).keep(warm.get()).show(ui, |ui| { + craft_ui::contract::Lazy::new(at, HUNDRED).show(ui, |ui| { count.set(count.get() + 1); let out = Button::new(format!("Child {at}")).show(ui); if !ui.is_sizing_pass() { @@ -141,8 +143,10 @@ fn a_focus_request_into_an_out_of_view_child_runs_it_and_scrolls_it_in() { }); }; let mut frames = Frames::new(); + frames.screen(room.get()); frames.idle(3, &mut show); - warm.set(false); + assert!(runs.iter().all(|count| count.get() > 0), "every child ran in the tall room"); + room.set(VIEW); frames.idle(1, &mut show); let last = CHILDREN - 1; runs.iter().for_each(|count| count.set(0)); @@ -166,14 +170,14 @@ fn tab_reaches_the_control_of_a_child_out_of_view() { let runs: Vec> = (0..CHILDREN).map(|_| Cell::new(0)).collect(); let buttons: Vec> = (0..CHILDREN).map(|_| Cell::new((Id::NULL, Rect::NOTHING))).collect(); let view = Cell::new(Rect::NOTHING); - // Every child runs once first, so each has stops to name. - let warm = Cell::new(true); + // Every child runs once first, in a room that shows them all, so each has stops to name. + let room = Cell::new(Vec2::new(VIEW.x, CHILDREN as f32 * 2.0 * VIEW.y)); let mut show = |ui: &mut Ui| { - in_region(ui, Rect::from_min_size(ORIGIN, VIEW), |ui| { + in_region(ui, Rect::from_min_size(ORIGIN, room.get()), |ui| { Slab::new(ContainerProps::new().scroll(Scroll::vertical())).id_salt("panel").show(ui, |ui, cx| { view.set(cx.rect); for (at, (count, button)) in runs.iter().zip(&buttons).enumerate() { - craft_ui::contract::Lazy::new(at, HUNDRED).keep(warm.get()).show(ui, |ui| { + craft_ui::contract::Lazy::new(at, HUNDRED).show(ui, |ui| { count.set(count.get() + 1); let out = Button::new(format!("Child {at}")).show(ui); if !ui.is_sizing_pass() { @@ -187,8 +191,10 @@ fn tab_reaches_the_control_of_a_child_out_of_view() { }); }; let mut frames = Frames::new(); + frames.screen(room.get()); frames.idle(3, &mut show); - warm.set(false); + assert!(runs.iter().all(|count| count.get() > 0), "every child ran in the tall room"); + room.set(VIEW); request(&frames.ctx, FocusTarget::Id(buttons[0].get().0)); frames.idle(3, &mut show); runs.iter().for_each(|count| count.set(0)); @@ -300,8 +306,8 @@ struct LazyColumn { runs: Vec>, shown: RefCell>, view: Cell, - /// A child kept running out of view. - keep: Cell>, + /// The child the next frames ask to reveal. + reveal: Cell>, /// Whether the body shows at all: hidden, as a tab switched away is. visible: Cell, } @@ -312,7 +318,7 @@ impl LazyColumn { runs: (0..children).map(|_| Cell::new(0)).collect(), shown: RefCell::new(Vec::new()), view: Cell::new(Rect::NOTHING), - keep: Cell::new(None), + reveal: Cell::new(None), visible: Cell::new(true), } } @@ -326,7 +332,7 @@ impl LazyColumn { Slab::new(ContainerProps::new().scroll(Scroll::vertical())).id_salt("column").show(ui, |ui, cx| { self.view.set(cx.rect); for (at, count) in self.runs.iter().enumerate() { - craft_ui::contract::Lazy::new(at, estimate(at)).keep(self.keep.get() == Some(at)).show(ui, |ui| { + craft_ui::contract::Lazy::new(at, estimate(at)).reveal(self.reveal.get() == Some(at)).show(ui, |ui| { count.set(count.get() + 1); let rect = Block::new(Vec2::new(LINE.x, height(at))).show(ui).rect; if !ui.is_sizing_pass() && !craft_ui::testing::is_measuring(ui.ctx()) { @@ -415,9 +421,9 @@ fn a_scroll_area_shown_again_runs_only_the_children_in_view() { assert!((at.min - rect.min).length() <= SAME, "and at the same place: {at:?}, then {rect:?}"); } -/// A child above the view that runs for the first time (kept, as a scroll target is) is taller than its estimate: -/// the children in view stay where they were, in the frame it runs, and the frame after runs no extra pass. Guards -/// the scroll anchor: the scroll position follows the first child at or after the view's start. +/// A child above the view that runs for the first time, as a wheel step up brings it in, is taller than its estimate: +/// the children in view move only by the wheel's step, in the frame it runs, and the frame after runs no +/// extra pass. Guards the scroll anchor: the scroll position follows the first child at or after the view's start. #[trial] fn content_in_view_stays_when_an_estimate_above_it_resolves() { const CHILDREN: usize = 40; @@ -435,23 +441,69 @@ fn content_in_view_stays_when_an_estimate_above_it_resolves() { frames.frame(vec![pointer::release(thumb + Vec2::new(0.0, 60.0))], &mut show); frames.idle(2, &mut show); let before = column.rects(); - let (first, _) = column.top().expect("a child in view"); - let above = first.checked_sub(2).expect("the drag moved past the first children"); + // Where a child starts: the rects are clipped to the view, and one clipped at its start ends a child's height + // after it. + let start = |rect: &Rect| if rect.min.y <= view.min.y + SAME { rect.max.y - HUNDRED } else { rect.min.y }; + let (first, top) = column.top().expect("a child in view"); + let above = first.checked_sub(1).expect("the drag moved past the first children"); assert_eq!(column.runs[above].get(), 0, "child {above} above the view never ran"); + // Up past the start of the first child in view, into the one above it. + let wheel = view.min.y - start(&top) + STEP; + frames.frame(vec![pointer::moved(view.center())], &mut show); let idle = frames.frame(vec![], &mut show); - column.keep.set(Some(above)); - let resolved = frames.frame(vec![], &mut show); - assert!(column.runs[above].get() > 0, "the kept child ran"); + let resolved = frames.frame(vec![pointer::wheel(wheel)], &mut show); + assert!(column.runs[above].get() > 0, "the child the wheel brought in ran"); let after = column.rects(); - let mut kept = 0; - for (at, rect) in &before { - if let Some(now) = after.get(at) { - assert!((now.min - rect.min).length() <= SAME, "child {at} in view stayed: {now:?}, then {rect:?}"); - kept += 1; - } + let moved: Vec<(usize, f32)> = before.iter().filter_map(|(at, rect)| Some((*at, start(after.get(at)?) - start(rect)))).collect(); + let &(_, step) = moved.first().expect("children in view ran in both frames"); + for (at, by) in &moved { + assert!((by - step).abs() <= SAME, "child {at} moved with the others: {by}, then {step}"); } - assert!(kept > 0, "children in view ran in both frames"); + // Without the anchor the content would move by the wheel and by what the estimate above it grew, half a child. + assert!((step - wheel).abs() < HUNDRED / 4.0, "the content moved by the wheel's {wheel}, not by the resolved estimate: {step}"); let next = frames.frame(vec![], &mut show); assert!(resolved > idle, "the frame the estimate resolved in ran the pass again at the anchored offset"); assert_eq!(next, idle, "an idle frame after it runs no extra pass"); } + +/// A reveal of a child far below the view that never ran glides the body to it: the frames between show children +/// between the start and the child at the top, each frame runs only the children in view, and the child ends at the +/// view's start. Guards `Lazy::reveal`: a skipped child placed by its estimate is a target, and the glide follows +/// its place while the estimates before it resolve. +#[trial] +fn a_revealed_child_glides_to_the_view_start() { + const CHILDREN: usize = 40; + // Frames the glide may take: two seconds at 60 Hz. + const GLIDE_FRAMES: usize = 120; + let column = LazyColumn::new(CHILDREN); + let mut show = |ui: &mut Ui| column.show(ui, varied, |_| HUNDRED / 2.0); + let mut frames = Frames::new(); + frames.idle(3, &mut show); + let target = CHILDREN - 6; + assert_eq!(column.runs[target].get(), 0, "the child far below the view never ran"); + column.reveal.set(Some(target)); + frames.frame(vec![], &mut show); + column.reveal.set(None); + let mut between = 0; + let mut arrived = false; + for _ in 0..GLIDE_FRAMES { + column.clear(); + frames.frame(vec![], &mut show); + let view = column.view.get(); + let rects = column.rects(); + for at in column.ran() { + let rect = rects.get(&at).expect("a child that ran has a rect"); + assert!(rect.intersects(view), "frame ran child {at} out of view: {rect:?} in {view:?}"); + } + let (top, rect) = column.top().expect("a child in view"); + if top == target && (rect.min.y - view.min.y).abs() <= SAME { + arrived = true; + break; + } + if top > 0 && top < target { + between += 1; + } + } + assert!(arrived, "the child reached the view's start"); + assert!(between > 1, "the glide showed offsets between the start and the child: {between} frames"); +} diff --git a/docs/craft-framework.md b/docs/craft-framework.md index 06d4131abb..14c121732b 100644 --- a/docs/craft-framework.md +++ b/docs/craft-framework.md @@ -286,14 +286,14 @@ Content runs in every pass, and its sizes come from this pass. Layouts also read **Out-of-view content.** Content inside a scroll area that is out of view this pass does not run. It keeps what it last showed: the extent it had in the last pass that showed it, which changes only in a pass that shows the content, and the stops it registered there. One mechanism (`runtime::lazy`, one store) serves every use: - Only content that meets the view runs. A `Lazy` child out of view registers the focus records of its last real run again in its place (its stops, the scopes it pushed and the roving groups of its stops; `focus::Transcript`), so Tab and F6 reach its stops; Tab onto one runs the child and the reveal scrolls it in. -- `Lazy::new(key, estimate).show(ui, |ui| ..)` wraps a large child of a scroll body (a card, a section of an app panel). Out of view it takes its remembered extent, also after the scroll area's room changed, and its closure does not run. It is a child in flow: in a `Grid` or spread `Row` body it holds one cell, its content is the one child that takes the cell, and out of view it takes the cell at its remembered extent. A card keyed by itself, not by its row, keeps its extent when a change of the column count regroups the rows. A child no pass showed yet takes its estimate (that long along the axes the area scrolls, nothing across them), so a first show runs only the children in view. It runs when its extent meets the view, while a stop from its last run holds keyboard focus or is the target of a focus request, and while `.keep(true)` asks for it. The key names the child among every `Lazy` of its scroll area. Outside a scroll area a `Lazy` always runs. +- `Lazy::new(key, estimate).show(ui, |ui| ..)` wraps a large child of a scroll body (a card, a section of an app panel). Out of view it takes its remembered extent, also after the scroll area's room changed, and its closure does not run. It is a child in flow: in a `Grid` or spread `Row` body it holds one cell, its content is the one child that takes the cell, and out of view it takes the cell at its remembered extent. A card keyed by itself, not by its row, keeps its extent when a change of the column count regroups the rows. A child no pass showed yet takes its estimate (that long along the axes the area scrolls, nothing across them), so a first show runs only the children in view. It runs when its extent meets the view, and while a stop from its last run holds keyboard focus or is the target of a focus request. `.reveal(true)` in a pass asks its scroll body to glide until the child starts at the view's start, whether it ran yet or not: the offset follows the child's place on the motion service's follow curve (a Travel motion, so reduced motion jumps), while estimates before it resolve; a wheel, drag or other move of the body ends the glide. The key names the child among every `Lazy` of its scroll area. Outside a scroll area a `Lazy` always runs. - The first run of a pass decides which children run, so the measuring run and the real run lay out the same children. - Every scroll input moves the offset at step 4, before the content runs, so the decision sees the offset the pass paints. Wheel, page keys and reveals arrive there directly. A thumb drag, a track press or an AccessKit scroll action is sensed after the content ran: the pass queues it for step 4 and asks for a discard pass, so the move shows in the same frame. - A scroll position the framework holds is also named by content: the first child at or after the view's start and its place in the view (`lazy::Anchor`, kept with the offset). When extents before that child change (estimates replaced by real extents, rows regrouped), the offset follows the child and the pass runs again, so the content in view does not move. An offset bound to the app (`Component::scroll`) is the app's plain offset, and a region that follows its end follows the end. - A scroll area that does not run (a tab switched away) keeps its children's entries, and its content extent lives beside its offset (`ScrollState`) with the same lifetime, so it shows again at the same offset after any length of hide; one that runs drops the entries of the children it did not reach. - A collection builds the rows in view, plus its lead, anchor, renaming and grabbed rows. Its rows are no Tab entries (Tab moves past the collection, arrows move its lead), so a row out of view has no stops to keep. It places the rows it does not build by the extents they had when last built, from the same store, and its output lists the rows in view and the kept rows. Rows it never built take its item layout's estimate, as a `Lazy` takes its own, so a long list is never built whole. - The access tree covers the view, by the same rule: content that runs reports its access nodes (a collection's built rows and their section headings included). A component that lays out section rows as its own parts (TileGrid's group headings and tail rows) reports the nodes of those in view. Content out of view (`Lazy` children and collection rows) is absent from the access tree until it scrolls in. AccessKit scroll actions still reach it, because they move the offset. -- Content that was never shown has only its estimate and no stops: Tab reaches it once it was shown. Mark content with `.keep(true)` when the app focuses it or scrolls to it before it was ever in view. +- Content that was never shown has only its estimate and no stops: Tab reaches it once it was shown. An app brings it into view with `.reveal(true)`. ### 3.7 One egui revision