Rename a length's abs component to px

`dp` is coming, and then `abs` says which of the two it is not. The
component has always been a pixel count, so the name that admits it is
the one that leaves room for a second unit beside it.

Mechanical: the field on `Len` and `UiScalar`, their constructors,
`to_abs`/`get_abs`, the matching WGSL struct member and the locals
composing it. Field order and types are unchanged, so the `Pod` layout
the shader reads is the same bytes. `f32::abs` is untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
iris-aiandClaude Opus 5 committed 2026-09-14 22:29:20 -04:00
1 parent 3f7cd8251b
commit 7c50a3e51b
22 files changed
+120 -124

No files matched your search

+1 -1
View File
@@ -80,7 +80,7 @@ fn fill(ui: &mut UiData, render: &mut UiRenderState, depth: usize) {
slot = render.moves.push(slot, UiRegion::FULL);
}
let px = |v: f32| UiScalar { rel: 0.0, abs: v };
let px = |v: f32| UiScalar { rel: 0.0, px: v };
for i in 0..INSTANCES {
let x = (i % (SIZE as usize / 2)) as f32 * 2.0;
let y = (i / (SIZE as usize / 2)) as f32;
+2 -2
View File
@@ -46,8 +46,8 @@ fn plant(h: &mut Harness, seed: u64, edits: &Edits) -> Tree {
fn resize_one(h: &mut Harness, tree: &Tree, idx: usize, rng: &mut Rng) -> Lens {
let lens = [
Some(Len::abs(20.0 + rng.below(180) as f32)),
Some(Len::abs(20.0 + rng.below(180) as f32)),
Some(Len::px(20.0 + rng.below(180) as f32)),
Some(Len::px(20.0 + rng.below(180) as f32)),
];
let sized = &mut h.rsc[tree.sized[idx]];
sized.x = lens[0];
+5 -5
View File
@@ -54,7 +54,7 @@ fn a_child_drawn_twice_moves_once() {
h.set_root((left, centered).span(Dir::RIGHT));
assert_corners!(h, inner, (100, 0), (300, 200));
h.rsc[left].x = Some(Len::abs(150));
h.rsc[left].x = Some(Len::px(150));
h.frame();
assert_corners!(h, inner, (150, 0), (350, 200));
@@ -104,7 +104,7 @@ fn a_fixed_box_is_drawn_again_rather_than_stretched() {
h.set_root(stack.align(Align::TOP));
assert_corners!(h, panel, (0, 0), (400, 100));
h.rsc[leaf].y = Some(Len::abs(250));
h.rsc[leaf].y = Some(Len::px(250));
h.frame();
assert_corners!(h, panel, (0, 0), (400, 250));
@@ -119,7 +119,7 @@ fn a_moved_subtree_takes_its_children_with_it() {
h.set_root((first, row).span(Dir::DOWN));
assert_corners!(h, inner, (10, 50), (390, 70));
h.rsc[first].y = Some(Len::abs(80));
h.rsc[first].y = Some(Len::px(80));
h.frame();
// The row is the same shape somewhere else, so one slot moved it and
@@ -140,7 +140,7 @@ fn a_fixed_length_child_keeps_it_when_the_box_around_it_grows() {
assert_corners!(h, fixed, (100, 0), (150, 200));
assert_corners!(h, rest, (150, 0), (400, 200));
h.rsc[bar].x = Some(Len::abs(200));
h.rsc[bar].x = Some(Len::px(200));
h.frame();
// The panel's box is 100 shorter, so the fixed child is the same 50 wide
@@ -163,7 +163,7 @@ fn a_box_with_a_fixed_length_can_be_stretched_on_its_other_axis() {
h.set_root((bar, column).span(Dir::RIGHT));
assert_corners!(h, inner, (110, 10), (390, 30));
h.rsc[bar].x = Some(Len::abs(200));
h.rsc[bar].x = Some(Len::px(200));
h.frame();
assert_corners!(h, inner, (210, 10), (390, 30));
+1 -1
View File
@@ -216,7 +216,7 @@ fn layout_cost() {
trace_selected(&tree);
let sized = tree.sized[0];
run("size", frames, &mut harness, move |harness, frame| {
harness.rsc[sized].x = Some(Len::abs(100.0 + (frame % 2) as f32 * 40.0));
harness.rsc[sized].x = Some(Len::px(100.0 + (frame % 2) as f32 * 40.0));
});
}
+1 -1
View File
@@ -37,7 +37,7 @@ fn replacing_rows_every_frame() {
}
h.set_root(span);
for i in 0..FRAMES {
h.rsc[first].y = Some(Len::abs(40.0 + (i % 2) as f32));
h.rsc[first].y = Some(Len::px(40.0 + (i % 2) as f32));
h.frame();
}
}
+11 -11
View File
@@ -156,7 +156,7 @@ impl Widget for FromHint {
fn draw(&mut self, painter: &mut Painter) -> Size {
let len = painter.size_hint(&self.inner, Axis::Y).unwrap();
let mut region = UiRegion::FULL;
region.y.end = region.y.start.offset(len.abs);
region.y.end = region.y.start.offset(len.px);
painter.widget_within(&self.inner, region);
Size::REST
}
@@ -173,7 +173,7 @@ fn a_parent_that_only_read_a_hint_relays_out_when_the_hint_changes() {
h.set_root(parent);
assert_corners!(h, inner, (0, 0), (400, 80));
h.rsc[inner].y = Some(Len::abs(120));
h.rsc[inner].y = Some(Len::px(120));
h.frame();
assert_corners!(h, inner, (0, 0), (400, 120));
@@ -187,7 +187,7 @@ struct ReadsOutput {
impl Widget for ReadsOutput {
fn draw(&mut self, painter: &mut Painter) -> Size {
self.draws.set(self.draws.get() + 1);
Size::abs(painter.output_size() / 4.0)
Size::px(painter.output_size() / 4.0)
}
}
@@ -198,7 +198,7 @@ struct ReadsWidth {
impl Widget for ReadsWidth {
fn draw(&mut self, painter: &mut Painter) -> Size {
self.draws.set(self.draws.get() + 1);
Size::abs((painter.output_len(Axis::X) / 4.0, 20.0).into())
Size::px((painter.output_len(Axis::X) / 4.0, 20.0).into())
}
}
@@ -287,12 +287,12 @@ fn subpixel_box_changes_accumulate_from_the_last_draw() {
let settled = draws.get();
for width in [100.02, 100.04, 100.05] {
h.rsc[first].size.x = Len::abs(width);
h.rsc[first].size.x = Len::px(width);
h.frame();
assert_eq!(draws.get(), settled);
}
h.rsc[first].size.x = Len::abs(100.06);
h.rsc[first].size.x = Len::px(100.06);
h.frame();
assert_eq!(draws.get(), settled + 1);
}
@@ -342,13 +342,13 @@ fn a_change_two_levels_under_its_reader_still_reaches_it() {
// Every wrapper up to the outer pad read the size below it, so the outer
// pad is what draws again -- and the span it hands the box to is the same
// size as before, which is what lets a draw reuse its way past the leaf.
let (leaf, _) = counted(&mut h, Size::abs((100, 100).into()), OnResize::Redraw);
let (leaf, _) = counted(&mut h, Size::px((100, 100).into()), OnResize::Redraw);
let padded = leaf.pad(10).add(&mut h.rsc);
let below = rect(Color::RED).add(&mut h.rsc);
h.set_root((padded, below).span(Dir::DOWN).pad(12));
assert_corners!(h, below, (12, 132), (388, 388));
h.rsc[leaf].size = Size::abs((100, 200).into());
h.rsc[leaf].size = Size::px((100, 200).into());
h.frame();
assert_corners!(h, below, (12, 232), (388, 388));
@@ -387,7 +387,7 @@ fn stretching_a_subtree_carries_the_children_in_it() {
let settled = draws.get();
assert_corners!(h, inner, (0, 40), (400, 400));
h.rsc[first].y = Some(Len::abs(80));
h.rsc[first].y = Some(Len::px(80));
h.frame();
assert_eq!(
@@ -411,7 +411,7 @@ fn a_widened_row_redraws_what_reads_its_length_and_nothing_else() {
h.set_root((bar, row).span(Dir::RIGHT));
let (settled_wrap, settled_back) = (wrap_draws.get(), back_draws.get());
h.rsc[bar].x = Some(Len::abs(200));
h.rsc[bar].x = Some(Len::px(200));
h.frame();
// The span reads every child's size, so redrawing one takes the span
@@ -437,7 +437,7 @@ fn a_declared_length_child_is_not_redrawn_when_the_box_around_it_grows() {
h.set_root((bar, row).span(Dir::RIGHT));
let settled = draws.get();
h.rsc[bar].x = Some(Len::abs(200));
h.rsc[bar].x = Some(Len::px(200));
h.frame();
assert_eq!(draws.get(), settled, "its own length did not change");
+1 -5
View File
@@ -94,11 +94,7 @@ fn build(h: &mut Harness, rows: usize) -> Vec<WidgetId> {
let mut col = Span::empty(Dir::DOWN);
for _ in 0..rows {
let mut row = Span::empty(Dir::RIGHT);
row.push(
rect(Color::RED)
.width(Len::abs(40.0))
.add_strong(&mut h.rsc),
);
row.push(rect(Color::RED).width(Len::px(40.0)).add_strong(&mut h.rsc));
let mut body = Span::empty(Dir::DOWN);
let para = wtext(words(&mut rng, 12, 52))
.size(16)