Make the frame a length of the window and the box a region

There is one coordinate unit, the window. Every box in the tree is a
region in window units and a widget's frame is a length in the same
units, which is only what fractions resolve against, so the box need not
be the frame and padding can take from both without either becoming the
other. A region node's entry is a translation -- a rel 1 region anchored
where its box starts -- rather than a box, so nothing composes a frame
back up a chain and a node that moves is one entry write.

Padding is then an inset of both: its pixels come off the frame, so
rel(1.0) under it fills the padded widget rather than overflowing it,
and off the box, so what is drawn sits inside. A length a container
decides for a child's frame is a length of the window like everything
else here -- a row's slot, padding's frame less its pixels, or the box a
stack's sizing child decided, which arrives as Part::Sized -- because a
slot of a row is not a fraction of anything the row can name, the same
reason a node entry is a translation. A declaration is a fraction of
whichever of those reached it, and is the only one that also places the
box.

Frame validity is a pin beside the box's, not a range: a range of window
pixels cannot say which frame an answer is a fraction of, since two
frames are different lengths at the same window size. A widget pins its
frame by reading it or by being answered with it under a fractional
rule, and the pin composes up wherever a length of this frame is what
reached the child.

Also here, because the diagnosis needed them: the shrinker reports the
shrunk tree's own divergence with each level's frame, ask, box and size
warm against cold, and there is a size-resize case -- a change and then a
resize, the order that shows an answer kept as a fraction of the wrong
length, which every other case compares at the window it was made at.

Three defects the reports found, each pinned: a rule changed over two
pads relocated the column under them instead of dividing it again (seed
59, depth 5, resize-size), a share inside padding had the padding taken
off twice, and a root resolved its own rule twice.

fmt and clippy clean with and without layout-diagnostics, 121 suite, 20
core, 11 generated, the 400-seed depth-5 shrinker over all sixteen cases.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
iris-aiandClaude Opus 5 committed 2026-09-19 00:14:46 -04:00
1 parent 0ef87ebfcf
commit 1512d8418b
15 files changed
+680 -444

No files matched your search

+15 -7
View File
@@ -14,12 +14,11 @@ impl Widget for Pad {
// widget -- the slack is the inner's to sit in, and forcing the near
// edge pinned it to a corner it had not asked for.
//
// The padding goes around what it pads: the frame passes through, so
// the inner's fractions mean what they would without it, and only
// the box it draws in is moved in by the pixels. Said as a part of
// this widget's own box in that box's own lengths, so nothing here
// reads how long the box is -- and a box chosen from this widget's
// own answer therefore does not feed back into that answer.
// Padding is an inset of both: it comes off the frame, so `rel(1)`
// under it fills this widget rather than overflowing it by the
// padding, and it comes off the box, so what is drawn sits inside.
// The two stay distinct -- the box can be narrower still, where a row
// asked this widget in the room left, and a text wraps at that.
let inset = |lead: Px, trail: Px| {
Place::Within(Part::Of(UiSpan::new(
Len::from_parts(Rel::ZERO, lead),
@@ -30,7 +29,16 @@ impl Widget for Pad {
inset(self.padding.left, self.padding.right),
inset(self.padding.top, self.padding.bottom),
];
let inner = painter.widget_at(&self.inner, [None; 2], place).size();
// Read from this widget's own frame rather than written as a
// fraction of it: a frame is a length of the window like everything
// else here, and taking the padding off is the whole of what this
// widget does to it.
let narrow = [
(Axis::X, self.padding.left + self.padding.right),
(Axis::Y, self.padding.top + self.padding.bottom),
]
.map(|(axis, pixels)| Some(painter.frame_len(axis) - Len::from_parts(Rel::ZERO, pixels)));
let inner = painter.widget_at(&self.inner, narrow, place).size();
Size {
x: LayoutLen {
px: inner.x.px + self.padding.left + self.padding.right,
+2 -1
View File
@@ -16,7 +16,8 @@ impl Widget for Scroll {
let answer_len = painter
.widget_at(&self.inner, [None; 2], [Place::Fill(Part::All); 2])
.len(self.axis);
let fixed = Len::from_parts(answer_len.rel, answer_len.px).to_px(container_len);
let fixed =
Len::from_parts(answer_len.rel, answer_len.px).to_px(painter.window_px_len(self.axis));
self.container_len = container_len;
self.content_len = fixed.max(container_len);
+2 -2
View File
@@ -68,12 +68,12 @@ impl Widget for Span {
// exist at all turns on this.
let mut shares = false;
if total.leftover > Weight::ZERO {
shares = room.to_px(painter.frame_px_len(axis)) > Px::ZERO;
shares = room.to_px(painter.window_px_len(axis)) > Px::ZERO;
let holds = match shares {
true => Holds::from(Px::STEP..=Px::MAX),
false => Holds::from(Px::MIN..=Px::ZERO),
};
painter.frame_holds(axis, holds.through(room));
painter.window_holds(axis, holds.through(room));
}
// Across itself a span is as long as its longest child -- unless a
+6 -3
View File
@@ -33,16 +33,19 @@ impl Widget for Stack {
// fraction under them is a fraction of it. A share leaves the axis
// to whoever gave the stack its box. Where a child sits in a box
// bigger than itself is its own business.
let narrow = [Axis::X, Axis::Y].map(|axis| {
let place = [Axis::X, Axis::Y].map(|axis| {
let len = size.axis(axis);
(len.leftover == Weight::ZERO).then(|| Len::from_parts(len.rel, len.px))
match len.leftover == Weight::ZERO {
true => Place::Fill(Part::Sized(Len::from_parts(len.rel, len.px))),
false => Place::Within(Part::All),
}
});
for (i, child) in self.children.iter().enumerate() {
if sizing == Some(i) {
continue;
}
painter.child_layer_at(i);
painter.widget_at(child, narrow, [Place::Within(Part::All); 2]);
painter.widget_at(child, [None; 2], place);
}
size
}