Say what a child gets of a container's box in that box's own lengths

Three things the measurements asked for, all about how much a box that came
from an answer costs.

**A part in the box's own coordinates.** Saying "less eleven pixels at the
end" in frame lengths from the box's start means reading how long the box is,
and a container whose box is its own answer then depends on its own answer:
`Pad` drew sixty-four times in one resize frame at seed 13, chasing its own
width. `Part::Of` says the same thing as a part of the box, which composes
without a length -- pixels are pixels wherever the box lands -- and what a
child under it holds for maps back through that part onto the container's
own box rather than onto the frame.

**One axis of the box at a time.** `extent_len` pinned both axes, so a span
dividing one of them held for one length of the other as well, and a resize
broke every span whose cross-axis answer moved.

**No lazy placement.** Leaving a child's answer to be placed at the end of
the parent's draw, rather than as the child answers, was meant to save a
recomposition. It costs one instead: the drawing is put in the part first
and in the answer's box after, and where it does not hold for both that is
two drawings rather than one. Seed 1 at depth 8 went from 391 widget draws
on a resize to 29 with it gone. The test that pinned three draws for a
numeric leaf in a span goes with it.

Seed 1 at depth 8, widget draws / distinct widgets / update, against #18's
head and against the commit this branch started from:

| phase   | e44dea3      | 34cafb6      | here          |
| ---     | ---          | ---          | ---           |
| cold    | 369/261/10.6 | 463/274/13.3 | 516/288/12.0  |
| repaint | 1            | 1            | 1             |
| many    | 157/95/0.33  | 263/108/0.59 | 187/119/0.52  |
| size    | 16/12/0.018  | 3/3          | 3/3/0.010     |
| scroll  | 2/0.002      | 1            | 1/0.004       |
| resize  | 13/13/0.019  | 22/15/0.032  | 24/76/0.090   |

Seed 13 at depth 8 is where the protocol still costs: `many` 1091 draws
against #18's 524, and `resize` 2215 against a frame #18 does not draw at
all. Both are the same shape -- an answer measured in one box and drawn in
another -- and the handoff says where that comes from.

Checked: fmt, clippy with -D warnings, 108 suite tests, 20 core tests, the
11 generated cases, and the shrinker at 400 trees of depth 5, which fails
seeds 2 (repaint) and 108 (reorder).
This commit is contained in:
iris-ai committed 2026-09-18 01:06:05 -04:00
1 parent 1956be3f3d
commit 0954770ceb
11 files changed
+134 -222

No files matched your search

+13 -50
View File
@@ -217,7 +217,7 @@ impl Widget for FromHint {
painter.widget_at(
&self.inner,
UiRegion::FULL,
[Place::Within(None), Place::Within(Some(top))],
[Place::Within(Part::All), Place::Within(Part::From(top))],
);
Size::LEFTOVER
}
@@ -880,8 +880,8 @@ fn resizing_a_fixed_frame_recomposes_its_contents_without_drawing_them() {
&self.child,
UiRegion::FULL,
[
Place::Within(Some(self.region.x)),
Place::Within(Some(self.region.y)),
Place::Within(Part::From(self.region.x)),
Place::Within(Part::From(self.region.y)),
],
);
Size::LEFTOVER
@@ -940,43 +940,6 @@ fn resizing_a_fixed_frame_recomposes_its_contents_without_drawing_them() {
}
}
#[test]
fn a_span_does_not_place_its_measurement_before_assigning_the_childs_slot() {
struct MeasuredBox(Rc<Cell<usize>>);
impl Widget for MeasuredBox {
fn draw(&mut self, painter: &mut Painter) -> Size {
self.0.set(self.0.get() + 1);
painter.px_size();
painter.primitive(RectPrimitive::color(Color::BLUE));
Size::from((100, 50))
}
}
let mut h = Harness::new((400, 200));
let draws = Rc::new(Cell::new(0));
let leaf = MeasuredBox(draws.clone()).add(&mut h.rsc);
h.set_root((leaf,).span(Dir::RIGHT).width(rel(1.0)).height(rel(1.0)));
assert_eq!(draws.get(), 3);
assert_corners!(h, leaf, (0, 75), (100, 125));
assert_eq!(
primitive_bounds(&h, leaf.id()),
vec![h.region(&leaf.id()).unwrap()]
);
h.frame();
assert_eq!(draws.get(), 3);
h.resize((600, 300));
h.frame();
assert_eq!(draws.get(), 6);
assert_corners!(h, leaf, (0, 125), (100, 175));
assert_eq!(
primitive_bounds(&h, leaf.id()),
vec![h.region(&leaf.id()).unwrap()]
);
}
#[test]
fn glyph_origins_compose_identically_when_drawn_and_when_retained() {
struct Glyphs {
@@ -1006,8 +969,8 @@ fn glyph_origins_compose_identically_when_drawn_and_when_retained() {
&self.child,
self.region,
[
Place::Fill(Some(self.extent.x)),
Place::Fill(Some(self.extent.y)),
Place::Fill(Part::From(self.extent.x)),
Place::Fill(Part::From(self.extent.y)),
],
);
Size::LEFTOVER
@@ -1176,8 +1139,8 @@ fn padding_and_stack_boxes_follow_the_extent_without_drawing_again() {
&self.child,
UiRegion::FULL,
[
Place::Fill(Some(self.extent.x)),
Place::Fill(Some(self.extent.y)),
Place::Fill(Part::From(self.extent.x)),
Place::Fill(Part::From(self.extent.y)),
],
);
Size::LEFTOVER
@@ -1264,11 +1227,11 @@ fn moving_an_extent_child_preserves_the_slot_chosen_from_its_measurement() {
&self.child,
UiRegion::FULL,
[
Place::Fill(Some(UiSpan::new(
Place::Fill(Part::From(UiSpan::new(
Len::px(self.start),
Len::px(self.start + 200.0),
))),
Place::Fill(Some(UiSpan::FULL)),
Place::Fill(Part::From(UiSpan::FULL)),
],
);
Size::LEFTOVER
@@ -1306,8 +1269,8 @@ fn extent_frames_keep_fractional_reports_and_numeric_dependencies_valid() {
&self.child,
UiRegion::FULL,
[
Place::Within(Some(self.region.x)),
Place::Within(Some(self.region.y)),
Place::Within(Part::From(self.region.x)),
Place::Within(Part::From(self.region.y)),
],
)
.size()
@@ -1326,8 +1289,8 @@ fn extent_frames_keep_fractional_reports_and_numeric_dependencies_valid() {
&self.child,
UiRegion::FULL,
[
Place::Fill(Some(self.extent.x)),
Place::Fill(Some(self.extent.y)),
Place::Fill(Part::From(self.extent.x)),
Place::Fill(Part::From(self.extent.y)),
],
)
.size(),