Put lengths, padding, gaps and alignment on the grid too

`Len` is `Px` beside `Rel` beside `Weight`, so the seam `4e28f10` left in
`Span` -- a float length added to a fixed-point cursor -- is gone, and the
sum a span compares against its box is exact.

`Weight` is its own scale, `Fixed<16>`, because a share of what is left over
is not a fraction of anything: a list divides its room by the total of them,
so the range has to hold a whole list's worth while the precision only has to
tell two weights apart. `Rel::ratio` turns two weights into a share on the
finer grid, which is what a span needs and what dividing them on their own
grid would round away.

`AxisAlign` holds a `Rel` rather than a float, which is what the layout was
reading out of it anyway. `Padding` and `Span::gap` hold `Px`, converted
where they are built instead of on every frame. `RegionAlign::rel` is gone;
its one caller wanted a position, and now builds one.

`Fixed` gains `from_num` for a number as it is written in source, `mul_int`
for a length repeated a whole number of times, and `ratio`.

Checked: fmt, clippy, 101 tests, 100 generated seeds in 86 s, all five
shrinker cases at 300 seeds, and all five examples byte-identical at
1920x1200 against `4e28f10`.

With the fuzzer comparing for equality rather than within 0.05 px, four of
the five cases now pass 100 seeds -- `resize-repaint` joins the other three.
`reorder` still fails one seed by one step, so the last of it is in what a
box is measured *in*: `px_len` and the window are still floats.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
iris-aiandClaude Opus 5 committed 2026-09-16 01:40:42 -04:00
1 parent 4e28f1047e
commit bd6de71a55
15 files changed
+199 -158

No files matched your search

+2 -2
View File
@@ -22,7 +22,7 @@ struct BranchesOnMeasurement {
impl Widget for BranchesOnMeasurement {
fn draw(&mut self, painter: &mut Painter) -> Size {
let mut top = UiRegion::FULL;
top.y.end = top.y.start.offset(40.0);
top.y.end = top.y.start.offset(Px::from_int(40));
let measured = painter.widget_within(&self.probe, top).len(Axis::X);
let px = measured
.apply_leftover()
@@ -30,7 +30,7 @@ impl Widget for BranchesOnMeasurement {
.to_f32();
let mut below = UiRegion::FULL;
below.y.start = below.y.start.offset(40.0);
below.y.start = below.y.start.offset(Px::from_int(40));
match px > self.threshold {
true => painter.widget_within(&self.wide, below),
false => painter.widget_within(&self.narrow, below),
+4 -4
View File
@@ -340,10 +340,10 @@ fn hairlines(h: &mut Harness, depth: usize, marks: &mut Vec<WidgetId>) -> Strong
let second = hairlines(h, depth - 1, marks);
let second = Pad {
padding: Padding {
left: 3.0,
right: 7.0,
top: 0.0,
bottom: 0.0,
left: Px::from_int(3),
right: Px::from_int(7),
top: Px::ZERO,
bottom: Px::ZERO,
},
inner: second,
}
+5 -9
View File
@@ -119,7 +119,7 @@ impl Node {
let handle = Span {
children,
dir: dir(*down),
gap: *gap,
gap: Px::from_f32(*gap),
ortho: match down {
true => OrthoSize::Children,
false => OrthoSize::Full,
@@ -140,12 +140,7 @@ impl Node {
Node::Pad(p, kid) => {
let inner = kid.build(h, out, spans, sized);
Pad {
padding: Padding {
left: *p,
right: *p,
top: *p,
bottom: *p,
},
padding: Padding::uniform(*p),
inner,
}
.add_strong(&mut h.rsc)
@@ -407,9 +402,10 @@ enum Case {
/// A different declared length, kept the same kind so the change is to the
/// value alone.
fn resized_len(len: Option<Len>) -> Option<Len> {
let half = Rel::from_f32(0.5);
len.map(|len| Len {
px: len.px * 0.5 + 13.0,
rel: len.rel * 0.5,
px: len.px.mul(half) + Px::from_int(13),
rel: len.rel.mul(half),
leftover: len.leftover,
})
}
+5 -5
View File
@@ -159,7 +159,7 @@ fn plant_pair(h: &mut Harness, swapped: bool) -> (Vec<WidgetId>, WeakWidget<Span
let span = Span {
children,
dir: Dir::RIGHT,
gap: 0.0,
gap: Px::ZERO,
ortho: OrthoSize::Children,
}
.add(&mut h.rsc);
@@ -213,7 +213,7 @@ fn plant_scrolled(h: &mut Harness, swapped: bool) -> (Vec<WidgetId>, [WeakWidget
let inner = Span {
children: inner_children,
dir: Dir::RIGHT,
gap: 0.0,
gap: Px::ZERO,
ortho: OrthoSize::Children,
}
.add(&mut h.rsc);
@@ -227,7 +227,7 @@ fn plant_scrolled(h: &mut Harness, swapped: bool) -> (Vec<WidgetId>, [WeakWidget
let outer = Span {
children: outer_children,
dir: Dir::RIGHT,
gap: 0.0,
gap: Px::ZERO,
ortho: OrthoSize::Children,
}
.add(&mut h.rsc);
@@ -333,7 +333,7 @@ fn plant_boundary(h: &mut Harness, swapped: bool) -> (Vec<WidgetId>, [WeakWidget
let measured = Span {
children: pair,
dir: Dir::DOWN,
gap: 0.0,
gap: Px::ZERO,
ortho: OrthoSize::Children,
}
.add(&mut h.rsc);
@@ -353,7 +353,7 @@ fn plant_boundary(h: &mut Harness, swapped: bool) -> (Vec<WidgetId>, [WeakWidget
let inner = Span {
children: inner_children,
dir: Dir::DOWN,
gap: 0.0,
gap: Px::ZERO,
ortho: OrthoSize::Children,
}
.add(&mut h.rsc);