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

+20 -20
View File
@@ -9,14 +9,14 @@ pub struct Size {
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Len {
pub abs: f32,
pub px: f32,
pub rel: f32,
pub rest: f32,
}
impl<N: UiNum> From<N> for Len {
fn from(value: N) -> Self {
Len::abs(value.to_f32())
Len::px(value.to_f32())
}
}
@@ -46,10 +46,10 @@ impl Size {
y: Len::REST,
};
pub fn abs(v: Vec2) -> Self {
pub fn px(v: Vec2) -> Self {
Self {
x: Len::abs(v.x),
y: Len::abs(v.y),
x: Len::px(v.x),
y: Len::px(v.y),
}
}
@@ -97,13 +97,13 @@ impl Size {
impl Len {
pub const ZERO: Self = Self {
abs: 0.0,
px: 0.0,
rel: 0.0,
rest: 0.0,
};
pub const REST: Self = Self {
abs: 0.0,
px: 0.0,
rel: 0.0,
rest: 1.0,
};
@@ -111,27 +111,27 @@ impl Len {
pub fn apply_rest(&self) -> UiScalar {
UiScalar {
rel: self.rel + if self.rest > 0.0 { 1.0 } else { 0.0 },
abs: self.abs,
px: self.px,
}
}
pub fn abs(abs: impl UiNum) -> Self {
pub fn px(px: impl UiNum) -> Self {
Self {
abs: abs.to_f32(),
px: px.to_f32(),
rel: 0.0,
rest: 0.0,
}
}
pub fn rel(rel: impl UiNum) -> Self {
Self {
abs: 0.0,
px: 0.0,
rel: rel.to_f32(),
rest: 0.0,
}
}
pub fn rest(ratio: impl UiNum) -> Self {
Self {
abs: 0.0,
px: 0.0,
rel: 0.0,
rest: ratio.to_f32(),
}
@@ -141,31 +141,31 @@ impl Len {
pub mod len_fns {
use super::*;
pub fn abs(abs: impl UiNum) -> Len {
pub fn px(px: impl UiNum) -> Len {
Len {
abs: abs.to_f32(),
px: px.to_f32(),
rel: 0.0,
rest: 0.0,
}
}
pub fn rel(rel: impl UiNum) -> Len {
Len {
abs: 0.0,
px: 0.0,
rel: rel.to_f32(),
rest: 0.0,
}
}
pub fn rest(ratio: impl UiNum) -> Len {
Len {
abs: 0.0,
px: 0.0,
rel: 0.0,
rest: ratio.to_f32(),
}
}
}
impl_op!(Len Add add; abs rel rest);
impl_op!(Len Sub sub; abs rel rest);
impl_op!(Len Add add; px rel rest);
impl_op!(Len Sub sub; px rel rest);
impl_op!(Size Add add; x y);
impl_op!(Size Sub sub; x y);
@@ -184,8 +184,8 @@ impl std::fmt::Display for Size {
impl std::fmt::Display for Len {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.abs != 0.0 {
write!(f, "{} abs;", self.abs)?;
if self.px != 0.0 {
write!(f, "{} px;", self.px)?;
}
if self.rel != 0.0 {
write!(f, "{} rel;", self.rel)?;