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
+27
-27
@@ -11,7 +11,7 @@ pub struct Size {
|
||||
pub struct Len {
|
||||
pub px: f32,
|
||||
pub rel: f32,
|
||||
pub rest: f32,
|
||||
pub leftover: f32,
|
||||
}
|
||||
|
||||
impl<N: UiNum> From<N> for Len {
|
||||
@@ -41,9 +41,9 @@ impl Size {
|
||||
y: Len::ZERO,
|
||||
};
|
||||
|
||||
pub const REST: Self = Self {
|
||||
x: Len::REST,
|
||||
y: Len::REST,
|
||||
pub const LEFTOVER: Self = Self {
|
||||
x: Len::LEFTOVER,
|
||||
y: Len::LEFTOVER,
|
||||
};
|
||||
|
||||
pub fn px(v: Vec2) -> Self {
|
||||
@@ -60,17 +60,17 @@ impl Size {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rest(v: Vec2) -> Self {
|
||||
pub fn leftover(v: Vec2) -> Self {
|
||||
Self {
|
||||
x: Len::rest(v.x),
|
||||
y: Len::rest(v.y),
|
||||
x: Len::leftover(v.x),
|
||||
y: Len::leftover(v.y),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_uivec2(self) -> UiVec2 {
|
||||
UiVec2 {
|
||||
x: self.x.apply_rest(),
|
||||
y: self.y.apply_rest(),
|
||||
x: self.x.apply_leftover(),
|
||||
y: self.y.apply_leftover(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,18 +99,18 @@ impl Len {
|
||||
pub const ZERO: Self = Self {
|
||||
px: 0.0,
|
||||
rel: 0.0,
|
||||
rest: 0.0,
|
||||
leftover: 0.0,
|
||||
};
|
||||
|
||||
pub const REST: Self = Self {
|
||||
pub const LEFTOVER: Self = Self {
|
||||
px: 0.0,
|
||||
rel: 0.0,
|
||||
rest: 1.0,
|
||||
leftover: 1.0,
|
||||
};
|
||||
|
||||
pub fn apply_rest(&self) -> UiScalar {
|
||||
pub fn apply_leftover(&self) -> UiScalar {
|
||||
UiScalar {
|
||||
rel: self.rel + if self.rest > 0.0 { 1.0 } else { 0.0 },
|
||||
rel: self.rel + if self.leftover > 0.0 { 1.0 } else { 0.0 },
|
||||
px: self.px,
|
||||
}
|
||||
}
|
||||
@@ -119,21 +119,21 @@ impl Len {
|
||||
Self {
|
||||
px: px.to_f32(),
|
||||
rel: 0.0,
|
||||
rest: 0.0,
|
||||
leftover: 0.0,
|
||||
}
|
||||
}
|
||||
pub fn rel(rel: impl UiNum) -> Self {
|
||||
Self {
|
||||
px: 0.0,
|
||||
rel: rel.to_f32(),
|
||||
rest: 0.0,
|
||||
leftover: 0.0,
|
||||
}
|
||||
}
|
||||
pub fn rest(ratio: impl UiNum) -> Self {
|
||||
pub fn leftover(ratio: impl UiNum) -> Self {
|
||||
Self {
|
||||
px: 0.0,
|
||||
rel: 0.0,
|
||||
rest: ratio.to_f32(),
|
||||
leftover: ratio.to_f32(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,34 +145,34 @@ pub mod len_fns {
|
||||
Len {
|
||||
px: px.to_f32(),
|
||||
rel: 0.0,
|
||||
rest: 0.0,
|
||||
leftover: 0.0,
|
||||
}
|
||||
}
|
||||
pub fn rel(rel: impl UiNum) -> Len {
|
||||
Len {
|
||||
px: 0.0,
|
||||
rel: rel.to_f32(),
|
||||
rest: 0.0,
|
||||
leftover: 0.0,
|
||||
}
|
||||
}
|
||||
pub fn rest(ratio: impl UiNum) -> Len {
|
||||
pub fn leftover(ratio: impl UiNum) -> Len {
|
||||
Len {
|
||||
px: 0.0,
|
||||
rel: 0.0,
|
||||
rest: ratio.to_f32(),
|
||||
leftover: ratio.to_f32(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_op!(Len Add add; px rel rest);
|
||||
impl_op!(Len Sub sub; px rel rest);
|
||||
impl_op!(Len Add add; px rel leftover);
|
||||
impl_op!(Len Sub sub; px rel leftover);
|
||||
|
||||
impl_op!(Size Add add; x y);
|
||||
impl_op!(Size Sub sub; x y);
|
||||
|
||||
impl Default for Len {
|
||||
fn default() -> Self {
|
||||
Self::rest(1.0)
|
||||
Self::leftover(1.0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,8 +190,8 @@ impl std::fmt::Display for Len {
|
||||
if self.rel != 0.0 {
|
||||
write!(f, "{} rel;", self.rel)?;
|
||||
}
|
||||
if self.rest != 0.0 {
|
||||
write!(f, "{} rest;", self.rest)?;
|
||||
if self.leftover != 0.0 {
|
||||
write!(f, "{} leftover;", self.leftover)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ impl<'a> Painter<'a> {
|
||||
}
|
||||
|
||||
/// What a widget declares its lengths to be, which whoever draws it
|
||||
/// resolves into its box. `rest` is not among them: a share of what is
|
||||
/// resolves into its box. `leftover` is not among them: a part of what is
|
||||
/// left over is only a length to the widget dividing one, so it passes
|
||||
/// up in the size instead. Reading it depends on nothing -- the box that
|
||||
/// comes of it is kept on the child, and `redraw` compares it there.
|
||||
@@ -439,11 +439,11 @@ impl PrimitiveLike for &TextureHandle {
|
||||
}
|
||||
}
|
||||
|
||||
/// What a widget declares a length of its box to be. `rest` is not one: a
|
||||
/// What a widget declares a length of its box to be. `leftover` is not one: a
|
||||
/// share of what is left over is only a length to the widget dividing one,
|
||||
/// so it passes up in the size instead.
|
||||
pub(crate) fn declared_len(widget: &dyn Widget, axis: Axis) -> Option<Len> {
|
||||
widget.size_hint(axis).filter(|len| len.rest == 0.0)
|
||||
widget.size_hint(axis).filter(|len| len.leftover == 0.0)
|
||||
}
|
||||
|
||||
/// Takes a widget's declared lengths in the box `region` is given in, since a
|
||||
|
||||
Reference in new issue
Block a user