Ask whether a rule gives the length, not whether there is one

`Painter::ruled` answered "is there a rule beside me on this axis", which is
the same question as "is my report moot" only while `Exact` is the only rule
there is. `Min`, `Max` and `Clamp` are queued, and under one of those the
answer is still the widget's to give and a span across itself still has to
read its children -- so the name would have been true and the meaning wrong,
which is the worst way for a predicate to age.

It is `has_exact_size` now, over `SizeRule::exact` rather than `known`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
iris-aiandClaude Opus 5 committed 2026-09-16 13:40:51 -04:00
1 parent a8898aaa54
commit 490918b789
4 files changed
+24 -17

No files matched your search

+12 -8
View File
@@ -222,7 +222,7 @@ impl<'a> Painter<'a> {
let widgets = self.rsc.widgets(); let widgets = self.rsc.widgets();
// A rule is the answer where there is one: it wins over whatever the // A rule is the answer where there is one: it wins over whatever the
// widget would draw, so it has to win over what the widget says too. // widget would draw, so it has to win over what the widget says too.
let hint = widgets.size_rules(id.id()).axis(axis).known().or_else(|| { let hint = widgets.size_rules(id.id()).axis(axis).exact().or_else(|| {
widgets widgets
.get_dyn(id.id()) .get_dyn(id.id())
.and_then(|widget| widget.size_hint(axis)) .and_then(|widget| widget.size_hint(axis))
@@ -360,17 +360,21 @@ impl<'a> Painter<'a> {
self.rsc.widgets().alignment(self.id) self.rsc.widgets().alignment(self.id)
} }
/// Whether a rule beside this widget settles its length on `axis`, which /// Whether a rule beside this widget gives its length on `axis` outright,
/// makes whatever it reports for that axis moot. The widget under a rule /// which makes whatever it reports for that axis moot. A rule that only
/// does not otherwise learn of it -- this is for a container deciding /// bounds the length is not one of these: the answer is still the
/// whether reading its children across an axis is worth anything, since /// widget's to give, and something still has to work it out.
/// reading one is also what makes its own size depend on it. ///
pub fn ruled(&self, axis: Axis) -> bool { /// The widget under a rule does not otherwise learn of it -- this is for
/// a container deciding whether reading its children across an axis is
/// worth anything, since reading one is also what makes its own size
/// depend on it.
pub fn has_exact_size(&self, axis: Axis) -> bool {
self.rsc self.rsc
.widgets() .widgets()
.size_rules(self.id) .size_rules(self.id)
.axis(axis) .axis(axis)
.known() .exact()
.is_some() .is_some()
} }
+6 -5
View File
@@ -29,11 +29,12 @@ impl SizeRule {
} }
} }
/// The length this rule fixes, whether or not it can narrow a box. A /// The length this rule gives outright, whatever the widget reports --
/// share is a length the widget's parent still has to divide, so it is /// which makes the widget's answer on that axis moot. A share counts: it
/// known here and resolved there -- unlike `declared`, which is only the /// is a length the widget's parent still has to divide, so it is exact
/// ones that give a box directly. /// here and resolved there, unlike `declared`, which is only the ones
pub fn known(&self) -> Option<LayoutLen> { /// that give a box directly.
pub fn exact(&self) -> Option<LayoutLen> {
match self { match self {
Self::Free => None, Self::Free => None,
Self::Exact(len) => Some(*len), Self::Exact(len) => Some(*len),
+5 -3
View File
@@ -80,9 +80,11 @@ impl Widget for Span {
} }
// Across itself a span is as long as its longest child -- unless a // Across itself a span is as long as its longest child -- unless a
// rule beside it already says how long it is, and then reading them // rule beside it gives that length outright, and then reading them
// answers nothing and makes its size depend on theirs for it. // answers nothing and makes its size depend on theirs for it. A rule
let shrinks = !painter.ruled(!axis); // that only bounds the length does not count: the answer is still
// this span's to give.
let shrinks = !painter.has_exact_size(!axis);
// What the fixed parts and the gaps before here take, which is a sum // What the fixed parts and the gaps before here take, which is a sum
// of lengths and exact, and how much of the leftover weight is // of lengths and exact, and how much of the leftover weight is
// spoken for. A position is one from the other rather than a step // spoken for. A position is one from the other rather than a step
+1 -1
View File
@@ -178,7 +178,7 @@ fn reshuffle(
/// it has to be buildable from what the failure printed. /// it has to be buildable from what the failure printed.
fn describe(id: WidgetId, h: &Harness) -> String { fn describe(id: WidgetId, h: &Harness) -> String {
let rules = h.rsc.widgets().size_rules(id); let rules = h.rsc.widgets().size_rules(id);
let rule = |r: SizeRule| match r.known() { let rule = |r: SizeRule| match r.exact() {
Some(len) => format!("{len}"), Some(len) => format!("{len}"),
None => "-".into(), None => "-".into(),
}; };