Keep the step 3/4 experiment as evidence
The worker's uncommitted attempt at evaluating children in parent-decided boxes, preserved as it stood when it stopped: separate answer-only pixel reads, per-child drawing contracts, provisional Fill asks in Span, and an assertion that a placed drawing hold for its answer box. The suite passes and every generated case stops on that assertion at Text. Not the protocol; wip/one-ask is. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
4328eac756
commit
aaba7dbfee
6 files changed
+180
-106
No files matched your search
+58
-4
@@ -32,6 +32,10 @@ pub struct Painter<'a> {
|
||||
/// drawing one that holds for that length alone -- the way reading a
|
||||
/// length in pixels makes it hold for that number of pixels.
|
||||
pub(super) extent_len: [Option<Len>; 2],
|
||||
/// Symbolic box lengths read only to compute the answer. A container can
|
||||
/// replace the provisional drawings used for that answer with drawings
|
||||
/// in decided boxes, so this contract is independent of the final one.
|
||||
pub(super) answer_extent_len: [Option<Len>; 2],
|
||||
/// The frame in pixels, which its children's frames are a length of:
|
||||
/// threaded down rather than composed back up the chain, so every length
|
||||
/// in layout is one multiply from its parent's and [`Holds::through`]
|
||||
@@ -58,8 +62,12 @@ pub struct Painter<'a> {
|
||||
pub(super) frame_own: [Holds; 2],
|
||||
/// The same for its own box.
|
||||
pub(super) extent_own: [Holds; 2],
|
||||
/// Dependencies of every child drawing, including unmeasured overlays.
|
||||
pub(super) under: LayoutHolds,
|
||||
/// Pixel-box dependencies used only to compute the answer. These do not
|
||||
/// constrain a retained drawing placed inside that answer.
|
||||
pub(super) answer_extent_own: [Holds; 2],
|
||||
/// The final drawing kept for each child. Asking one child again replaces
|
||||
/// its provisional drawing and therefore replaces this contract too.
|
||||
pub(super) under: Vec<(WidgetId, LayoutHolds)>,
|
||||
/// The movable region this widget's primitives are positioned through:
|
||||
/// its own when opted in, otherwise the nearest ancestor's.
|
||||
pub(super) move_idx: MoveIdx,
|
||||
@@ -228,7 +236,11 @@ impl<'a> Painter<'a> {
|
||||
self.rsc,
|
||||
);
|
||||
let compose = |holds| in_parent(holds, local, extent, place, declared);
|
||||
self.under = self.under.and(compose(holds));
|
||||
let holds = compose(holds);
|
||||
match self.under.iter_mut().find(|(child, _)| *child == id.id()) {
|
||||
Some((_, kept)) => *kept = holds,
|
||||
None => self.under.push((id.id(), holds)),
|
||||
}
|
||||
DrawResult {
|
||||
child: id,
|
||||
painter: self,
|
||||
@@ -242,6 +254,7 @@ impl<'a> Painter<'a> {
|
||||
/// this frame; what it answered is still something this widget asked.
|
||||
pub fn undraw<W: ?Sized>(&mut self, id: &StrongWidget<W>) {
|
||||
self.children.retain(|child| *child != id.id());
|
||||
self.under.retain(|(child, _)| *child != id.id());
|
||||
self.state.undraw_rec(id.id(), self.rsc);
|
||||
}
|
||||
|
||||
@@ -356,9 +369,31 @@ impl<'a> Painter<'a> {
|
||||
pub fn extent_len(&mut self, axis: Axis) -> Len {
|
||||
let len = self.extent.axis(axis).len();
|
||||
self.extent_len[axis as usize] = Some(len);
|
||||
self.answer_extent_len[axis as usize] = Some(len);
|
||||
len
|
||||
}
|
||||
|
||||
/// The symbolic length used to compute this widget's answer, where the
|
||||
/// final drawing itself is rebuilt without depending on that length.
|
||||
pub fn answer_extent_len(&mut self, axis: Axis) -> Len {
|
||||
let len = self.extent.axis(axis).len();
|
||||
self.answer_extent_len[axis as usize] = Some(len);
|
||||
len
|
||||
}
|
||||
|
||||
/// Says that the final drawing uses a symbolic length already read for
|
||||
/// the answer.
|
||||
pub fn drawing_uses_extent_len(&mut self, axis: Axis, len: Len) {
|
||||
debug_assert_eq!(self.extent.axis(axis).len(), len);
|
||||
self.extent_len[axis as usize] = Some(len);
|
||||
}
|
||||
|
||||
/// A part of this widget's box, expressed in its frame coordinates so it
|
||||
/// can be used as a child frame decided here.
|
||||
pub fn extent_part(&self, axis: Axis, part: Part) -> UiSpan {
|
||||
part.of(*self.extent.axis(axis))
|
||||
}
|
||||
|
||||
/// Where this widget sits in a box longer than the length it takes. A
|
||||
/// widget that positions its own content reads it to place that content
|
||||
/// the way the box around it would have placed the widget.
|
||||
@@ -390,6 +425,14 @@ impl<'a> Painter<'a> {
|
||||
PxVec2::new(self.px_len(Axis::X), self.px_len(Axis::Y))
|
||||
}
|
||||
|
||||
/// This widget's own box in pixels, used only to compute its answer.
|
||||
pub fn answer_px_size(&mut self) -> PxVec2 {
|
||||
PxVec2::new(
|
||||
self.answer_px_len(Axis::X),
|
||||
self.answer_px_len(Axis::Y),
|
||||
)
|
||||
}
|
||||
|
||||
/// One axis of this widget's own box in pixels. Prefer this to
|
||||
/// [`Self::px_size`] when the other axis cannot affect the drawing.
|
||||
pub fn px_len(&mut self, axis: Axis) -> Px {
|
||||
@@ -402,6 +445,17 @@ impl<'a> Painter<'a> {
|
||||
len
|
||||
}
|
||||
|
||||
/// One pixel length used only to compute this widget's answer. The final
|
||||
/// drawing may be retained when that answer is placed in another box.
|
||||
pub fn answer_px_len(&mut self, axis: Axis) -> Px {
|
||||
let len = self.extent.axis(axis).len().to_px(self.px.axis(axis));
|
||||
let own = &mut self.answer_extent_own[axis as usize];
|
||||
if *own == Holds::ANY {
|
||||
*own = Holds::at(len);
|
||||
}
|
||||
len
|
||||
}
|
||||
|
||||
/// The lengths of this widget's own box on `axis` that what it is drawing
|
||||
/// holds for -- the same primitives, in the same fractions and offsets
|
||||
/// of the box, and the same reported size. A widget that read its length
|
||||
@@ -555,7 +609,7 @@ pub(crate) fn in_parent(
|
||||
// own box, which is what lets that box move without a redraw. A
|
||||
// length it pinned is this widget's length wherever the part is
|
||||
// the whole of it, and pins the same way.
|
||||
(Part::All, None) => {
|
||||
(Part::All, None) if *frame.axis(axis) == UiSpan::FULL => {
|
||||
result.extent[n] = holds.extent[n];
|
||||
result.extent_len[n] = holds.extent_len[n];
|
||||
}
|
||||
|
||||
+41
-75
@@ -251,7 +251,7 @@ impl UiRenderState {
|
||||
true => None,
|
||||
false => self
|
||||
.retained_answer(id, part, info)
|
||||
.or_else(|| self.try_reuse(id, frame, part, info, rsc)),
|
||||
.and_then(|answer| self.try_reuse(id, frame, part, info, rsc).map(|_| answer)),
|
||||
};
|
||||
let answer = retained.unwrap_or_else(|| {
|
||||
if old.is_none() {
|
||||
@@ -265,49 +265,25 @@ impl UiRenderState {
|
||||
// axis the parent left open. The frame itself does not change, so
|
||||
// nothing under it resolves a fraction a second time.
|
||||
//
|
||||
// From the answer it gave when its parent measured it, and not from
|
||||
// what a placing evaluation reported: placing a drawing by what it
|
||||
// said in the box its own answer chose would move the box out from
|
||||
// under it.
|
||||
let measured = match info.offer() {
|
||||
true => answer.0,
|
||||
false => self.active[&id].measured().unwrap_or(answer.0),
|
||||
};
|
||||
let extent = placed_extent(
|
||||
part,
|
||||
measured,
|
||||
answer.0,
|
||||
declared_lens(rsc.widgets(), id),
|
||||
info.fill(),
|
||||
align,
|
||||
);
|
||||
self.place(id, extent, info, rsc);
|
||||
|
||||
// On axes the parent filled, measurement and drawing share an extent.
|
||||
// Otherwise the answer fixes the final extent as a function of the
|
||||
// frame, so pull that drawing's validity back through it.
|
||||
let drawing_holds = self.active[&id].holds;
|
||||
let mut settled = answer;
|
||||
for axis in AXES {
|
||||
let n = axis as usize;
|
||||
settled.1.frame[n] = settled.1.frame[n].and(drawing_holds.frame[n]);
|
||||
if info.fill()[n] {
|
||||
settled.1.extent[n] = settled.1.extent[n].and(drawing_holds.extent[n]);
|
||||
} else {
|
||||
settled.1.frame[n] = settled.1.frame[n]
|
||||
.and(drawing_holds.extent[n].through(extent.axis(axis).len()));
|
||||
}
|
||||
}
|
||||
let active = self.active.get_mut(&id).unwrap();
|
||||
// Whoever asked owns how the boxes were reached: the frame it stated,
|
||||
// and what of its own box it gave the drawing. A local redraw asks
|
||||
// the same question again from these.
|
||||
active.frame_abs = frame;
|
||||
active.frame = info.frame;
|
||||
if info.offer() {
|
||||
active.answer = Some(answer);
|
||||
active.offer_place = info.offer_place;
|
||||
active.offer_part = part;
|
||||
}
|
||||
active.answer = Some(answer);
|
||||
active.offer_place = info.offer_place;
|
||||
active.offer_part = part;
|
||||
active.place = info.place;
|
||||
active.own_align = align;
|
||||
// A subtree can be reused whole under a different parent -- same box,
|
||||
@@ -322,7 +298,7 @@ impl UiRenderState {
|
||||
{
|
||||
old_parent.children.retain(|child| *child != id);
|
||||
}
|
||||
(answer.0, answer.1, settled.1)
|
||||
(answer.0, answer.1, drawing_holds)
|
||||
}
|
||||
|
||||
/// Recompose retained geometry when the evaluation still holds at this extent.
|
||||
@@ -333,6 +309,15 @@ impl UiRenderState {
|
||||
{
|
||||
return;
|
||||
}
|
||||
assert_eq!(
|
||||
extent,
|
||||
info.part,
|
||||
"'{}' ({id:?}) does not hold for the box its answer chose: part {:?}, wanted {extent:?}, retained {:?} with {:?}",
|
||||
rsc.widgets().label(id),
|
||||
info.part,
|
||||
self.active.get(&id).map(|active| active.extent),
|
||||
self.active.get(&id).map(|active| active.holds),
|
||||
);
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
diag::bump(Counter::PlaceRedraws);
|
||||
let old = self.remove(id, false, rsc);
|
||||
@@ -376,6 +361,7 @@ impl UiRenderState {
|
||||
frame: local,
|
||||
extent,
|
||||
extent_len: [None; 2],
|
||||
answer_extent_len: [None; 2],
|
||||
px,
|
||||
mask: info.mask,
|
||||
layer: info.layer,
|
||||
@@ -389,8 +375,9 @@ impl UiRenderState {
|
||||
at_offer,
|
||||
size_deps: Vec::new(),
|
||||
frame_own: [Holds::ANY; 2],
|
||||
under: LayoutHolds::ANY,
|
||||
under: Vec::new(),
|
||||
extent_own: [Holds::ANY; 2],
|
||||
answer_extent_own: [Holds::ANY; 2],
|
||||
answer_under: LayoutHolds::ANY,
|
||||
depth: info.depth,
|
||||
move_idx,
|
||||
@@ -419,7 +406,9 @@ impl UiRenderState {
|
||||
primitives,
|
||||
mask_region,
|
||||
extent_own,
|
||||
answer_extent_own,
|
||||
extent_len,
|
||||
answer_extent_len,
|
||||
answer_under,
|
||||
children,
|
||||
offered: _,
|
||||
@@ -465,13 +454,23 @@ impl UiRenderState {
|
||||
if let Some(idx) = retired_move {
|
||||
self.moves.remove(idx);
|
||||
}
|
||||
let own_holds = LayoutHolds {
|
||||
let drawing_own = LayoutHolds {
|
||||
frame: frame_own,
|
||||
extent: extent_own,
|
||||
extent_len,
|
||||
};
|
||||
let answer_holds = own_holds.and(answer_under);
|
||||
let holds = answer_holds.and(under);
|
||||
let answer_own = LayoutHolds {
|
||||
extent: [
|
||||
drawing_own.extent[0].and(answer_extent_own[0]),
|
||||
drawing_own.extent[1].and(answer_extent_own[1]),
|
||||
],
|
||||
extent_len: answer_extent_len,
|
||||
..drawing_own
|
||||
};
|
||||
let answer_holds = answer_own.and(answer_under);
|
||||
let holds = under
|
||||
.into_iter()
|
||||
.fold(drawing_own, |holds, (_, child)| holds.and(child));
|
||||
debug_assert!(
|
||||
holds.contains(px, extent),
|
||||
"'{}' ({id:?}) drew in {px:?}, outside the ranges it reported: {holds:?}",
|
||||
@@ -1179,10 +1178,10 @@ impl UiRenderState {
|
||||
};
|
||||
let px = self.asked_px(id);
|
||||
let (was_answer, was_holds) = (active.answer, active.holds);
|
||||
// The boxes its parent gave it, then and now: its frame is the same
|
||||
// on every ask, so the question its parent asked is the one this
|
||||
// asks again -- there is no box here that could be its parent's to
|
||||
// choose instead.
|
||||
let needs_replacement = active.place != active.offer_place;
|
||||
// Re-ask the question its answer came from, not a later placement of
|
||||
// that answer. A parent may move the retained drawing into a box the
|
||||
// answer chose without making that box a new question.
|
||||
let parent_extent = self.active[&parent].extent;
|
||||
let info = DrawInfo {
|
||||
layer: active.layer,
|
||||
@@ -1193,49 +1192,16 @@ impl UiRenderState {
|
||||
mask: active.parent_mask,
|
||||
frame: active.frame,
|
||||
frame_abs: active.frame_abs,
|
||||
part: Self::re_ask(active, parent_extent, active.place).1,
|
||||
place: active.place,
|
||||
part: Self::re_ask(active, parent_extent, active.offer_place).1,
|
||||
place: active.offer_place,
|
||||
offer_place: active.offer_place,
|
||||
px,
|
||||
};
|
||||
// The ask that measured it, asked again: the box it was measured in
|
||||
// as its parent left it, rather than where that ask's place resolves
|
||||
// to now -- a parent drawn again in the box its own answer chose
|
||||
// gives its children boxes it never measured anything in.
|
||||
let offered = DrawInfo {
|
||||
place: info.offer_place,
|
||||
part: active.offer_part,
|
||||
..info
|
||||
};
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
diag::bump(Counter::LocalRedraws);
|
||||
|
||||
// Asked again in the box its parent gave it, which is the question
|
||||
// its parent asked only while that box is as long as the one it was
|
||||
// measured in. Any other box is a different question, so the parent
|
||||
// asks it, with the mark left on. Lengths and not whole boxes: what
|
||||
// a drawing depends on is its lengths, so the same lengths elsewhere
|
||||
// is one question.
|
||||
//
|
||||
// The frame is the same on every ask now, so this is about the box
|
||||
// the drawing goes in alone. Removing it -- asking the measuring
|
||||
// question here and placing the answer afterwards -- is what the
|
||||
// transparent-frames plan asks for next, and it does not hold yet:
|
||||
// seeds 104 (`align`) and 210 (`reorder`) at depth 5 settle
|
||||
// differently warm and cold without it.
|
||||
if info.part.size() != offered.part.size() {
|
||||
self.mark(id, rsc.widgets_mut());
|
||||
self.mark(parent, rsc.widgets_mut());
|
||||
return false;
|
||||
}
|
||||
let old = self.remove(id, false, rsc);
|
||||
// The original measurement is refreshed before the assigned slot is
|
||||
// restored: its lengths may differ even though the frame is
|
||||
// unchanged.
|
||||
let answer = self.draw_inner(id, offered, old, rsc);
|
||||
if info.place != info.offer_place || info.part != offered.part {
|
||||
self.draw_inner(id, info, None, rsc);
|
||||
}
|
||||
let answer = self.draw_inner(id, info, old, rsc);
|
||||
let active = self.active.get_mut(&id).unwrap();
|
||||
// A wider contract does not invalidate the guarantee the parent kept.
|
||||
// Retain that guarantee so widening and narrowing back do not churn it.
|
||||
@@ -1248,7 +1214,7 @@ impl UiRenderState {
|
||||
if active.holds.covers(was_holds) && was_holds.contains(px, active.extent) {
|
||||
active.holds = was_holds;
|
||||
}
|
||||
if active.answer != was_answer || active.holds != was_holds {
|
||||
if needs_replacement || active.answer != was_answer || active.holds != was_holds {
|
||||
// The parent retains both the answer and the drawing's validity;
|
||||
// even an unchanged size can narrow the range safe for a resize.
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
|
||||
Reference in new issue
Block a user