Put place before the rel base, and say what a Place decides

An argument that is usually `None` goes last. So `widget_at` and `place_at`
take the place first, and `narrow_rel_base` after it.

`Place` and `Part` also now say which of the two boxes they decide, since
that is the question a caller has to answer to pick between them: `Part` is
the child's region, said as a part of the caller's own, and `Within`/`Fill`
is what becomes of the placement in it.
This commit is contained in:
iris-ai committed 2026-09-19 17:16:41 -04:00
1 parent beb138632a
commit c55be21761
8 files changed
+41 -38

No files matched your search

+12 -12
View File
@@ -169,30 +169,30 @@ impl<'a> Painter<'a> {
let len = region.axis(axis).len(); let len = region.axis(axis).len();
(len != Len::FULL).then(|| len.within_len(self.rel_base(axis))) (len != Len::FULL).then(|| len.within_len(self.rel_base(axis)))
}); });
self.widget_at(id, narrow, region_places(region)) self.widget_at(id, region_places(region), narrow)
} }
/// Asks a child, saying what its fractions are of and where it is asked. /// Asks a child, saying what its fractions are of and where it is asked.
/// ///
/// `place` is the child's region, per axis, said as a part of this
/// widget's own: see [`Place`]. The child draws once, in that region,
/// and its answer is placed inside it by re-expressing the drawing.
/// Nothing is drawn again in a box an answer chose; a container that
/// puts the answer somewhere else says so with [`Self::place_at`].
///
/// `narrow_rel_base` is the child's rel base, per axis, as a length of /// `narrow_rel_base` is the child's rel base, per axis, as a length of
/// the window: a resolved share, or a box a sibling's answer decided. /// the window: a resolved share, or a box a sibling's answer decided.
/// `None`, whole or per axis, forwards this widget's own -- which is /// `None`, whole or per axis, forwards this widget's own -- which is
/// what a container that only divides room passes, so a fraction under /// what a container that only divides room passes, so a fraction under
/// it means the same wherever it sits and however deeply it is nested. /// it means the same wherever it sits and however deeply it is nested.
/// It only ever narrows: a length the child declares narrows it again /// It only ever narrows: a length the child declares narrows it again
/// here whatever the caller says, and what comes of it is also the box /// here whatever the caller says, and what comes of it also narrows the
/// the child is asked in, placed in the part by the child's alignment. /// region, placed in the part by the child's alignment.
///
/// `place` is where the child is asked, per axis, as a part of this
/// widget's box: see [`Place`]. The child draws once, in that box, and
/// its answer is placed inside it by re-expressing the drawing. Nothing
/// is drawn again in a box an answer chose; a container that puts the
/// answer somewhere else says so with [`Self::place_at`].
pub fn widget_at<'s, W: ?Sized>( pub fn widget_at<'s, W: ?Sized>(
&'s mut self, &'s mut self,
id: &'s StrongWidget<W>, id: &'s StrongWidget<W>,
narrow_rel_base: impl Into<Option<[Option<Len>; 2]>>,
place: [Place; 2], place: [Place; 2],
narrow_rel_base: impl Into<Option<[Option<Len>; 2]>>,
) -> DrawResult<'s, 'a, W> { ) -> DrawResult<'s, 'a, W> {
let narrow_rel_base = narrow_rel_base.into().unwrap_or([None; 2]); let narrow_rel_base = narrow_rel_base.into().unwrap_or([None; 2]);
let region_node = self.rsc.widgets().is_region_node(id.id()); let region_node = self.rsc.widgets().is_region_node(id.id());
@@ -273,12 +273,12 @@ impl<'a> Painter<'a> {
pub fn place_at<'s, W: ?Sized>( pub fn place_at<'s, W: ?Sized>(
&'s mut self, &'s mut self,
id: &'s StrongWidget<W>, id: &'s StrongWidget<W>,
narrow_rel_base: impl Into<Option<[Option<Len>; 2]>>,
place: [Place; 2], place: [Place; 2],
narrow_rel_base: impl Into<Option<[Option<Len>; 2]>>,
) -> DrawResult<'s, 'a, W> { ) -> DrawResult<'s, 'a, W> {
let narrow_rel_base = narrow_rel_base.into().unwrap_or([None; 2]); let narrow_rel_base = narrow_rel_base.into().unwrap_or([None; 2]);
if narrow_rel_base.iter().any(Option::is_some) || !self.children.contains(&id.id()) { if narrow_rel_base.iter().any(Option::is_some) || !self.children.contains(&id.id()) {
return self.widget_at(id, narrow_rel_base, place); return self.widget_at(id, place, narrow_rel_base);
} }
let at = self.placing(); let at = self.placing();
self.state.place_in(id.id(), &at, place, self.rsc); self.state.place_in(id.id(), &at, place, self.rsc);
+10 -7
View File
@@ -1,6 +1,7 @@
use crate::{AxisAlign, Len, PrimitiveHandle, UiRegion, UiSpan}; use crate::{AxisAlign, Len, PrimitiveHandle, UiRegion, UiSpan};
/// What of a widget's own box a child is given, along one axis. /// A child's region along one axis, said as a part of the region the widget
/// saying it was given.
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
pub enum Part { pub enum Part {
/// Window lengths from where the box starts, which is what a container /// Window lengths from where the box starts, which is what a container
@@ -8,7 +9,7 @@ pub enum Part {
/// length, so the cursor that sums those reports is one too. A moved box /// length, so the cursor that sums those reports is one too. A moved box
/// re-places every child by re-adding its start, exactly. A fraction /// re-places every child by re-adding its start, exactly. A fraction
/// here is a fraction of the window and not of the box -- the whole of a /// here is a fraction of the window and not of the box -- the whole of a
/// box is `Of(UiSpan::FULL)`, not a `rel(1.0)` span. /// box is [`Self::WHOLE`], not a `rel(1.0)` span.
From(UiSpan), From(UiSpan),
/// A part of the box in its own coordinates, which is what a container /// A part of the box in its own coordinates, which is what a container
/// that insets one speaks: taking eleven pixels off the end needs no /// that insets one speaks: taking eleven pixels off the end needs no
@@ -42,12 +43,14 @@ impl Part {
} }
} }
/// Where a child goes along one axis, as a part of this widget's box. /// A child's region along one axis, and what becomes of its placement in
/// that region once it has answered.
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
pub enum Place { pub enum Place {
/// The child's answer, aligned inside the part by the child's alignment. /// The placement is the child's answer, aligned inside the region by the
/// child's alignment.
Within(Part), Within(Part),
/// Exactly the part; the answer is not placed inside it again. /// The region is the placement; the answer is not placed inside it again.
Fill(Part), Fill(Part),
} }
@@ -58,8 +61,8 @@ impl Place {
} }
} }
/// Whether the part is the drawing's box outright, rather than the box /// Whether the region is the placement outright, rather than a box the
/// the answer is placed inside. /// answer is placed inside.
pub(crate) fn fills(self) -> bool { pub(crate) fn fills(self) -> bool {
matches!(self, Self::Fill(_)) matches!(self, Self::Fill(_))
} }
+3 -3
View File
@@ -120,7 +120,7 @@ impl Widget for Branch {
let cut = Len::from_parts(Rel::ZERO, Px::from_int(40)); let cut = Len::from_parts(Rel::ZERO, Px::from_int(40));
let top = Place::Within(Part::From(UiSpan::new(Len::ZERO, cut))); let top = Place::Within(Part::From(UiSpan::new(Len::ZERO, cut)));
let measured = painter let measured = painter
.widget_at(&self.probe, None, [Place::Within(Part::WHOLE), top]) .widget_at(&self.probe, [Place::Within(Part::WHOLE), top], None)
.len(Axis::X); .len(Axis::X);
let len = measured.apply_leftover(); let len = measured.apply_leftover();
let px = painter.to_px(len, Axis::X); let px = painter.to_px(len, Axis::X);
@@ -137,8 +137,8 @@ impl Widget for Branch {
let below = Place::Within(Part::From(UiSpan::new(cut, painter.region_len(Axis::Y)))); let below = Place::Within(Part::From(UiSpan::new(cut, painter.region_len(Axis::Y))));
let place = [Place::Within(Part::WHOLE), below]; let place = [Place::Within(Part::WHOLE), below];
match px > threshold { match px > threshold {
true => painter.widget_at(&self.wide, None, place), true => painter.widget_at(&self.wide, place, None),
false => painter.widget_at(&self.narrow, None, place), false => painter.widget_at(&self.narrow, place, None),
}; };
Size::LEFTOVER Size::LEFTOVER
} }
+2 -2
View File
@@ -14,7 +14,7 @@ impl Widget for Scroll {
let container_len = painter.px_len(self.axis); let container_len = painter.px_len(self.axis);
// Asked in the whole viewport, then put at the scrolled offset. // Asked in the whole viewport, then put at the scrolled offset.
let answer_len = painter let answer_len = painter
.widget_at(&self.inner, None, [Place::Fill(Part::WHOLE); 2]) .widget_at(&self.inner, [Place::Fill(Part::WHOLE); 2], None)
.len(self.axis); .len(self.axis);
let fixed = painter.to_px(Len::from_parts(answer_len.rel, answer_len.px), self.axis); let fixed = painter.to_px(Len::from_parts(answer_len.rel, answer_len.px), self.axis);
self.container_len = container_len; self.container_len = container_len;
@@ -64,9 +64,9 @@ impl Widget for Scroll {
// box, scrolled: its drawing moved there, not made again there. // box, scrolled: its drawing moved there, not made again there.
painter.place_at( painter.place_at(
&self.inner, &self.inner,
None,
self.axis self.axis
.pair(Place::Fill(content), Place::Fill(Part::WHOLE)), .pair(Place::Fill(content), Place::Fill(Part::WHOLE)),
None,
); );
// What it occupies is its box, on both axes: it clips its content to // 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 // that box, so it can neither take less of one nor honestly ask for
+2 -2
View File
@@ -36,7 +36,7 @@ impl Widget for Span {
None => { None => {
let room = Place::Within(Part::From(along(cursor, far))); let room = Place::Within(Part::From(along(cursor, far)));
painter painter
.widget_at(child, None, axis.pair(room, across)) .widget_at(child, axis.pair(room, across), None)
.len(axis) .len(axis)
} }
}; };
@@ -123,7 +123,7 @@ impl Widget for Span {
let place = axis.pair(Place::Fill(Part::From(slot)), across); let place = axis.pair(Place::Fill(Part::From(slot)), across);
let narrow = let narrow =
(len.leftover > Weight::ZERO && shares).then(|| axis.pair(Some(slot.len()), None)); (len.leftover > Weight::ZERO && shares).then(|| axis.pair(Some(slot.len()), None));
let used = painter.place_at(child, narrow, place).len(!axis); let used = painter.place_at(child, place, narrow).len(!axis);
if shrinks { if shrinks {
// Choosing between a fixed and a relative length from the // Choosing between a fixed and a relative length from the
// span's own eventual width admits multiple fixed points. // span's own eventual width admits multiple fixed points.
+2 -2
View File
@@ -23,7 +23,7 @@ impl Widget for Stack {
Some((i, child)) => { Some((i, child)) => {
painter.child_layer_at(i); painter.child_layer_at(i);
painter painter
.widget_at(child, None, [Place::Fill(Part::WHOLE); 2]) .widget_at(child, [Place::Fill(Part::WHOLE); 2], None)
.size() .size()
} }
None => Size::LEFTOVER, None => Size::LEFTOVER,
@@ -45,7 +45,7 @@ impl Widget for Stack {
continue; continue;
} }
painter.child_layer_at(i); painter.child_layer_at(i);
painter.widget_at(child, None, place); painter.widget_at(child, place, None);
} }
size size
} }
+3 -3
View File
@@ -24,15 +24,15 @@ impl Widget for BranchesOnMeasurement {
let cut = Len::from_parts(Rel::ZERO, Px::from_int(40)); let cut = Len::from_parts(Rel::ZERO, Px::from_int(40));
let top = Place::Within(Part::From(UiSpan::new(Len::ZERO, cut))); let top = Place::Within(Part::From(UiSpan::new(Len::ZERO, cut)));
let measured = painter let measured = painter
.widget_at(&self.probe, None, [Place::Within(Part::WHOLE), top]) .widget_at(&self.probe, [Place::Within(Part::WHOLE), top], None)
.len(Axis::X); .len(Axis::X);
let px = painter.to_px(measured.apply_leftover(), Axis::X); let px = painter.to_px(measured.apply_leftover(), Axis::X);
let below = Place::Within(Part::From(UiSpan::new(cut, painter.region_len(Axis::Y)))); let below = Place::Within(Part::From(UiSpan::new(cut, painter.region_len(Axis::Y))));
let place = [Place::Within(Part::WHOLE), below]; let place = [Place::Within(Part::WHOLE), below];
match px > Px::from_f32(self.threshold) { match px > Px::from_f32(self.threshold) {
true => painter.widget_at(&self.wide, None, place), true => painter.widget_at(&self.wide, place, None),
false => painter.widget_at(&self.narrow, None, place), false => painter.widget_at(&self.narrow, place, None),
}; };
Size::LEFTOVER Size::LEFTOVER
} }
+7 -7
View File
@@ -216,8 +216,8 @@ impl Widget for FromHint {
let top = UiSpan::new(Len::ZERO, Len::from_parts(Rel::ZERO, len.px)); let top = UiSpan::new(Len::ZERO, Len::from_parts(Rel::ZERO, len.px));
painter.widget_at( painter.widget_at(
&self.inner, &self.inner,
[None; 2],
[Place::Within(Part::WHOLE), Place::Within(Part::From(top))], [Place::Within(Part::WHOLE), Place::Within(Part::From(top))],
None,
); );
Size::LEFTOVER Size::LEFTOVER
} }
@@ -877,11 +877,11 @@ fn resizing_a_fixed_frame_recomposes_its_contents_without_drawing_them() {
fn draw(&mut self, painter: &mut Painter) -> Size { fn draw(&mut self, painter: &mut Painter) -> Size {
painter.widget_at( painter.widget_at(
&self.child, &self.child,
[None; 2],
[ [
Place::Within(Part::From(self.region.x)), Place::Within(Part::From(self.region.x)),
Place::Within(Part::From(self.region.y)), Place::Within(Part::From(self.region.y)),
], ],
None,
); );
Size::LEFTOVER Size::LEFTOVER
} }
@@ -966,11 +966,11 @@ fn glyph_origins_compose_identically_when_drawn_and_when_retained() {
fn draw(&mut self, painter: &mut Painter) -> Size { fn draw(&mut self, painter: &mut Painter) -> Size {
painter.widget_at( painter.widget_at(
&self.child, &self.child,
[Some(self.frame.x.len()), None],
[ [
Place::Fill(Part::From(self.region.x)), Place::Fill(Part::From(self.region.x)),
Place::Fill(Part::From(self.region.y)), Place::Fill(Part::From(self.region.y)),
], ],
[Some(self.frame.x.len()), None],
); );
Size::LEFTOVER Size::LEFTOVER
} }
@@ -1136,11 +1136,11 @@ fn padding_and_stack_boxes_follow_the_region_without_drawing_again() {
fn draw(&mut self, painter: &mut Painter) -> Size { fn draw(&mut self, painter: &mut Painter) -> Size {
painter.widget_at( painter.widget_at(
&self.child, &self.child,
[None; 2],
[ [
Place::Fill(Part::From(self.region.x)), Place::Fill(Part::From(self.region.x)),
Place::Fill(Part::From(self.region.y)), Place::Fill(Part::From(self.region.y)),
], ],
None,
); );
Size::LEFTOVER Size::LEFTOVER
} }
@@ -1224,7 +1224,6 @@ fn moving_a_childs_region_preserves_the_slot_chosen_from_its_measurement() {
fn draw(&mut self, painter: &mut Painter) -> Size { fn draw(&mut self, painter: &mut Painter) -> Size {
painter.widget_at( painter.widget_at(
&self.child, &self.child,
[None; 2],
[ [
Place::Fill(Part::From(UiSpan::new( Place::Fill(Part::From(UiSpan::new(
Len::px(self.start), Len::px(self.start),
@@ -1232,6 +1231,7 @@ fn moving_a_childs_region_preserves_the_slot_chosen_from_its_measurement() {
))), ))),
Place::Fill(Part::From(UiSpan::FULL)), Place::Fill(Part::From(UiSpan::FULL)),
], ],
None,
); );
Size::LEFTOVER Size::LEFTOVER
} }
@@ -1266,11 +1266,11 @@ fn changing_regions_keep_fractional_reports_and_numeric_dependencies_valid() {
painter painter
.widget_at( .widget_at(
&self.child, &self.child,
[None; 2],
[ [
Place::Within(Part::From(self.region.x)), Place::Within(Part::From(self.region.x)),
Place::Within(Part::From(self.region.y)), Place::Within(Part::From(self.region.y)),
], ],
None,
) )
.size() .size()
} }
@@ -1286,11 +1286,11 @@ fn changing_regions_keep_fractional_reports_and_numeric_dependencies_valid() {
painter painter
.widget_at( .widget_at(
&self.child, &self.child,
[None; 2],
[ [
Place::Fill(Part::From(self.region.x)), Place::Fill(Part::From(self.region.x)),
Place::Fill(Part::From(self.region.y)), Place::Fill(Part::From(self.region.y)),
], ],
None,
) )
.size(), .size(),
); );