Memoized views: the header trial asserts every call replayed; a measuring replay's value holds the real run's layout

The trial checks the frame's memo log: three replays (the sizing pass and the real run of each of the frame's two
passes), the last pass's real run among them. MemoView::show and the runner say that a measuring call that replays
returns the kept real run's value, laid out in that run's room and flow, so a caller that measures takes the extent
the call reports.
This commit is contained in:
aiongg
2026-11-21 17:45:03 +00:00
parent f8888f8beb
commit f300c5954a
3 changed files with 21 additions and 6 deletions
+2
View File
@@ -150,6 +150,8 @@ impl Lazy {
}
kept
} else {
// The kept real run's output, laid out in that run's room and flow: a caller that measures sizes from
// the extent this call takes, never from rects in it.
lazy::kept_output(&ctx, id)
};
report_unit(&ctx, shrink, id, rect.size());
+3 -1
View File
@@ -110,7 +110,9 @@ impl<P: MemoProps, R: Clone + PartialEq + Shift + Send + Sync + 'static> MemoVie
}
/// Runs the view in a child `Ui` placed in flow in `ui`, or adds its last run again. Returns what the run returned,
/// the kept value when it replayed; `None` only when it is out of view in a scroll area.
/// the kept value when it replayed; `None` only when it is out of view in a scroll area. A measuring run that
/// replays returns the kept real run's value, laid out in that run's room and flow: code that measures sizes from
/// the extent the view takes in `ui`, never from rects in the value.
pub fn show(self, ui: &mut Ui) -> Option<R> {
let MemoView { lazy, mut props, show } = self;
let ctx = ui.ctx().clone();
+16 -5
View File
@@ -741,10 +741,11 @@ impl Container for Headed {
}
}
/// One frame of `Headed` with the body text `label`; returns how many sizing passes its body ran in.
fn headed_frame(frames: &mut Frames, label: &str) -> usize {
/// One frame of `Headed` with the body text `label`; returns the frame's passes and how many sizing passes its body ran
/// in.
fn headed_frame(frames: &mut Frames, label: &str) -> (usize, usize) {
let sizing = Cell::new(0);
frames.frame(vec![], |ui| {
let passes = frames.frame(vec![], |ui| {
in_region(ui, STACK_ROOM, |ui| {
let headed = Headed { common: Common::new(), props: ContainerProps::new().header(HeaderRegion::new()) };
headed.show(ui, |ui, _| {
@@ -755,7 +756,7 @@ fn headed_frame(frames: &mut Frames, label: &str) -> usize {
});
});
});
sizing.get()
(passes, sizing.get())
}
/// A view in the header of a content-sized container replays when the container measures its regions again: its
@@ -771,9 +772,19 @@ fn a_view_in_a_measured_header_replays_in_the_sizing_pass_and_the_real_run() {
headed_frame(&mut frames, "Short");
assert_eq!(title_runs(), 0, "settled: an idle frame replays the header's view");
// A second line, no wider than the first: the container's width, and with it the header's room, stays.
let sizing = headed_frame(&mut frames, "Short\nShort");
let (passes, sizing) = headed_frame(&mut frames, "Short\nShort");
assert!(sizing > 0, "the taller label made the container measure its regions again");
assert_eq!(passes, 2, "the taller container asks for one discard pass");
assert_eq!(title_runs(), 0, "the unchanged view replayed in every call: {:?}", last_frame_memo_runs(&frames.ctx));
let heading = |runs: Vec<(&'static str, Id, MemoRun)>| -> Vec<MemoRun> {
runs.into_iter().filter(|(name, _, _)| name.ends_with("::Title")).map(|(_, _, run)| run).collect()
};
assert_eq!(heading(last_pass_memo_runs(&frames.ctx)), [MemoRun::Replayed], "the discard pass's real run replayed the view");
assert_eq!(
heading(last_frame_memo_runs(&frames.ctx)),
[MemoRun::Replayed; 3],
"the view was called and replayed in the sizing pass and in the real run of each of the two passes"
);
}
/// A paragraph that wraps at its room's width.