Put lengths, padding, gaps and alignment on the grid too
`Len` is `Px` beside `Rel` beside `Weight`, so the seam `4e28f10` left in `Span` -- a float length added to a fixed-point cursor -- is gone, and the sum a span compares against its box is exact. `Weight` is its own scale, `Fixed<16>`, because a share of what is left over is not a fraction of anything: a list divides its room by the total of them, so the range has to hold a whole list's worth while the precision only has to tell two weights apart. `Rel::ratio` turns two weights into a share on the finer grid, which is what a span needs and what dividing them on their own grid would round away. `AxisAlign` holds a `Rel` rather than a float, which is what the layout was reading out of it anyway. `Padding` and `Span::gap` hold `Px`, converted where they are built instead of on every frame. `RegionAlign::rel` is gone; its one caller wanted a position, and now builds one. `Fixed` gains `from_num` for a number as it is written in source, `mul_int` for a length repeated a whole number of times, and `ratio`. Checked: fmt, clippy, 101 tests, 100 generated seeds in 86 s, all five shrinker cases at 300 seeds, and all five examples byte-identical at 1920x1200 against `4e28f10`. With the fuzzer comparing for equality rather than within 0.05 px, four of the five cases now pass 100 seeds -- `resize-repaint` joins the other three. `reorder` still fails one seed by one step, so the last of it is in what a box is measured *in*: `px_len` and the window are still floats. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4e28f1047e
commit
bd6de71a55
15 files changed
+199
-158
No files matched your search
@@ -1,4 +1,4 @@
|
||||
use crate::{Px, Rel, vec2};
|
||||
use crate::{Px, Rel};
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -35,7 +35,7 @@ impl Align {
|
||||
/// is the near one depends on the writing system and on which way a container
|
||||
/// runs, and the middle is the same either way.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct AxisAlign(f32);
|
||||
pub struct AxisAlign(Rel);
|
||||
|
||||
impl AxisAlign {
|
||||
pub const NEG: Self = Self::new(0.0);
|
||||
@@ -43,10 +43,12 @@ impl AxisAlign {
|
||||
pub const POS: Self = Self::new(1.0);
|
||||
|
||||
pub const fn new(rel: f32) -> Self {
|
||||
Self(rel)
|
||||
Self(Rel::from_f32(rel))
|
||||
}
|
||||
|
||||
pub const fn rel(&self) -> f32 {
|
||||
/// A fraction of the room left over, which is what the layout reads: the
|
||||
/// three constants are the familiar places along it, not the only ones.
|
||||
pub const fn rel(&self) -> Rel {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
@@ -118,9 +120,6 @@ impl RegionAlign {
|
||||
pub const fn new(x: AxisAlign, y: AxisAlign) -> Self {
|
||||
Self { x, y }
|
||||
}
|
||||
pub const fn rel(&self) -> Vec2 {
|
||||
vec2(self.x.rel(), self.y.rel())
|
||||
}
|
||||
}
|
||||
|
||||
impl UiVec2 {
|
||||
@@ -175,7 +174,7 @@ impl Vec2 {
|
||||
|
||||
impl UiScalar {
|
||||
pub const fn align(&self, align: AxisAlign) -> UiSpan {
|
||||
let rel = Rel::from_f32(align.rel());
|
||||
let rel = align.rel();
|
||||
let rest = Rel::ONE.sub(rel);
|
||||
let at = UiScalar::from_parts(rel, Px::ZERO);
|
||||
UiSpan {
|
||||
@@ -221,7 +220,10 @@ impl From<CardinalAlign> for Align {
|
||||
|
||||
const impl From<RegionAlign> for UiVec2 {
|
||||
fn from(align: RegionAlign) -> Self {
|
||||
Self::rel(align.rel())
|
||||
Self::new(
|
||||
UiScalar::from_parts(align.x.rel(), Px::ZERO),
|
||||
UiScalar::from_parts(align.y.rel(), Px::ZERO),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user