Rename rest to leftover
The length kind that asks for a part of what is left once the fixed lengths are taken is called leftover: Len::leftover(2), Len::LEFTOVER, Size::LEFTOVER, Len::leftover the field, and apply_leftover. It says what it is where "rest" reads as "the remainder of the list" as often as "the remaining space", and every agent who has touched this has reached for a third word for it. Locals called rest that meant a region or a widget are renamed with it, since the word now names something else. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9644971daf
commit
691e3eb23c
16 files changed
+98
-89
No files matched your search
@@ -24,15 +24,15 @@ impl Widget for BranchesOnMeasurement {
|
||||
let mut top = UiRegion::FULL;
|
||||
top.y.end = top.y.start.offset(40.0);
|
||||
let measured = painter.place(&self.probe, top).len(Axis::X);
|
||||
let px = measured.apply_rest().to_px(painter.px_len(Axis::X));
|
||||
let px = measured.apply_leftover().to_px(painter.px_len(Axis::X));
|
||||
|
||||
let mut rest = UiRegion::FULL;
|
||||
rest.y.start = rest.y.start.offset(40.0);
|
||||
let mut below = UiRegion::FULL;
|
||||
below.y.start = below.y.start.offset(40.0);
|
||||
match px > self.threshold {
|
||||
true => painter.place(&self.wide, rest),
|
||||
false => painter.place(&self.narrow, rest),
|
||||
true => painter.place(&self.wide, below),
|
||||
false => painter.place(&self.narrow, below),
|
||||
};
|
||||
Size::REST
|
||||
Size::LEFTOVER
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -131,22 +131,22 @@ fn a_moved_subtree_takes_its_children_with_it() {
|
||||
fn a_fixed_length_child_keeps_it_when_the_box_around_it_grows() {
|
||||
let mut h = Harness::new((400, 200));
|
||||
let fixed = rect(Color::BLUE).width(50).add(&mut h.rsc);
|
||||
let rest = rect(Color::GREEN).add(&mut h.rsc);
|
||||
let panel = (fixed, rest).span(Dir::RIGHT).add(&mut h.rsc);
|
||||
let leftover = rect(Color::GREEN).add(&mut h.rsc);
|
||||
let panel = (fixed, leftover).span(Dir::RIGHT).add(&mut h.rsc);
|
||||
// Changing the bar's width is the only thing that changes the box the
|
||||
// panel and everything under it was drawn for.
|
||||
let bar = rect(Color::RED).width(100).add(&mut h.rsc);
|
||||
h.set_root((bar, panel).span(Dir::RIGHT));
|
||||
assert_corners!(h, fixed, (100, 0), (150, 200));
|
||||
assert_corners!(h, rest, (150, 0), (400, 200));
|
||||
assert_corners!(h, leftover, (150, 0), (400, 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
|
||||
// against its new start and the one taking the rest absorbs the change.
|
||||
// against its new start and the one taking what is left absorbs the change.
|
||||
assert_corners!(h, fixed, (200, 0), (250, 200));
|
||||
assert_corners!(h, rest, (250, 0), (400, 200));
|
||||
assert_corners!(h, leftover, (250, 0), (400, 200));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -187,7 +187,7 @@ fn only_a_container_that_places_its_children_lengthens_the_chain() {
|
||||
);
|
||||
}
|
||||
|
||||
/// A span that sizes from its children passes their `rest` weight up rather
|
||||
/// A span that sizes from its children passes their `leftover` weight up
|
||||
/// than collapsing it to one share, so nesting divides the same space instead
|
||||
/// of re-dividing a share of it.
|
||||
#[test]
|
||||
@@ -256,7 +256,7 @@ fn hairline(h: &mut Harness, marks: &mut Vec<WidgetId>) -> StrongWidget {
|
||||
fn share(h: &mut Harness, inner: StrongWidget, ratio: f32) -> StrongWidget {
|
||||
SetSize {
|
||||
inner,
|
||||
x: Some(Len::rest(ratio)),
|
||||
x: Some(Len::leftover(ratio)),
|
||||
y: None,
|
||||
}
|
||||
.add_strong(&mut h.rsc)
|
||||
|
||||
+12
-12
@@ -43,11 +43,11 @@ fn counted(h: &mut Harness, size: Size, dependence: OnResize) -> (WeakWidget<Cou
|
||||
(id, Counts(draws))
|
||||
}
|
||||
|
||||
/// A fixed-width leaf beside one that takes the rest, so changing the first
|
||||
/// hands the second a different box without the output changing.
|
||||
fn pair(h: &mut Harness, rest: OnResize) -> (WeakWidget<Counted>, Counts, WidgetId) {
|
||||
/// A fixed-width leaf beside one that takes what is left over, so changing
|
||||
/// the first hands the second a different box without the output changing.
|
||||
fn pair(h: &mut Harness, leftover: OnResize) -> (WeakWidget<Counted>, Counts, WidgetId) {
|
||||
let (first, _) = counted(h, Size::from((100, 200)), OnResize::Translate);
|
||||
let (second, draws) = counted(h, Size::REST, rest);
|
||||
let (second, draws) = counted(h, Size::LEFTOVER, leftover);
|
||||
h.set_root((first, second).span(Dir::RIGHT));
|
||||
(first, draws, second.id())
|
||||
}
|
||||
@@ -119,7 +119,7 @@ fn a_span_relays_out_when_a_child_it_measured_changes() {
|
||||
fn a_repaint_that_keeps_its_size_does_not_relay_out() {
|
||||
let mut h = Harness::new((400, 200));
|
||||
let (first, draws) = counted(&mut h, Size::from((100, 200)), OnResize::Translate);
|
||||
let (second, _) = counted(&mut h, Size::REST, OnResize::Translate);
|
||||
let (second, _) = counted(&mut h, Size::LEFTOVER, OnResize::Translate);
|
||||
h.set_root((first, second).span(Dir::RIGHT));
|
||||
let settled = draws.get();
|
||||
|
||||
@@ -158,7 +158,7 @@ impl Widget for FromHint {
|
||||
let mut region = UiRegion::FULL;
|
||||
region.y.end = region.y.start.offset(len.px);
|
||||
painter.widget_within(&self.inner, region);
|
||||
Size::REST
|
||||
Size::LEFTOVER
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ impl Widget for ReadsWidth {
|
||||
#[test]
|
||||
fn a_resize_does_not_redraw_what_the_shader_can_move() {
|
||||
let mut h = Harness::new((400, 200));
|
||||
let (leaf, draws) = counted(&mut h, Size::REST, OnResize::Scale);
|
||||
let (leaf, draws) = counted(&mut h, Size::LEFTOVER, OnResize::Scale);
|
||||
h.set_root(leaf);
|
||||
let settled = draws.get();
|
||||
|
||||
@@ -236,7 +236,7 @@ fn a_resize_does_not_redraw_what_the_shader_can_move() {
|
||||
#[test]
|
||||
fn a_resize_redraws_what_does_not_scale() {
|
||||
let mut h = Harness::new((400, 200));
|
||||
let (leaf, draws) = counted(&mut h, Size::REST, OnResize::Redraw);
|
||||
let (leaf, draws) = counted(&mut h, Size::LEFTOVER, OnResize::Redraw);
|
||||
h.set_root(leaf);
|
||||
let settled = draws.get();
|
||||
|
||||
@@ -430,8 +430,8 @@ fn a_widened_row_redraws_what_reads_its_length_and_nothing_else() {
|
||||
let mut h = Harness::new((400, 200));
|
||||
// What a transcript row is: something whose shaping depends on the width
|
||||
// it is given, beside something that only has to be the right shape.
|
||||
let (wraps, wrap_draws) = counted(&mut h, Size::REST, OnResize::Redraw);
|
||||
let (backing, back_draws) = counted(&mut h, Size::REST, OnResize::Scale);
|
||||
let (wraps, wrap_draws) = counted(&mut h, Size::LEFTOVER, OnResize::Redraw);
|
||||
let (backing, back_draws) = counted(&mut h, Size::LEFTOVER, OnResize::Scale);
|
||||
let row = (backing, wraps).span(Dir::RIGHT).add(&mut h.rsc);
|
||||
let bar = rect(Color::RED).width(100).add(&mut h.rsc);
|
||||
h.set_root((bar, row).span(Dir::RIGHT));
|
||||
@@ -457,8 +457,8 @@ fn a_declared_length_child_is_not_redrawn_when_the_box_around_it_grows() {
|
||||
// drawing the child in its own box is only an answer for that box.
|
||||
let (counter, draws) = counted(&mut h, Size::from((80, 200)), OnResize::Redraw);
|
||||
let fixed = counter.width(80).add(&mut h.rsc);
|
||||
let (rest, _) = counted(&mut h, Size::REST, OnResize::Scale);
|
||||
let row = (fixed, rest).span(Dir::RIGHT).add(&mut h.rsc);
|
||||
let (leftover, _) = counted(&mut h, Size::LEFTOVER, OnResize::Scale);
|
||||
let row = (fixed, leftover).span(Dir::RIGHT).add(&mut h.rsc);
|
||||
let bar = rect(Color::RED).width(100).add(&mut h.rsc);
|
||||
h.set_root((bar, row).span(Dir::RIGHT));
|
||||
let settled = draws.get();
|
||||
|
||||
+2
-2
@@ -327,7 +327,7 @@ fn sized(rng: &mut Rng, inner: Node) -> Node {
|
||||
}
|
||||
let len = |rng: &mut Rng| match rng.below(4) {
|
||||
0 => Some(Len::px(20.0 + rng.below(180) as f32)),
|
||||
1 => Some(Len::REST),
|
||||
1 => Some(Len::LEFTOVER),
|
||||
_ => None,
|
||||
};
|
||||
Node::Sized(len(rng), len(rng), Box::new(inner))
|
||||
@@ -343,7 +343,7 @@ fn grow(rng: &mut Rng, depth: usize) -> Node {
|
||||
}
|
||||
let len = |rng: &mut Rng| match rng.below(4) {
|
||||
0 => Some(Len::px(20.0 + rng.below(180) as f32)),
|
||||
1 => Some(Len::REST),
|
||||
1 => Some(Len::LEFTOVER),
|
||||
2 => Some(Len::rel(0.25 + rng.below(3) as f32 * 0.25)),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user