Replace placement calls with region nodes

This commit is contained in:
iris-ai committed 2026-09-15 18:02:28 -04:00
1 parent f437495309
commit 71c9c39523
23 files changed
+374 -170

No files matched your search

+16 -12
View File
@@ -21,8 +21,8 @@ pub struct Span {
impl Widget for Span {
fn draw(&mut self, painter: &mut Painter) -> Size {
let axis = self.dir.axis;
// A length for every child before any is placed: from its own hint
// where it has one, and from drawing it where it does not.
// A length for every child before their final boxes are chosen: from
// a hint where one exists, and from drawing otherwise.
let mut cursor = UiScalar::rel_min();
let mut lens = Vec::with_capacity(self.children.len());
for child in &self.children {
@@ -33,7 +33,7 @@ impl Widget for Span {
let region = UiRegion::from_axis(axis, span, UiSpan::FULL);
let len = match painter.known_len(child, axis, region) {
Some(len) => len,
None => painter.place(child, region).len(axis),
None => painter.widget_within(child, region).len(axis),
};
cursor.px += len.px + self.gap;
cursor.rel += len.rel;
@@ -47,24 +47,28 @@ impl Widget for Span {
// beside 300 px is full at 600 and overfull at 400. The answer is
// the same on either side of the length the fixed parts alone fill.
let fixed = 1.0 - total.rel;
let shares = total.leftover > 0.0 && fixed * painter.px_len(axis) > total.px;
let mut shares = false;
if total.leftover > 0.0 {
let range = if fixed > 0.0 {
let current = painter.px_len(axis);
let holds = if fixed > 0.0 {
let full = total.px / fixed;
shares = current > full;
match shares {
true => full..=f32::INFINITY,
false => f32::NEG_INFINITY..=full,
true => Holds::exact(full.next_up()..=f32::INFINITY),
false => Holds::exact(f32::NEG_INFINITY..=full),
}
} else if fixed < 0.0 {
let full = total.px / fixed;
shares = current < full;
match shares {
true => f32::NEG_INFINITY..=full,
false => full..=f32::INFINITY,
true => Holds::exact(f32::NEG_INFINITY..=full.next_down()),
false => Holds::exact(full..=f32::INFINITY),
}
} else {
f32::NEG_INFINITY..=f32::INFINITY
shares = total.px < 0.0;
Holds::ANY
};
painter.holds(axis, range);
painter.holds(axis, holds);
}
let mut start = UiScalar::rel_min();
@@ -93,7 +97,7 @@ impl Widget for Span {
if self.dir.sign == Sign::Neg {
region.flip(axis);
}
let placed = painter.place(child, region);
let placed = painter.widget_within(child, region);
if self.ortho == OrthoSize::Children {
let used = placed.len(!axis);
// Choosing between a fixed and a relative length from the