One argument says where a child goes and what its fractions are of

`Place` was a product written as a sum -- a `Part` and a fill flag -- and
`Part` named three operations the geometry already had, under words that did
not match them. `Of` was `UiSpan::within`, `From` was `UiSpan::shift`, and
`Sized` was `placement`'s own body with the length given rather than
reported. Both enums are gone.

`PlaceDescAxis` says one axis, named after the operation it performs:
`within`, `shifted`, `sized`, and `WHOLE`. What is optional is a builder --
`fills` and `rel_base` -- so a caller writes only what it decided, and the
rel base it does not write follows the constructor: a span composed into the
caller's box narrows it, a span along a cursor does not, a decided length is
it. That was the one rule a caller could get wrong with nothing failing.

`PlaceDesc` says both axes with named fields, so `axis`, `axis_mut` and
`from_axis` work the way they do on every other pair here, and the joint
work -- resolving a region, reading the fill flags -- is written once rather
than per axis. `widget_at` and `place_at` take `impl Into<PlaceDesc>`, so a
wrapper passes a `UiRegion` and says nothing else. `widget_within` and
`ActiveData::narrow_rel_base` are deleted; `asked` and `placed` carry the
rel base their ask stated.

Cold layout is byte-identical to `84dad21`.
This commit is contained in:
iris-ai committed 2026-09-19 17:59:26 -04:00
1 parent c55be21761
commit 58ce74dd7d
12 files changed
+367 -271

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ pub struct Offset {
impl Widget for Offset {
fn draw(&mut self, painter: &mut Painter) -> Size {
painter
.widget_within(&self.inner, UiRegion::FULL.offset(self.amt))
.widget_at(&self.inner, UiRegion::FULL.offset(self.amt))
.size()
}
}
+1 -3
View File
@@ -19,9 +19,7 @@ impl Widget for Pad {
// 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 inner = painter
.widget_within(&self.inner, self.padding.region())
.size();
let inner = painter.widget_at(&self.inner, self.padding.region()).size();
Size {
x: LayoutLen {
px: inner.x.px + self.padding.left + self.padding.right,
+4 -6
View File
@@ -14,7 +14,7 @@ impl Widget for Scroll {
let container_len = painter.px_len(self.axis);
// Asked in the whole viewport, then put at the scrolled offset.
let answer_len = painter
.widget_at(&self.inner, [Place::Fill(Part::WHOLE); 2], None)
.widget_at(&self.inner, PlaceDesc::WHOLE.fills())
.len(self.axis);
let fixed = painter.to_px(Len::from_parts(answer_len.rel, answer_len.px), self.axis);
self.container_len = container_len;
@@ -54,9 +54,9 @@ impl Widget for Scroll {
let content = match moved || self.content_len != self.container_len {
true => {
let start = Len::from_parts(Rel::ZERO, anchor - self.amt);
Part::From(UiSpan::new(start, start.offset(self.content_len)))
PlaceDescAxis::shifted(UiSpan::new(start, start.offset(self.content_len)))
}
false => Part::WHOLE,
false => PlaceDescAxis::WHOLE,
};
// The viewport is the inner's rel base, so a fraction it declares or
// reports is a fraction of what is on screen rather than of the
@@ -64,9 +64,7 @@ impl Widget for Scroll {
// box, scrolled: its drawing moved there, not made again there.
painter.place_at(
&self.inner,
self.axis
.pair(Place::Fill(content), Place::Fill(Part::WHOLE)),
None,
PlaceDesc::from_axis(self.axis, content.fills(), PlaceDescAxis::WHOLE.fills()),
);
// What it occupies is its box, on both axes: it clips its content to
// that box, so it can neither take less of one nor honestly ask for
+9 -7
View File
@@ -21,7 +21,7 @@ impl Widget for Span {
// Across itself the child sits where its own alignment says, in the
// whole of the row: a span is what contains its children there, and
// nothing divides that axis.
let across = Place::Within(Part::WHOLE);
let across = PlaceDescAxis::WHOLE;
// A length for every child before their final slots are chosen: from
// a hint where one says, and from drawing otherwise. The rel base passes
// through unchanged, so `rel(0.5)` is half the area this span was
@@ -34,9 +34,9 @@ impl Widget for Span {
let len = match painter.size_hint(child, axis) {
Some(len) => len,
None => {
let room = Place::Within(Part::From(along(cursor, far)));
let room = PlaceDescAxis::shifted(along(cursor, far));
painter
.widget_at(child, axis.pair(room, across), None)
.widget_at(child, PlaceDesc::from_axis(axis, room, across))
.len(axis)
}
};
@@ -120,10 +120,12 @@ impl Widget for Span {
// fixed child's slot is its own answer, so a drawing made in the
// room is put there as it is, and one not made yet is made here.
let slot = along(from, start);
let place = axis.pair(Place::Fill(Part::From(slot)), across);
let narrow =
(len.leftover > Weight::ZERO && shares).then(|| axis.pair(Some(slot.len()), None));
let used = painter.place_at(child, place, narrow).len(!axis);
let slot_place = PlaceDescAxis::shifted(slot).fills();
let mut place = PlaceDesc::from_axis(axis, slot_place, across);
if len.leftover > Weight::ZERO && shares {
place = place.rel_base(axis, slot.len());
}
let used = painter.place_at(child, place).len(!axis);
if shrinks {
// Choosing between a fixed and a relative length from the
// span's own eventual width admits multiple fixed points.
+7 -8
View File
@@ -22,9 +22,7 @@ impl Widget for Stack {
// drawing belongs to the layer it was made on.
Some((i, child)) => {
painter.child_layer_at(i);
painter
.widget_at(child, [Place::Fill(Part::WHOLE); 2], None)
.size()
painter.widget_at(child, PlaceDesc::WHOLE.fills()).size()
}
None => Size::LEFTOVER,
};
@@ -33,19 +31,20 @@ 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 place = [Axis::X, Axis::Y].map(|axis| {
let on = |axis| {
let len = size.axis(axis);
match len.leftover == Weight::ZERO {
true => Place::Fill(Part::Sized(Len::from_parts(len.rel, len.px))),
false => Place::Within(Part::WHOLE),
true => PlaceDescAxis::sized(Len::from_parts(len.rel, len.px)).fills(),
false => PlaceDescAxis::WHOLE,
}
});
};
let place = PlaceDesc::new(on(Axis::X), on(Axis::Y));
for (i, child) in self.children.iter().enumerate() {
if sizing == Some(i) {
continue;
}
painter.child_layer_at(i);
painter.widget_at(child, place, None);
painter.widget_at(child, place);
}
size
}