Say narrow_rel_base, and let a container pass None for it
`narrow` said what the argument did to a value it never named, so a reader had to go and find out which value. It is `narrow_rel_base`, and the resolved one stays the bare `rel_base` -- which is also the only one in `Painter`, `Placing` and `LayoutHolds`, where there is nothing to tell it apart from. It takes `impl Into<Option<[Option<Len>; 2]>>`, so a container that does not narrow anything writes `None` rather than `[None; 2]`, and `Span` builds the one case that does with a `then` instead of a mutable array. Cold layout is byte-identical to `84dad21`.
This commit is contained in:
1 parent
aeb60e50f5
commit
beb138632a
8 files changed
+55
-49
No files matched your search
+30
-22
@@ -174,14 +174,14 @@ impl<'a> Painter<'a> {
|
||||
|
||||
/// Asks a child, saying what its fractions are of and where it is asked.
|
||||
///
|
||||
/// `narrow` is the child's rel base, per axis, as a length of the
|
||||
/// window: a resolved share, or a box a sibling's answer decided. `None`
|
||||
/// forwards this widget's own, which is what a container that only
|
||||
/// divides room passes, so a fraction under it means the same wherever
|
||||
/// it sits and however deeply it is nested. It only ever narrows -- a
|
||||
/// length the child declares narrows it again here whatever the caller
|
||||
/// says -- and what comes of it is also the box the child is asked in,
|
||||
/// placed in the part by the child's alignment.
|
||||
/// `narrow_rel_base` is the child's rel base, per axis, as a length of
|
||||
/// the window: a resolved share, or a box a sibling's answer decided.
|
||||
/// `None`, whole or per axis, forwards this widget's own -- which is
|
||||
/// what a container that only divides room passes, so a fraction under
|
||||
/// it means the same wherever it sits and however deeply it is nested.
|
||||
/// It only ever narrows: a length the child declares narrows it again
|
||||
/// here whatever the caller says, and what comes of it is also the box
|
||||
/// the child is asked in, placed in the part by the child's alignment.
|
||||
///
|
||||
/// `place` is where the child is asked, per axis, as a part of this
|
||||
/// widget's box: see [`Place`]. The child draws once, in that box, and
|
||||
@@ -191,14 +191,21 @@ impl<'a> Painter<'a> {
|
||||
pub fn widget_at<'s, W: ?Sized>(
|
||||
&'s mut self,
|
||||
id: &'s StrongWidget<W>,
|
||||
narrow: [Option<Len>; 2],
|
||||
narrow_rel_base: impl Into<Option<[Option<Len>; 2]>>,
|
||||
place: [Place; 2],
|
||||
) -> DrawResult<'s, 'a, W> {
|
||||
let narrow_rel_base = narrow_rel_base.into().unwrap_or([None; 2]);
|
||||
let region_node = self.rsc.widgets().is_region_node(id.id());
|
||||
let declared = self.declared_lens(id);
|
||||
let align = self.rsc.widgets().alignment(id.id());
|
||||
let (rel_base, region) =
|
||||
rel_base_and_region(self.region, self.rel_base, place, narrow, declared, align);
|
||||
let (rel_base, region) = rel_base_and_region(
|
||||
self.region,
|
||||
self.rel_base,
|
||||
place,
|
||||
narrow_rel_base,
|
||||
declared,
|
||||
align,
|
||||
);
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
if region_node {
|
||||
diag::bump(Counter::RegionNodeDraws);
|
||||
@@ -223,15 +230,15 @@ impl<'a> Painter<'a> {
|
||||
region,
|
||||
placed: place,
|
||||
asked: place,
|
||||
narrow,
|
||||
narrow_rel_base,
|
||||
re_asked,
|
||||
px,
|
||||
},
|
||||
None,
|
||||
self.rsc,
|
||||
);
|
||||
let holds = self.in_parent(holds, region, place, narrow, declared);
|
||||
let answer_holds = self.in_parent(answer_holds, region, place, narrow, declared);
|
||||
let holds = self.in_parent(holds, region, place, narrow_rel_base, declared);
|
||||
let answer_holds = self.in_parent(answer_holds, region, place, narrow_rel_base, declared);
|
||||
match self.under.iter_mut().find(|(child, _)| *child == id.id()) {
|
||||
Some((_, kept)) => *kept = holds,
|
||||
None => self.under.push((id.id(), holds)),
|
||||
@@ -266,11 +273,12 @@ impl<'a> Painter<'a> {
|
||||
pub fn place_at<'s, W: ?Sized>(
|
||||
&'s mut self,
|
||||
id: &'s StrongWidget<W>,
|
||||
narrow: [Option<Len>; 2],
|
||||
narrow_rel_base: impl Into<Option<[Option<Len>; 2]>>,
|
||||
place: [Place; 2],
|
||||
) -> DrawResult<'s, 'a, W> {
|
||||
if narrow.iter().any(Option::is_some) || !self.children.contains(&id.id()) {
|
||||
return self.widget_at(id, narrow, place);
|
||||
let narrow_rel_base = narrow_rel_base.into().unwrap_or([None; 2]);
|
||||
if narrow_rel_base.iter().any(Option::is_some) || !self.children.contains(&id.id()) {
|
||||
return self.widget_at(id, narrow_rel_base, place);
|
||||
}
|
||||
let at = self.placing();
|
||||
self.state.place_in(id.id(), &at, place, self.rsc);
|
||||
@@ -612,7 +620,7 @@ impl Painter<'_> {
|
||||
holds: LayoutHolds,
|
||||
region: UiRegion,
|
||||
place: [Place; 2],
|
||||
narrow: [Option<Len>; 2],
|
||||
narrow_rel_base: [Option<Len>; 2],
|
||||
declared: [Option<LayoutLen>; 2],
|
||||
) -> LayoutHolds {
|
||||
let mut result = LayoutHolds::ANY;
|
||||
@@ -621,7 +629,7 @@ impl Painter<'_> {
|
||||
// Every read became pixels against the window, so a range on
|
||||
// it is already in this widget's terms.
|
||||
result.window[n] = holds.window[n];
|
||||
let reaches = narrow[n].is_none()
|
||||
let reaches = narrow_rel_base[n].is_none()
|
||||
&& !matches!(place[n].part(), Part::Sized(_))
|
||||
&& declared[n].is_none_or(|len| len.rel != Rel::ZERO);
|
||||
result.rel_base[n] = holds.rel_base[n].and(reaches.then(|| self.rel_base.axis(axis)));
|
||||
@@ -729,7 +737,7 @@ pub(crate) fn placement(
|
||||
/// widget asking draws in.
|
||||
///
|
||||
/// `own` is that widget's own box, and `place` what of it the child is
|
||||
/// given. `narrow` is a rel base the container decided for the child -- a row's
|
||||
/// given. `narrow_rel_base` is a rel base the container decided for the child -- a row's
|
||||
/// slot, or padding's rel base less its pixels -- and [`Part::Sized`] one a
|
||||
/// sibling's answer decided; both are window lengths, like every other
|
||||
/// length here, since a slot of a row is not a fraction of anything the row
|
||||
@@ -740,7 +748,7 @@ pub(crate) fn rel_base_and_region(
|
||||
own: UiRegion,
|
||||
parent_rel_base: UiVec2,
|
||||
place: [Place; 2],
|
||||
narrow: [Option<Len>; 2],
|
||||
narrow_rel_base: [Option<Len>; 2],
|
||||
declared: [Option<LayoutLen>; 2],
|
||||
align: RegionAlign,
|
||||
) -> (UiVec2, UiRegion) {
|
||||
@@ -754,7 +762,7 @@ pub(crate) fn rel_base_and_region(
|
||||
_ => None,
|
||||
};
|
||||
let base = sized
|
||||
.or(narrow[n])
|
||||
.or(narrow_rel_base[n])
|
||||
.unwrap_or_else(|| parent_rel_base.axis(axis));
|
||||
let len = declared[n]
|
||||
.map(|len| Len::from_parts(len.rel, len.px).within_len(base))
|
||||
|
||||
Reference in new issue
Block a user