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>
71 lines
3.2 KiB
Rust
71 lines
3.2 KiB
Rust
use crate::{
|
|
Holds, LayerId, LayoutLen, MaskIdx, MoveIdx, PrimitiveHandle, RegionAlign, Size, TextureHandle,
|
|
UiRegion, UiVec2, WidgetId,
|
|
};
|
|
|
|
/// What is kept of a widget its parent has asked about. `drawn` says whether
|
|
/// it currently draws; one that does not is kept so that a change to it, or
|
|
/// under it, still reaches whoever asked.
|
|
#[derive(Debug)]
|
|
pub struct ActiveData {
|
|
pub id: WidgetId,
|
|
/// The box its drawing is in, in `parent_move`'s coordinates.
|
|
pub region: UiRegion,
|
|
/// The box its parent gave it, in the same coordinates: what it was
|
|
/// asked about, before its own answer placed its drawing inside it.
|
|
/// `region` is that placement, and a local redraw asks here.
|
|
pub given: UiRegion,
|
|
/// The same box as lengths of its parent's box, which is the one route
|
|
/// to a box in pixels: a draw threads these down a level at a time, and
|
|
/// [`crate::UiRenderState::redraw`] takes the same steps back up.
|
|
pub given_len: UiVec2,
|
|
/// The lengths of the box its parent first asked about it in, as
|
|
/// lengths of the box the parent was itself offered. Any later box it
|
|
/// was given was decided knowing its answer, so this is the question
|
|
/// asked again -- and a chain of fractions has no frame in it, which is
|
|
/// why a region node between two widgets cannot break it.
|
|
pub offer_len: UiVec2,
|
|
/// What it answered there: the size and what that held for.
|
|
pub answer: (Size, [Holds; 2]),
|
|
/// What the widget said it used of its box, the last time it drew.
|
|
pub size: Size,
|
|
/// The pixel lengths of `region`, per axis, that its drawing and `size`
|
|
/// hold for.
|
|
pub holds: [Holds; 2],
|
|
pub drawn: bool,
|
|
pub parent: Option<WidgetId>,
|
|
/// How far down the tree it was drawn, the root being 1. Carried down a
|
|
/// draw rather than worked out by walking up, so it is right for every
|
|
/// widget a frame visits and cannot drift while one is being drawn.
|
|
pub depth: usize,
|
|
pub textures: Vec<TextureHandle>,
|
|
pub primitives: Vec<PrimitiveHandle>,
|
|
pub children: Vec<WidgetId>,
|
|
/// The children whose size this widget read while drawing.
|
|
pub size_deps: Vec<WidgetId>,
|
|
/// The movable region its primitives are positioned through: its own when
|
|
/// opted in, otherwise the nearest ancestor's.
|
|
pub move_idx: MoveIdx,
|
|
/// The declared lengths whoever drew this widget resolved into its box.
|
|
/// A change to one moves a box this widget cannot fix by drawing again,
|
|
/// and comparing them is what says so.
|
|
pub declared: [Option<LayoutLen>; 2],
|
|
/// The axes along which its parent chose its box from its own answer,
|
|
/// so a local redraw asks the question its parent asked.
|
|
pub decided: [bool; 2],
|
|
/// Its alignment when it was last drawn, which a change to the property
|
|
/// is found against.
|
|
pub own_align: RegionAlign,
|
|
/// The movable region whose coordinates `region` uses.
|
|
pub parent_move: MoveIdx,
|
|
pub mask: MaskIdx,
|
|
pub layer: LayerId,
|
|
}
|
|
|
|
impl ActiveData {
|
|
/// Whether its drawing and size hold for a box of these pixel lengths.
|
|
pub fn holds_at(&self, px: crate::PxVec2) -> bool {
|
|
self.holds[0].contains(px.x) && self.holds[1].contains(px.y)
|
|
}
|
|
}
|