Measure a dirty widget where its parent asked, not in a box its answer decided
A local redraw drew a dirty widget in the box it was placed in. When a reader decided that box from the widget's own answer -- an aligned span sized to its children, a text at the tail of a row, a scroll's content -- the old answer is a fixed point of measuring there whatever the content now says, so the layout had two stable answers and which one it reached depended on the tree's history. `tests/unsettled.rs` has the two shrunk cases: the four-widget aligned span, and a scroll placing a pass-through `SetSize` in a box the content decided, where the span under it was placed once and nothing at its own edge said so. `ActiveData::offered_px` keeps the pixel size of the box the parent first asked about the child in, whether through `known_len` or a first `place`, beside `px`, the box it drew against. A dirty widget whose size reads an axis on which some reader up its chain gave what it read a box other than the one it asked in is not drawn locally: the chain is marked and the parent of the highest such placement draws, since above it every box is a constraint rather than an answer. The walk goes up the whole reader chain because a pass-through hands a derived box down unchanged. `Scroll` read its box's length for the clamp through `px_len`, which records the reported size as depending on it, and it does not: its size is its content's. That made every scroll tick a size question asked in a derived box, at 34x the instructions. `Painter::px_len_for_draw` is the read that records nothing. Instructions per frame on the depth-8 rig against the previous head: `many` at 32 dirty 0.66M to 0.74M, at 130 dirty 27.7M to 26.5M, `resize` 15.8M to 15.0M, `scroll`, `repaint` and `size` unchanged. The shrinking fuzzer passes 200 trees at depth 7 in all four cases, the hundred-seed sweep passes, and the five reference renders and the resize render are byte-identical. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
65f68bbb8a
commit
02ff8c7454
6 files changed
+200
-51
No files matched your search
+28
-1
@@ -21,6 +21,9 @@ pub struct Painter<'a> {
|
||||
pub(super) textures: Vec<TextureHandle>,
|
||||
pub(super) primitives: Vec<PrimitiveHandle>,
|
||||
pub(super) children: Vec<WidgetId>,
|
||||
/// The children asked about so far, so the first box each was asked
|
||||
/// about is the one recorded as its offer.
|
||||
pub(super) offered: Vec<WidgetId>,
|
||||
/// The children whose size this widget read while drawing.
|
||||
pub(super) size_deps: Vec<WidgetId>,
|
||||
/// Offered pixel axes which can affect the size this draw reports.
|
||||
@@ -141,6 +144,7 @@ impl<'a> Painter<'a> {
|
||||
None,
|
||||
self.rsc,
|
||||
);
|
||||
self.offer(id.id(), region);
|
||||
DrawResult {
|
||||
child: id,
|
||||
painter: self,
|
||||
@@ -182,6 +186,8 @@ impl<'a> Painter<'a> {
|
||||
axis: Axis,
|
||||
region: UiRegion,
|
||||
) -> Option<Len> {
|
||||
let region = region.within(&self.region);
|
||||
self.offer(child.id(), region);
|
||||
if let Some(hint) = self.size_hint(child, axis) {
|
||||
return Some(hint);
|
||||
}
|
||||
@@ -189,12 +195,12 @@ impl<'a> Painter<'a> {
|
||||
.map(|size| size.axis(axis))
|
||||
}
|
||||
|
||||
/// `region` in this widget's own coordinates.
|
||||
fn retained_size<W: ?Sized>(
|
||||
&mut self,
|
||||
child: &StrongWidget<W>,
|
||||
region: UiRegion,
|
||||
) -> Option<Size> {
|
||||
let region = region.within(&self.region);
|
||||
let (size, box_inputs, output_inputs) =
|
||||
self.state
|
||||
.retained_size(child.id(), region, self.move_idx, self.rsc.widgets())?;
|
||||
@@ -204,6 +210,20 @@ impl<'a> Painter<'a> {
|
||||
Some(size)
|
||||
}
|
||||
|
||||
/// Records the box a child was first asked about in this draw. Any later
|
||||
/// box this draw gives it was decided knowing its answer, so a size the
|
||||
/// child measures there is not an answer to this widget's question.
|
||||
fn offer(&mut self, child: WidgetId, region: UiRegion) {
|
||||
if self.offered.contains(&child) {
|
||||
return;
|
||||
}
|
||||
self.offered.push(child);
|
||||
let px = self.state.px_of(self.move_idx, region);
|
||||
if let Some(active) = self.state.active.get_mut(&child) {
|
||||
active.offered_px = px;
|
||||
}
|
||||
}
|
||||
|
||||
/// Depends on a length the child gave without being drawn. A hint is
|
||||
/// context-free, so this depends on the child but on no pixel axis.
|
||||
fn depend_on_hint<W: ?Sized>(&mut self, child: &StrongWidget<W>) {
|
||||
@@ -309,6 +329,13 @@ impl<'a> Painter<'a> {
|
||||
/// [`Self::px_size`] when the other axis cannot affect the reported size.
|
||||
pub fn px_len(&mut self, axis: Axis) -> f32 {
|
||||
self.size_box_inputs[axis as usize] = true;
|
||||
self.px_len_for_draw(axis)
|
||||
}
|
||||
|
||||
/// One axis of this widget's box in pixels, for a draw whose reported
|
||||
/// size does not follow from it -- a clamp or a position. Nothing records
|
||||
/// the read, so a size that does depend on it would go stale.
|
||||
pub fn px_len_for_draw(&self, axis: Axis) -> f32 {
|
||||
let region = self.state.moves.resolve(self.move_idx, self.region);
|
||||
region
|
||||
.size()
|
||||
|
||||
Reference in new issue
Block a user