Avoid speculative layout when retained answers suffice

This commit is contained in:
iris-ai committed 2026-09-14 15:33:39 -04:00
1 parent cdec29351a
commit a640c6cce2
5 files changed
+116 -27

No files matched your search

+47 -4
View File
@@ -79,10 +79,9 @@ fn a_leaf_that_depends_on_its_box_is_drawn_again_when_the_box_changes() {
h.rsc[first].size = Size::from((150, 200));
h.frame();
// Twice: once for the span to measure it, once for its real box. A child
// that can hint its length is spared the first, and a smaller number here
// means someone has made that cheaper rather than broken it.
assert_eq!(draws.get(), settled + 2);
// The preceding fixed child makes the remaining box this child's real
// box, so measuring it also draws it in its final place.
assert_eq!(draws.get(), settled + 1);
assert_corners!(h, second, (150, 0), (400, 200));
}
@@ -116,6 +115,50 @@ fn a_span_relays_out_when_a_child_it_measured_changes() {
assert_corners!(h, second, (250, 0), (400, 200));
}
#[test]
fn a_repaint_that_keeps_its_size_does_not_relay_out() {
let mut h = Harness::new((400, 200));
let (first, draws) = counted(&mut h, Size::from((100, 200)), OnResize::Translate);
let (second, _) = counted(&mut h, Size::REST, OnResize::Translate);
h.set_root((first, second).span(Dir::RIGHT));
let settled = draws.get();
// Taking mutable access is the ordinary content-change signal. This
// widget returns the same size, so the parent has nothing to lay out.
let _ = h.rsc.widgets_mut().get_dyn_mut(first.id());
h.frame();
assert_eq!(draws.get(), settled + 1);
}
#[test]
fn scrolling_reuses_the_clean_contents_size() {
let mut h = Harness::new((400, 200));
let (inner, draws) = counted(&mut h, Size::from((400, 600)), OnResize::Translate);
let scroll = Scroll::new(inner.add_strong(&mut h.rsc), Axis::Y).add(&mut h.rsc);
h.set_root(scroll);
let settled = draws.get();
h.rsc[scroll].scroll(40.0);
h.frame();
assert_eq!(draws.get(), settled);
assert_corners!(h, inner, (0, -360), (400, 240));
}
#[test]
fn scrolling_remeasures_changed_contents() {
let mut h = Harness::new((400, 200));
let (inner, _) = counted(&mut h, Size::from((400, 600)), OnResize::Translate);
let scroll = Scroll::new(inner.add_strong(&mut h.rsc), Axis::Y).add(&mut h.rsc);
h.set_root(scroll);
h.rsc[inner].size = Size::from((400, 800));
h.frame();
assert_corners!(h, inner, (0, -600), (400, 200));
}
#[test]
fn a_placed_child_survives_the_next_frame() {
let mut h = Harness::new((400, 200));