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:
iris-aiandClaude Opus 5 committed 2026-09-16 13:40:15 -04:00
1 parent 4f5e27cba9
commit a8898aaa54
27 files changed
+218 -202

No files matched your search

+4 -4
View File
@@ -1,4 +1,4 @@
use crate::{Axis, Len, Painter, Size};
use crate::{Axis, LayoutLen, Painter, Size};
use std::any::Any;
mod data;
@@ -24,7 +24,7 @@ pub trait Widget: Any {
/// An exact length the widget can give without a painter or its children.
/// Optional, and saves a draw rather than changing one: a hint that
/// disagrees with the eventual draw fails a debug assertion.
fn size_hint(&self, _axis: Axis) -> Option<Len> {
fn size_hint(&self, _axis: Axis) -> Option<LayoutLen> {
None
}
}
@@ -35,8 +35,8 @@ impl Widget for () {
Size::default()
}
fn size_hint(&self, _axis: Axis) -> Option<Len> {
Some(Len::default())
fn size_hint(&self, _axis: Axis) -> Option<LayoutLen> {
Some(LayoutLen::default())
}
}
+9 -9
View File
@@ -1,4 +1,4 @@
use crate::{Axis, Len, Weight};
use crate::{Axis, LayoutLen, Weight};
/// What a widget's length on one axis is, as a rule its parent applies where
/// it draws it rather than an answer the widget gives about itself.
@@ -14,7 +14,7 @@ pub enum SizeRule {
#[default]
Free,
/// This length, whatever the widget reports.
Exact(Len),
Exact(LayoutLen),
}
impl SizeRule {
@@ -22,7 +22,7 @@ impl SizeRule {
/// give one. `leftover` is never among them: a share is a length only to
/// whoever divides one, so it passes up in the reported size instead and
/// is resolved there.
pub fn declared(&self) -> Option<Len> {
pub fn declared(&self) -> Option<LayoutLen> {
match self {
Self::Exact(len) if len.leftover == Weight::ZERO => Some(*len),
_ => None,
@@ -33,7 +33,7 @@ impl SizeRule {
/// share is a length the widget's parent still has to divide, so it is
/// known here and resolved there -- unlike `declared`, which is only the
/// ones that give a box directly.
pub fn known(&self) -> Option<Len> {
pub fn known(&self) -> Option<LayoutLen> {
match self {
Self::Free => None,
Self::Exact(len) => Some(*len),
@@ -41,7 +41,7 @@ impl SizeRule {
}
/// The length a widget reporting `reported` ends up with.
pub fn apply(&self, reported: Len) -> Len {
pub fn apply(&self, reported: LayoutLen) -> LayoutLen {
match self {
Self::Free => reported,
Self::Exact(len) => *len,
@@ -49,14 +49,14 @@ impl SizeRule {
}
}
impl From<Len> for SizeRule {
fn from(len: Len) -> Self {
impl From<LayoutLen> for SizeRule {
fn from(len: LayoutLen) -> Self {
Self::Exact(len)
}
}
impl From<Option<Len>> for SizeRule {
fn from(len: Option<Len>) -> Self {
impl From<Option<LayoutLen>> for SizeRule {
fn from(len: Option<LayoutLen>) -> Self {
len.map_or(Self::Free, Self::Exact)
}
}