mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
Memoized views: a row unit replays in the row's measuring sweeps
With the flow facts out of the key, the counting sweep's call keys as the real call does, and an idle frame or a frame at the same width runs a memoized row unit in none of the row's sweeps. The trials say so: the row-unit trial asserts no measuring run, and the counting-call trial describes the call by its flow.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
//! A memoized view that is one unit of a shrinking row: the row's counting sweep calls it with another key than its
|
||||
//! real run, and that call leaves the replay decision of the pass to the calls after it and reuses its own measure.
|
||||
//! A memoized view that is one unit of a shrinking row: the row's counting sweep calls it in another flow than its real
|
||||
//! run (the content shows unbounded there), and that call leaves the replay decision of the pass to the real call and
|
||||
//! reuses the measure of the last counting call.
|
||||
|
||||
use craft_ui::contract::{MemoProps, MemoView, Props as _, Show as _, ShowContainer as _, Sizing};
|
||||
use craft_ui::layout::BodyLayout;
|
||||
@@ -26,11 +27,11 @@ fn of_view(runs: Vec<(&'static str, egui::Id, MemoRun)>) -> Vec<MemoRun> {
|
||||
}
|
||||
|
||||
/// A memoized view in a row that is not short, whose new content is wider: it runs once in the real run that meets the
|
||||
/// new props and once as a measuring run in the row's counting sweep, whose call keys apart from the real run's
|
||||
/// (the content shows unbounded there). The real run of the discard pass that sweep belongs to replays, and so does
|
||||
/// new props and once as a measuring run in the row's counting sweep, whose flow is not the real run's (the content
|
||||
/// shows unbounded there). The real run of the discard pass that sweep belongs to replays, and so does
|
||||
/// every call of the next frame, a counting sweep's included.
|
||||
#[trial]
|
||||
fn a_memoized_row_unit_replays_after_the_rows_counting_call_with_another_key() {
|
||||
fn a_memoized_row_unit_replays_after_the_rows_counting_call() {
|
||||
let width = Cell::new(60.0);
|
||||
let mut frames = Frames::new();
|
||||
let frame = |frames: &mut Frames| {
|
||||
|
||||
@@ -1687,7 +1687,7 @@ fn line(props: &mut Line, ui: &mut Ui) -> Rect {
|
||||
|
||||
/// A memoized view is one unit of the shrinking row around it: with room it is as wide as its content, and when a
|
||||
/// sibling after it grows it narrows so the row fits, though the region it is offered stays the same. It replays while
|
||||
/// the row's width for it is unchanged and runs once when that width changes.
|
||||
/// the row's width for it is unchanged, in the row's measuring sweeps too, and runs once when that width changes.
|
||||
#[trial]
|
||||
fn a_view_in_a_row_narrows_with_it_and_runs_only_when_its_width_changes() {
|
||||
const ROOM: Rect = Rect { min: Pos2::new(10.0, 10.0), max: Pos2::new(310.0, 50.0) };
|
||||
@@ -1710,7 +1710,7 @@ fn a_view_in_a_row_narrows_with_it_and_runs_only_when_its_width_changes() {
|
||||
}
|
||||
let (wide, _) = frame(&mut frames, "B");
|
||||
assert_eq!(runs_of(&frames, "Line"), [MemoRun::Replayed], "an idle frame replays the view");
|
||||
assert!(measuring_runs_of(&frames, "Line") <= SWEEPS, "an idle frame runs the view at most once per measuring sweep of the row");
|
||||
assert_eq!(measuring_runs_of(&frames, "Line"), 0, "an idle frame replays the view in the row's measuring sweeps too");
|
||||
let (narrow, after) = frame(&mut frames, "A much longer button label");
|
||||
assert_eq!(runs_of(&frames, "Line"), [MemoRun::Ran], "a new width runs the view");
|
||||
assert!(narrow.width() < wide.width(), "the view narrows: {narrow:?} from {wide:?}");
|
||||
@@ -1719,14 +1719,9 @@ fn a_view_in_a_row_narrows_with_it_and_runs_only_when_its_width_changes() {
|
||||
frame(&mut frames, "A much longer button label");
|
||||
}
|
||||
assert_eq!(runs_of(&frames, "Line"), [MemoRun::Replayed], "at the same width it replays again");
|
||||
assert!(measuring_runs_of(&frames, "Line") <= SWEEPS, "at the same width the view runs at most once per measuring sweep of the row");
|
||||
assert_eq!(measuring_runs_of(&frames, "Line"), 0, "at the same width the view replays in the row's measuring sweeps too");
|
||||
}
|
||||
|
||||
/// The sweeps of a shrinking row's measuring run that show its units: the counting sweep and, for a short row, the
|
||||
/// sweep that asks its body units for their least. Until FW-310 moves `unbounded` out of the scope key, the counting
|
||||
/// sweep's call keys apart from the real call's and a memoized unit runs in each sweep; FW-310 tightens this to none.
|
||||
const SWEEPS: usize = 2;
|
||||
|
||||
/// How many times the views named `name` ran in the last frame outside the real run of its last pass: in sizing and
|
||||
/// measuring runs.
|
||||
fn measuring_runs_of(frames: &Frames, name: &str) -> usize {
|
||||
|
||||
Reference in New Issue
Block a user