Thread a box in pixels down the draw, one multiply from its parent's
A box in pixels was composed back up the move chain, on a grid fine enough that the walk rounded once, while a widget's offer was threaded down through its ancestors' offers. Two routes to one length, which is what `Holds::through` allowed for -- and the offer's route broke at a region node. `offered_region` fell back to `UiRegion::FULL` there, and `redraw` resolved that against the node's slot entry, which holds the box its parent *placed* the node in. Under a `Scroll` that is as long as the content rather than the viewport, so everything below was re-asked at a width its own answer had produced and the old answer confirmed itself: shrinker seed 220 on `reorder` left a widget 290px out. `ActiveData` now keeps a widget's box as lengths of its parent's box -- `given_len`, and `offer_len` for the box it was first asked about -- and `DrawInfo` carries the pixel lengths, threaded down one `Len::to_px` at a time: the box its parent gave it, then the part of that box its own answer placed the drawing in, which `placed_lens` states once for both `placed_box` and the walk. `Painter::px_size` and `px_len` read that value, and `UiRenderState::asked_px` takes the same steps back up the parent chain where a local redraw starts part-way down the tree. Neither chain has a coordinate frame in it, so neither can break at a region node, and warm and cold reach every length by the same expression. Three things follow. `Holds::through` is the exact preimage of `px + floor(rel * box)` -- two divisions, no allowance, the whole of a box mapping back to itself. A local redraw asks in the box its parent gave it and only where that box is as long as the offer, which retires `redraw`'s third ask and the region-node exception beside it; `draw_inner` places the answer inside that box itself. And symbolic regions are left to the GPU, hit testing and remaps, where `Moves::resolve` is the only walk: `wide.rs`, `Moves::compose`, `Moves::size_of`, `px_of`, `px_region`, `offered_region` and `slot_wide` are gone, 252 lines of `core/` net. `px` is deliberately not stored beside those lengths. A resize every widget's `Holds` admits redraws nothing, so a stored pixel length would be stale on every widget in the tree with nothing on it to say so, and refreshing it costs a walk down every reused subtree on the resize path. Instructions:u, medians of 21 runs, seed 1 at depth 8: | phase | before | after | | | --- | ---: | ---: | ---: | | `cold`, 200 frames | 313.1M | 312.9M | -0.04% | | `resize` | 408.1M | 405.6M | -0.61% | | `many` | 1,924M | 1,756M | -8.75% | | `scroll` | 357.3M | 323.4M | -9.49% | | `repaint` | 363.3M | 315.4M | -13.18% | `cold` and `resize` have all twenty-five work counters identical, so those two rows say the draw path costs the same threaded as composed. The other three do less work: `repaint` goes from 23 draw requests and 13 widget draws a frame to 1 and 1, `scroll` from 20 and 11 to 8 and 2, `many` from 273 and 186 to 207 and 157. Primitive writes are unmoved in every phase. Verified: `view`, `minimal`, `random`, `tabs` and `text` render byte-identical at 1920x1200 against `5b78002`, as does the `tabs` touch replay before and after the gesture, and a live resize of `random` to 1280x800 is identical both to the old head's and to a cold render at that size. The oracle passes 100 seeds in release and 120 in debug -- the debug run is the one that exercises the `Holds` assertion -- and the fifteen shrinker cases pass at 400 seeds of depth 5 and 1000 of depth 6. Seed 220 is `unsettled::a_widget_under_a_region_node_is_asked_in_the_box_that_node_was_offered`, which needs both halves of this to fail: the old chain with the old allowance passes it, and the old chain with the exact preimage does not. `AGREE_STEPS` stays 2. One step passes the 100-seed oracle and fails the 400-seed shrinker on `resize-size` by 0.002 px, so what is left there is the resize path re-expressing a part as a fraction of a box that changed length, not a length reached two ways. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5b7800264d
commit
32542d0c0b
9 files changed
+399
-557
No files matched your search
+110
-10
@@ -3,13 +3,15 @@
|
||||
//! frame that had not settled: a wrapping text shaped at a width it was
|
||||
//! measured in rather than the one it was given. The rest are a widget
|
||||
//! measured again in a box its own answer had decided, where the old answer
|
||||
//! is a fixed point whatever the content now says. The last two are neither:
|
||||
//! one box length, composed two ways, landing either side of the boundary
|
||||
//! that decided whether a child was drawn at all, and one box as long as the
|
||||
//! box a widget was offered but somewhere else.
|
||||
//! is a fixed point whatever the content now says. The last three are
|
||||
//! neither: one box length, composed two ways, landing either side of the
|
||||
//! boundary that decided whether a child was drawn at all, and two boxes
|
||||
//! reached through a region node's own entry rather than through the offer
|
||||
//! that node was given.
|
||||
|
||||
use iris::harness::Harness;
|
||||
use iris::prelude::*;
|
||||
use iris::random::Branch;
|
||||
|
||||
/// Six widgets, shrunk from a 402-widget tree the fuzzer found. Nothing about
|
||||
/// the tree changes -- every widget is marked for redraw and the frame is
|
||||
@@ -428,12 +430,12 @@ fn plant_nested_scrolls(h: &mut Harness) -> Vec<WidgetId> {
|
||||
vec![text.id(), inner.id(), filler.id(), span.id(), root.id()]
|
||||
}
|
||||
|
||||
/// A local redraw asks a dirty widget in the box its parent asked it in, and
|
||||
/// then again in the box its parent chose from that answer. Skipping the
|
||||
/// second ask because the two boxes are the same *length* left this inner
|
||||
/// scroll, which owns a region node, drawn at its offer. The offer is the
|
||||
/// outer scroll's whole viewport and the final box is 24px above it -- the
|
||||
/// height of the sized child the outer scroll snaps to the end of -- so the
|
||||
/// A local redraw asks a dirty widget in the box its parent gave it, and only
|
||||
/// where that box is as long as the one it was offered; anything else is a
|
||||
/// question its parent has to ask. This inner scroll's offer is the outer
|
||||
/// scroll's whole viewport and the box it was given is 24px shorter -- the
|
||||
/// height of the sized child the outer scroll snaps to the end of -- so what
|
||||
/// it must not do is settle itself. It was drawn at its offer once, and the
|
||||
/// inner scroll and its text stayed 24px too low.
|
||||
#[test]
|
||||
fn redrawing_one_widget_does_not_move_what_scrolls_around_it() {
|
||||
@@ -454,3 +456,101 @@ fn redrawing_one_widget_does_not_move_what_scrolls_around_it() {
|
||||
}
|
||||
assert!(wrong.is_empty(), "{}", wrong.join("\n"));
|
||||
}
|
||||
|
||||
/// Ten widgets, of the shape `tests/shrink.rs` reduces the oracle's seed 220
|
||||
/// to. The pad owns a movable region and is the scroll's content, so the box
|
||||
/// the scroll places it in is as long as that content while the box it was
|
||||
/// offered is the viewport -- and with no padding to tell those two apart,
|
||||
/// the span inside it looked like it was still at its offer. So everything
|
||||
/// under the pad was asked again in the *placed* box, the offer resolving
|
||||
/// against the node's own entry, which holds that box: the texts kept the
|
||||
/// widths they had, the content stayed the length those widths make, and the
|
||||
/// old answer confirmed itself. What the branch adds is a tree that differs
|
||||
/// rather than a box that moved, since a probe measured at the wrong width
|
||||
/// takes the other side.
|
||||
fn plant_under_a_node(h: &mut Harness, swapped: bool) -> (Vec<WidgetId>, [WeakWidget<Span>; 2]) {
|
||||
let probe = rect(Color::RED).add(&mut h.rsc);
|
||||
let wide = rect(Color::GREEN).add(&mut h.rsc);
|
||||
let narrow = rect(Color::BLUE).add(&mut h.rsc);
|
||||
let branch = Branch {
|
||||
probe: probe.add_strong(&mut h.rsc),
|
||||
wide: wide.add_strong(&mut h.rsc),
|
||||
narrow: narrow.add_strong(&mut h.rsc),
|
||||
threshold: 213.0,
|
||||
}
|
||||
.add(&mut h.rsc);
|
||||
let wrapped = wtext(
|
||||
"Wrapping shapes one source into as many lines as the box \
|
||||
leaves room for, so a paragraph's height is an answer and not a setting.",
|
||||
)
|
||||
.size(16)
|
||||
.wrap(true)
|
||||
.add(&mut h.rsc);
|
||||
let plain = wtext("one line, overflowing whatever it is given")
|
||||
.size(16)
|
||||
.wrap(false)
|
||||
.add(&mut h.rsc);
|
||||
let row = |h: &mut Harness, mut children: Vec<StrongWidget>| {
|
||||
if swapped {
|
||||
children.rotate_left(1);
|
||||
}
|
||||
Span {
|
||||
children,
|
||||
dir: Dir::RIGHT,
|
||||
gap: Px::ZERO,
|
||||
}
|
||||
.add(&mut h.rsc)
|
||||
};
|
||||
let texts: Vec<StrongWidget> =
|
||||
vec![wrapped.add_strong(&mut h.rsc), plain.add_strong(&mut h.rsc)];
|
||||
let inner = row(h, texts);
|
||||
let pair: Vec<StrongWidget> = vec![branch.add_strong(&mut h.rsc), inner.add_strong(&mut h.rsc)];
|
||||
let outer = row(h, pair);
|
||||
let pad = Pad {
|
||||
padding: Padding::ZERO,
|
||||
inner: outer.add_strong(&mut h.rsc),
|
||||
}
|
||||
.add(&mut h.rsc);
|
||||
h.rsc.widgets_mut().set_region_node(pad.id(), true);
|
||||
let root = Scroll::new(pad.add_strong(&mut h.rsc), Axis::X).add(&mut h.rsc);
|
||||
h.set_root(root);
|
||||
(
|
||||
vec![
|
||||
probe.id(),
|
||||
wide.id(),
|
||||
narrow.id(),
|
||||
branch.id(),
|
||||
wrapped.id(),
|
||||
plain.id(),
|
||||
inner.id(),
|
||||
outer.id(),
|
||||
pad.id(),
|
||||
root.id(),
|
||||
],
|
||||
[outer, inner],
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_widget_under_a_region_node_is_asked_in_the_box_that_node_was_offered() {
|
||||
let mut warm = Harness::new((900, 1200));
|
||||
let (ids, spans) = plant_under_a_node(&mut warm, false);
|
||||
warm.frame();
|
||||
for span in spans {
|
||||
warm.rsc[span].children.rotate_left(1);
|
||||
}
|
||||
warm.frame();
|
||||
|
||||
let mut cold = Harness::new((900, 1200));
|
||||
let (cold_ids, _) = plant_under_a_node(&mut cold, true);
|
||||
cold.frame();
|
||||
|
||||
let mut wrong = Vec::new();
|
||||
for (i, (&w, &c)) in ids.iter().zip(&cold_ids).enumerate() {
|
||||
let (got, want) = (warm.region(&w), cold.region(&c));
|
||||
if got != want {
|
||||
wrong.push(format!("widget {i}: warm {got:?} cold {want:?}"));
|
||||
}
|
||||
}
|
||||
assert!(wrong.is_empty(), "{}", wrong.join("\n"));
|
||||
}
|
||||
+13
-5
@@ -42,11 +42,19 @@ const OUTER: (f32, f32) = (1920.0, 1200.0);
|
||||
const INNER: (f32, f32) = (640.0, 900.0);
|
||||
const STILL: (f32, f32) = (900.0, 1200.0);
|
||||
|
||||
/// The same box, to a step of the grid per level of nesting between the two
|
||||
/// ways of reaching it. A move, a repaint and a row of shares land on the
|
||||
/// same number; what is left is a box centred in a fraction of its parent
|
||||
/// against the same box centred in its own pixels. A step is a thousandth of
|
||||
/// a pixel, where this was a twentieth of one before any of it was on a grid.
|
||||
/// The same box, to two steps of the grid between the two ways of reaching
|
||||
/// it. A move, a repaint, a row of shares and every length in pixels land on
|
||||
/// the same number. What needs the slack is a position: a box centred in a
|
||||
/// fraction of its parent against the same box centred in its own pixels,
|
||||
/// and a box re-expressed as a fraction of a parent that changed length.
|
||||
/// A step is a thousandth of a pixel, where this was a twentieth of one
|
||||
/// before any of it was on a grid.
|
||||
///
|
||||
/// **One step is not enough**, tried 2026-09-17 once a length in pixels
|
||||
/// stopped being composed: it passes the 100-seed oracle and fails the
|
||||
/// 400-seed shrinker on `resize-size`, seeds 384 and 162, by 0.002 px. So
|
||||
/// what is left here is the resize path's own rounding rather than a length
|
||||
/// reached two ways.
|
||||
const AGREE_STEPS: i32 = 2;
|
||||
|
||||
/// A way of changing what a span holds. Each is a shape worth its own case:
|
||||
|
||||
Reference in new issue
Block a user