Give a length with no share in it its own type again
`UiScalar` was `Len` without the `leftover` weight, which is the separation canonical `main` already had as `Len` beside `LayoutLen` and this branch collapsed. It is needed back for the queued clamp: a cap may not contain a share, because a cap has to read the report a rule otherwise makes moot, and a share puts the container's division into the same equation -- two self-consistent assignments, which is the multiple-fixed-point failure generated seed 13 punished for orthogonal sizing. `min(report, cap)` is not a `LayoutLen` either: it is a sum of parts, and the smaller of two of them is not one. So `UiScalar` is `Len`, what was `Len` is `LayoutLen`, and the two say in their docs which is which: a `Len` is pixels plus a fraction of a box -- a position being the length from the box's start, which is why a span is two of them -- and a `LayoutLen` is a `Len` plus a claim only a container dividing its room can answer. `From<Len> for LayoutLen` is the one-way step between them. Names only; the shader's `UiScalar` is renamed with them. Checked: fmt, clippy, 105 tests, and `tabs`, `minimal`, `view`, `text` and `random` byte-identical at 1920x1200. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4f5e27cba9
commit
a8898aaa54
27 files changed
+218
-202
No files matched your search
+10
-10
@@ -72,7 +72,7 @@ enum Node {
|
||||
Stack(Vec<Node>),
|
||||
Pad(f32, Box<Node>),
|
||||
Aligned(u8, u8, Box<Node>),
|
||||
Sized(Option<Len>, Option<Len>, Box<Node>),
|
||||
Sized(Option<LayoutLen>, Option<LayoutLen>, Box<Node>),
|
||||
Scroll(bool, Box<Node>),
|
||||
Branch(Box<Node>, Box<Node>, Box<Node>, f32),
|
||||
}
|
||||
@@ -131,7 +131,7 @@ impl Node {
|
||||
if !*down {
|
||||
h.rsc
|
||||
.widgets_mut()
|
||||
.set_size_rules(handle, None, Some(Len::rel(1.0)));
|
||||
.set_size_rules(handle, None, Some(LayoutLen::rel(1.0)));
|
||||
}
|
||||
spans.push(handle);
|
||||
handle.add_strong(&mut h.rsc)
|
||||
@@ -191,7 +191,7 @@ impl Node {
|
||||
|
||||
/// The lengths every `Sized` node would carry after `resized`, in the
|
||||
/// order `build` pushes them.
|
||||
fn sized_lens(&self, out: &mut Vec<(Option<Len>, Option<Len>)>) {
|
||||
fn sized_lens(&self, out: &mut Vec<(Option<LayoutLen>, Option<LayoutLen>)>) {
|
||||
match self {
|
||||
Node::Text(..) | Node::OneLine | Node::Rect => {}
|
||||
Node::Span(_, _, kids, _) | Node::Stack(kids) => {
|
||||
@@ -352,8 +352,8 @@ fn sized(rng: &mut Rng, inner: Node) -> Node {
|
||||
return inner;
|
||||
}
|
||||
let len = |rng: &mut Rng| match rng.below(4) {
|
||||
0 => Some(Len::px(20.0 + rng.below(180) as f32)),
|
||||
1 => Some(Len::LEFTOVER),
|
||||
0 => Some(LayoutLen::px(20.0 + rng.below(180) as f32)),
|
||||
1 => Some(LayoutLen::LEFTOVER),
|
||||
_ => None,
|
||||
};
|
||||
Node::Sized(len(rng), len(rng), Box::new(inner))
|
||||
@@ -368,9 +368,9 @@ 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::LEFTOVER),
|
||||
2 => Some(Len::rel(0.25 + rng.below(3) as f32 * 0.25)),
|
||||
0 => Some(LayoutLen::px(20.0 + rng.below(180) as f32)),
|
||||
1 => Some(LayoutLen::LEFTOVER),
|
||||
2 => Some(LayoutLen::rel(0.25 + rng.below(3) as f32 * 0.25)),
|
||||
_ => None,
|
||||
};
|
||||
let kid = |rng: &mut Rng| {
|
||||
@@ -408,9 +408,9 @@ enum Case {
|
||||
|
||||
/// A different declared length, kept the same kind so the change is to the
|
||||
/// value alone.
|
||||
fn resized_len(len: Option<Len>) -> Option<Len> {
|
||||
fn resized_len(len: Option<LayoutLen>) -> Option<LayoutLen> {
|
||||
let half = Rel::from_f32(0.5);
|
||||
len.map(|len| Len {
|
||||
len.map(|len| LayoutLen {
|
||||
px: len.px.mul(half) + Px::from_int(13),
|
||||
rel: len.rel.mul(half),
|
||||
leftover: len.leftover,
|
||||
|
||||
Reference in new issue
Block a user