Make a declared length one that cannot carry a share
`declared_lens` filtered `leftover` out of both its sources and every consumer then re-dropped it, so the rule lived in two filters and a comment. A declaration is a `Len`: `LayoutLen::declared` states the rule once and both sources go through it, and `Declared` replaces the bare two-element array on `ActiveData` and in four signatures. The two sources stay one value deliberately. A rule decides the child's box; a hint only promises what it will report -- but `size_hint` is by contract an exact answer with no painter context, and `hints_agree` fails a widget that draws something else, so narrowing the box to a hint cannot change what is drawn. Every consumer asks about the length, never which said it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
55df32a33c
commit
2807a925af
5 files changed
+57
-34
No files matched your search
@@ -1,5 +1,5 @@
|
||||
use crate::util::impl_axis_index;
|
||||
use crate::{LayoutLen, Weight};
|
||||
use crate::{Axis, LayoutLen, Len};
|
||||
|
||||
/// 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.
|
||||
@@ -20,14 +20,9 @@ pub enum SizeRule {
|
||||
|
||||
impl SizeRule {
|
||||
/// The length this rule gives without the widget being drawn, if it can
|
||||
/// 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<LayoutLen> {
|
||||
match self {
|
||||
Self::Exact(len) if len.leftover == Weight::ZERO => Some(*len),
|
||||
_ => None,
|
||||
}
|
||||
/// give one.
|
||||
pub fn declared(&self) -> Option<Len> {
|
||||
self.exact().and_then(LayoutLen::declared)
|
||||
}
|
||||
|
||||
/// The length this rule gives outright, whatever the widget reports --
|
||||
@@ -72,3 +67,28 @@ pub struct SizeRules {
|
||||
}
|
||||
|
||||
impl_axis_index!(SizeRules => SizeRule);
|
||||
|
||||
/// What a widget's box is on each axis where something says so outright,
|
||||
/// before it is drawn: a rule beside it, or a hint it gives about itself.
|
||||
/// Whoever draws the widget resolves these against its rel base.
|
||||
///
|
||||
/// A [`Len`] rather than a [`LayoutLen`], because a share can never be one
|
||||
/// -- see [`LayoutLen::declared`].
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct Declared {
|
||||
pub x: Option<Len>,
|
||||
pub y: Option<Len>,
|
||||
}
|
||||
|
||||
impl Declared {
|
||||
pub const NONE: Self = Self { x: None, y: None };
|
||||
|
||||
pub fn per_axis(f: impl Fn(Axis) -> Option<Len>) -> Self {
|
||||
Self {
|
||||
x: f(Axis::X),
|
||||
y: f(Axis::Y),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_axis_index!(Declared => Option<Len>);
|
||||
Reference in new issue
Block a user