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
@@ -14,11 +14,17 @@ impl Widget for Aligned {
|
||||
.map(|(x, y)| Size { x, y }),
|
||||
(Some(_), None) => painter
|
||||
.known_len(&self.inner, Axis::X, UiRegion::FULL)
|
||||
.map(|x| Size { x, y: Len::REST }),
|
||||
.map(|x| Size {
|
||||
x,
|
||||
y: Len::LEFTOVER,
|
||||
}),
|
||||
(None, Some(_)) => painter
|
||||
.known_len(&self.inner, Axis::Y, UiRegion::FULL)
|
||||
.map(|y| Size { x: Len::REST, y }),
|
||||
(None, None) => Some(Size::REST),
|
||||
.map(|y| Size {
|
||||
x: Len::LEFTOVER,
|
||||
y,
|
||||
}),
|
||||
(None, None) => Some(Size::LEFTOVER),
|
||||
};
|
||||
// Drawn where it may be too big only when the aligned axes are not
|
||||
// already known, then given its aligned box once its size is known.
|
||||
@@ -26,8 +32,8 @@ impl Widget for Aligned {
|
||||
let size = known.unwrap_or_else(|| painter.place(&self.inner, UiRegion::FULL).size());
|
||||
let region = match self.align.tuple() {
|
||||
(Some(x), Some(y)) => size.to_uivec2().align(RegionAlign { x, y }),
|
||||
(Some(x), None) => UiRegion::new(size.x.apply_rest().align(x), UiSpan::FULL),
|
||||
(None, Some(y)) => UiRegion::new(UiSpan::FULL, size.y.apply_rest().align(y)),
|
||||
(Some(x), None) => UiRegion::new(size.x.apply_leftover().align(x), UiSpan::FULL),
|
||||
(None, Some(y)) => UiRegion::new(UiSpan::FULL, size.y.apply_leftover().align(y)),
|
||||
(None, None) => UiRegion::FULL,
|
||||
};
|
||||
let placed = painter.place(&self.inner, region).size();
|
||||
|
||||
@@ -19,7 +19,7 @@ impl Widget for MaxSize {
|
||||
|
||||
fn capped(len: Len, max: Option<Len>, output: f32) -> Len {
|
||||
match max {
|
||||
Some(max) if len.apply_rest().to_px(output) > max.apply_rest().to_px(output) => max,
|
||||
Some(max) if len.apply_leftover().to_px(output) > max.apply_leftover().to_px(output) => max,
|
||||
_ => len,
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ impl Widget for Pad {
|
||||
}
|
||||
|
||||
/// The padding is an offset from each edge, so a longer box pads the same
|
||||
/// amount and the child takes the rest.
|
||||
/// amount and the child takes what is left over.
|
||||
fn on_resize(&self, _: Axis) -> OnResize {
|
||||
OnResize::Scale
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ impl Widget for Scroll {
|
||||
let child = measured.then(|| painter.place(&self.inner, UiRegion::FULL).size());
|
||||
let content_len = known_len
|
||||
.unwrap_or_else(|| child.unwrap().axis(self.axis))
|
||||
.apply_rest()
|
||||
.apply_leftover()
|
||||
.within_len(container_len)
|
||||
.to_px(output_len);
|
||||
self.container_len = container_len.to_px(output_len);
|
||||
|
||||
@@ -9,7 +9,7 @@ pub struct SetSize {
|
||||
impl Widget for SetSize {
|
||||
fn draw(&mut self, painter: &mut Painter) -> Size {
|
||||
// Nothing to apply: a declared length is taken where this widget is
|
||||
// drawn, so the box it has already is that length, and `rest` is a
|
||||
// drawn, so the box it has already is that length, and `leftover` is a
|
||||
// share only whoever divides a length can work out. Both reach them
|
||||
// through `size_hint`.
|
||||
let child = painter.widget(&self.inner).size();
|
||||
@@ -20,7 +20,7 @@ impl Widget for SetSize {
|
||||
}
|
||||
|
||||
/// A declared axis is known without looking at the child, which is what
|
||||
/// lets a span lay out around `.height(rest(1))` without drawing it.
|
||||
/// lets a span lay out around `.height(leftover(1))` without drawing it.
|
||||
fn size_hint(&self, axis: Axis) -> Option<Len> {
|
||||
match axis {
|
||||
Axis::X => self.x,
|
||||
|
||||
@@ -37,9 +37,9 @@ impl Widget for Span {
|
||||
for (child, len) in self.children.iter().zip(&lens) {
|
||||
let mut span = UiSpan::FULL;
|
||||
span.start = start;
|
||||
if len.rest > 0.0 {
|
||||
if len.leftover > 0.0 {
|
||||
let offset = UiScalar::new(total.rel, total.px);
|
||||
let rel_end = UiScalar::rel(len.rest / total.rest);
|
||||
let rel_end = UiScalar::rel(len.leftover / total.leftover);
|
||||
let end = (UiScalar::rel_max() + start) - offset;
|
||||
start = rel_end.within(&start.to(end));
|
||||
}
|
||||
@@ -52,19 +52,19 @@ impl Widget for Span {
|
||||
}
|
||||
let used = painter.place(child, region).size().axis(!axis);
|
||||
// TODO: rel shouldn't do this, but no easy way before actually calculating pixels
|
||||
if used.rel > 0.0 || used.rest > 0.0 {
|
||||
ortho = Len::REST;
|
||||
} else if ortho.rest == 0.0 {
|
||||
if used.rel > 0.0 || used.leftover > 0.0 {
|
||||
ortho = Len::LEFTOVER;
|
||||
} else if ortho.leftover == 0.0 {
|
||||
ortho.px = ortho.px.max(used.px);
|
||||
}
|
||||
start.px += self.gap;
|
||||
}
|
||||
|
||||
// Carried whole rather than collapsed to one share: a span that sizes
|
||||
// from its children does not resolve `rest`, it passes the weight up,
|
||||
// from its children does not resolve `leftover`, it passes the weight up,
|
||||
// so nesting spans divides the same space rather than re-dividing a
|
||||
// share of it. Four `rest(1)` children under two spans under one span
|
||||
// get a quarter each, which collapsing to `rest(1)` per level does
|
||||
// share of it. Four `leftover(1)` children under two spans under one span
|
||||
// get a quarter each, which collapsing to `leftover(1)` per level does
|
||||
// not give. Resolution happens at the nearest ancestor with a length,
|
||||
// and the root always has one.
|
||||
let along = total;
|
||||
|
||||
Reference in new issue
Block a user