diff --git a/core/src/layout_diagnostics.rs b/core/src/layout_diagnostics.rs index f5eac2c..b5f4daf 100644 --- a/core/src/layout_diagnostics.rs +++ b/core/src/layout_diagnostics.rs @@ -53,7 +53,7 @@ pub(crate) enum Counter { TextBreaks, GlyphPlacements, OutsidePinnedLen, - OutsideFrame, + OutsideRelBase, OutsideRegion, } @@ -89,7 +89,7 @@ impl Counter { "text line breaks", "glyph placements", "reuse outside: the length it was pinned to", - "reuse outside: a frame length", + "reuse outside: a rel base", "reuse outside: a region length", ]; } diff --git a/core/src/ui/active.rs b/core/src/ui/active.rs index ca4b15a..1ea06a7 100644 --- a/core/src/ui/active.rs +++ b/core/src/ui/active.rs @@ -13,10 +13,10 @@ pub struct ActiveData { pub placement: UiRegion, /// What a fraction declared or reported under this widget is a fraction /// of, as a length of the window. - pub frame: UiVec2, - /// A frame its parent decided for it on each axis -- a row's slot, or - /// padding's frame less its pixels -- as a length of the window. `None` - /// forwards the parent's frame. What it declared is kept separately in + pub rel_base: UiVec2, + /// A rel base its parent decided for it on each axis -- a row's slot, or + /// padding's rel base less its pixels -- as a length of the window. `None` + /// forwards the parent's rel base. What it declared is kept separately in /// `declared` and is a fraction of whichever of the two reached it. pub narrow: [Option; 2], /// Where its drawing was put, and where it was asked, each as a part of @@ -41,7 +41,7 @@ pub struct ActiveData { /// What the widget reported, in window-unit lengths. pub size: Size, /// The window and region reads that this drawing holds for, and the - /// frame and region it pinned. + /// rel base and region it pinned. pub holds: LayoutHolds, pub drawn: bool, pub parent: Option, @@ -61,7 +61,7 @@ pub struct ActiveData { /// The movable region its primitives are positioned through: its own when /// opted in, otherwise the nearest ancestor's. pub move_idx: MoveIdx, - /// The declared lengths whoever drew this widget resolved into its frame. + /// The declared lengths whoever drew this widget resolved into its rel base. /// A change to one moves a box this widget cannot fix by drawing again, /// and comparing them is what says so. pub declared: [Option; 2], diff --git a/core/src/ui/layout_holds.rs b/core/src/ui/layout_holds.rs index bcf4270..3a1a494 100644 --- a/core/src/ui/layout_holds.rs +++ b/core/src/ui/layout_holds.rs @@ -4,24 +4,24 @@ const AXES: [Axis; 2] = [Axis::X, Axis::Y]; /// What one evaluation of a widget depends on: the window lengths its reads /// hold for, the pixel lengths of its own box, and the symbolic lengths of -/// that box and of its frame where either one is what it was expressed in. +/// that box and of its rel base where either one is what it was expressed in. /// /// The symbolic lengths are pins rather than ranges: a container places its -/// children as lengths of its frame measured from where its own box starts, +/// children as lengths of its rel base measured from where its own box starts, /// so what it draws turns on that box's length and on nothing about where it /// is. A box pin reaches the parent only where the box it pinned is the /// parent's own; anywhere else the parent chose that length itself, and a /// widget pinned this way is checked when it is re-placed. /// -/// A frame pin says the answer or the drawing is a fraction of the frame, -/// which is a different length wherever the frame is a different one -- at +/// A rel base pin says the answer or the drawing is a fraction of the rel base, +/// which is a different length wherever the rel base is a different one -- at /// the same window size, so no range of window pixels can say it. A length -/// of the frame that is only pixels is not one: it is that many pixels -/// whatever the frame turns out to be. +/// of the rel base that is only pixels is not one: it is that many pixels +/// whatever the rel base turns out to be. #[derive(Clone, Copy, Debug, PartialEq)] pub struct LayoutHolds { pub window: [Holds; 2], - pub frame_len: [Option; 2], + pub rel_base: [Option; 2], pub region: [Holds; 2], pub region_len: [Option; 2], } @@ -29,7 +29,7 @@ pub struct LayoutHolds { impl LayoutHolds { pub const ANY: Self = Self { window: [Holds::ANY; 2], - frame_len: [None; 2], + rel_base: [None; 2], region: [Holds::ANY; 2], region_len: [None; 2], }; @@ -45,12 +45,12 @@ impl LayoutHolds { || self.region_len[n] == other.region_len[n] ); debug_assert!( - self.frame_len[n].is_none() - || other.frame_len[n].is_none() - || self.frame_len[n] == other.frame_len[n] + self.rel_base[n].is_none() + || other.rel_base[n].is_none() + || self.rel_base[n] == other.rel_base[n] ); result.region_len[n] = self.region_len[n].or(other.region_len[n]); - result.frame_len[n] = self.frame_len[n].or(other.frame_len[n]); + result.rel_base[n] = self.rel_base[n].or(other.rel_base[n]); } result } @@ -62,16 +62,16 @@ impl LayoutHolds { && self.region[n].lo <= other.region[n].lo && self.region[n].hi >= other.region[n].hi && self.region_len[n].is_none_or(|len| other.region_len[n] == Some(len)) - && self.frame_len[n].is_none_or(|len| other.frame_len[n] == Some(len)) + && self.rel_base[n].is_none_or(|len| other.rel_base[n] == Some(len)) }) } - pub fn contains(self, window: PxVec2, frame: UiVec2, region: UiRegion) -> bool { + pub fn contains(self, window: PxVec2, rel_base: UiVec2, region: UiRegion) -> bool { AXES.into_iter().all(|axis| { let n = axis as usize; let len = region.axis(axis).len(); self.window[n].contains(window.axis(axis)) - && self.frame_len[n].is_none_or(|pinned| pinned == frame.axis(axis)) + && self.rel_base[n].is_none_or(|pinned| pinned == rel_base.axis(axis)) && self.region[n].contains(len.to_px(window.axis(axis))) && self.region_len[n].is_none_or(|pinned| pinned == len) }) diff --git a/core/src/ui/painter.rs b/core/src/ui/painter.rs index bfc9ee0..009b3bc 100644 --- a/core/src/ui/painter.rs +++ b/core/src/ui/painter.rs @@ -17,11 +17,11 @@ pub struct Painter<'a> { pub(super) state: &'a mut UiRenderState, pub(super) rsc: &'a mut dyn UiRsc, - /// This widget's frame, per axis: a length of the window, and what a + /// This widget's rel base, per axis: a length of the window, and what a /// fraction it or anything under it declares or reports is a fraction /// of. A length rather than a box, so padding can take from both the - /// frame and the box without either becoming the other. - pub(super) frame: UiVec2, + /// rel base and the box without either becoming the other. + pub(super) rel_base: UiVec2, /// The box this widget was asked in, in its region node's coordinates: /// what it draws in, and what its children's places are parts of. pub(super) region: UiRegion, @@ -41,7 +41,7 @@ pub struct Painter<'a> { pub(super) size_deps: Vec, /// What this draw itself reads, as against what its children's drawings /// hold for: every window and every length of its own region until it - /// reads one, then that one unless it says otherwise, and the frame or + /// reads one, then that one unless it says otherwise, and the rel base or /// region length it read symbolically, each of which makes the drawing /// hold for that length alone. pub(super) own: LayoutHolds, @@ -144,24 +144,44 @@ impl<'a> Painter<'a> { }; } - /// Draws a widget in the whole of this widget's own box, with the frame + /// Draws a widget in the whole of this widget's own box, with the rel base /// forwarded unchanged: what a container that is only a wrapper around /// one child wants, and what every transparent container passes for the - /// frame. + /// rel base. pub fn widget<'s, W: ?Sized>(&'s mut self, id: &'s StrongWidget) -> DrawResult<'s, 'a, W> { - self.widget_at(id, [None; 2], [Place::Within(Part::All); 2]) + self.widget_within(id, UiRegion::FULL) + } + + /// Draws a widget in `region` of this widget's own box, in that box's own + /// coordinates -- an inset, or an offset. + /// + /// The child's rel base is this widget's narrowed the same way the box is, + /// so padding takes its pixels off both and an offset, which changes the + /// box's length by nothing, changes neither. An axis the region leaves + /// whole is not read at all, so a wrapper that only moves its child does + /// not pin the drawing to a rel base. + pub fn widget_within<'s, W: ?Sized>( + &'s mut self, + id: &'s StrongWidget, + region: UiRegion, + ) -> DrawResult<'s, 'a, W> { + let narrow = AXES.map(|axis| { + let len = region.axis(axis).len(); + (len != Len::FULL).then(|| len.within_len(self.rel_base(axis))) + }); + self.widget_at(id, narrow, region_places(region)) } /// Asks a child, saying what its fractions are of and where it is asked. /// - /// `narrow` is a length this widget decided for the child's frame, per - /// axis, as a length of this widget's own frame: a resolved share, or a - /// box a sibling's answer decided. `None` forwards this widget's frame, - /// 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. A declared length narrows the frame here whatever the - /// caller says. A narrowed frame is placed in the part by the child's - /// alignment and is the box the child is asked in. + /// `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. /// /// `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 @@ -177,8 +197,8 @@ impl<'a> Painter<'a> { 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 (frame, region) = - frame_and_region(self.region, self.frame, place, narrow, declared, align); + let (rel_base, region) = + rel_base_and_region(self.region, self.rel_base, place, narrow, declared, align); #[cfg(feature = "layout-diagnostics")] if region_node { diag::bump(Counter::RegionNodeDraws); @@ -189,7 +209,7 @@ impl<'a> Painter<'a> { if !re_asked { self.children.push(id.id()); } - let px = frame.to_px(self.window); + let px = rel_base.to_px(self.window); let (size, answer_holds, holds) = self.state.draw_inner( id.id(), DrawInfo { @@ -199,7 +219,7 @@ impl<'a> Painter<'a> { parent_move: self.move_idx, region_node, mask: self.mask, - frame, + rel_base, region, placed: place, asked: place, @@ -233,18 +253,36 @@ impl<'a> Painter<'a> { self.state.undraw_rec(id.id(), self.rsc); } - /// Puts a child asked about in this draw somewhere else in this - /// widget's box: its answer, placed in this part instead. The drawing - /// is re-expressed there rather than made again -- what a row does once - /// it knows every slot, having measured each child from its cursor. - pub fn place_at(&mut self, id: &StrongWidget, place: [Place; 2]) { - debug_assert!( - self.children.contains(&id.id()), - "'{}' placed a child it did not ask about in this draw", - self.label() - ); + /// Puts a child in `place` of this widget's box, where that box is the + /// answer the child already gave: the drawing is re-expressed there + /// rather than made again -- what a row does once it knows every slot, + /// having measured each child from its cursor. + /// + /// A child this draw has not asked about, and one whose rel base this + /// narrows, is asked here instead: there is no answer to re-express, or + /// the question has changed. So a container that places every child the + /// same way says it once, and which of the two happens is this widget's + /// business rather than the caller's. + pub fn place_at<'s, W: ?Sized>( + &'s mut self, + id: &'s StrongWidget, + narrow: [Option; 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 at = self.placing(); self.state.place_in(id.id(), &at, place, self.rsc); + let active = &self.state.active[&id.id()]; + let size = active.measured().unwrap_or(active.size); + DrawResult { + child: id, + painter: self, + size, + // Read where it was asked; moving it is not a second answer. + answer_holds: LayoutHolds::ANY, + } } /// This widget as the thing its children are placed within. @@ -252,7 +290,7 @@ impl<'a> Painter<'a> { Placing { id: self.id, region: self.region, - frame: self.frame, + rel_base: self.rel_base, window: self.window, depth: self.depth, move_idx: self.move_idx, @@ -261,7 +299,7 @@ impl<'a> Painter<'a> { } /// What a widget's rules declare its lengths to be, which whoever draws - /// it resolves into its frame. Reading them depends on nothing -- the box + /// it resolves into its rel base. Reading them depends on nothing -- the box /// that comes of them is kept on the child, and `redraw` compares it /// there. fn declared_lens(&self, id: &StrongWidget) -> [Option; 2] { @@ -270,7 +308,7 @@ impl<'a> Painter<'a> { /// What a child says its length is without being drawn, if it can say, /// as the length its draw would report: a fraction in it is resolved - /// against this widget's frame, which is the frame a child asked with + /// against this widget's rel base, which is the rel base a child asked with /// nothing narrowed gets. Asking counts as reading its size. pub fn size_hint(&mut self, id: &StrongWidget, axis: Axis) -> Option { let widgets = self.rsc.widgets(); @@ -281,8 +319,8 @@ impl<'a> Painter<'a> { .get_dyn(id.id()) .and_then(|widget| widget.size_hint(axis)) }); - let frame = self.frame.axis(axis); - let resolved = hint.map(|hint| hint.within_len(frame)); + let rel_base = self.rel_base.axis(axis); + let resolved = hint.map(|hint| hint.within_len(rel_base)); #[cfg(feature = "layout-diagnostics")] { diag::hint_read(id.id(), self.id, axis, resolved); @@ -293,12 +331,12 @@ impl<'a> Painter<'a> { } if let Some(hint) = hint { self.depend_on(id); - // Resolving a fraction against this frame makes this draw a - // function of the frame's length. The fraction to ask about is - // the child's own: resolved against a frame of pixels, none is + // Resolving a fraction against this rel base makes this draw a + // function of the rel base's length. The fraction to ask about is + // the child's own: resolved against a rel base of pixels, none is // left to see it by. if hint.rel != Rel::ZERO { - self.own.frame_len[axis as usize] = Some(frame); + self.own.rel_base[axis as usize] = Some(rel_base); } } resolved @@ -322,7 +360,7 @@ impl<'a> Painter<'a> { ui.text.render(buffer, attrs, width) } - /// Writes glyphs in the selected frame or region coordinates. + /// Writes glyphs in the selected rel base or region coordinates. // TODO: merge the text methods into the primitive ones. pub fn glyphs(&mut self, text: &RenderedText, origin: UiRegion) { // Glyph offsets and sizes are pixels, which compose additively. @@ -358,7 +396,7 @@ impl<'a> Painter<'a> { } /// The symbolic length of this widget's own box along one axis, in the - /// lengths of its frame that it places its children in. Reading it pins + /// lengths of its rel base that it places its children in. Reading it pins /// the drawing to that length -- and to nothing about where the box /// starts, which is what lets a container move without being drawn /// again. One axis at a time, because a container that divides one axis @@ -369,14 +407,14 @@ impl<'a> Painter<'a> { len } - /// The symbolic length of this widget's frame along one axis: what a - /// fraction it or anything under it declares is a fraction of. A - /// container reads it to hand a length of it down -- padding, which - /// takes its pixels off. Reading it pins the drawing to that frame, the - /// way [`Self::region_len`] pins it to the box. - pub fn frame_len(&mut self, axis: Axis) -> Len { - let len = self.frame.axis(axis); - self.own.frame_len[axis as usize] = Some(len); + /// This widget's rel base along one axis: what a fraction it or anything + /// under it declares or reports is a fraction of. A container reads it + /// to hand a length of it down -- padding, which takes its pixels off. + /// Reading it pins the drawing to that rel base, the way + /// [`Self::region_len`] pins it to the box. + pub fn rel_base(&mut self, axis: Axis) -> Len { + let len = self.rel_base.axis(axis); + self.own.rel_base[axis as usize] = Some(len); len } @@ -559,14 +597,14 @@ impl PrimitiveLike for &TextureHandle { /// only what the child was asked with. impl Painter<'_> { /// Window ranges are already about the one unit and combine directly. - /// A frame pin becomes this widget's own frame wherever a length of it + /// A rel base pin becomes this widget's own rel base wherever a length of it /// is what reached the child; where only pixels did, no length of this - /// frame can change the child's and the pin stops here. + /// rel base can change the child's and the pin stops here. /// /// A child's validity maps back through the part of this widget's box, /// where the box the child was asked in is that part; a declared length /// places the box inside the part instead, and then only that length - /// reaches the child. A narrowed frame is not one of these: it decides + /// reaches the child. A narrowed rel base is not one of these: it decides /// what fractions under the child mean and leaves the box the part it /// was given. fn in_parent( @@ -586,18 +624,8 @@ impl Painter<'_> { let reaches = narrow[n].is_none() && !matches!(place[n].part(), Part::Sized(_)) && declared[n].is_none_or(|len| len.rel != Rel::ZERO); - result.frame_len[n] = holds.frame_len[n].and(reaches.then(|| self.frame.axis(axis))); + result.rel_base[n] = holds.rel_base[n].and(reaches.then(|| self.rel_base.axis(axis))); match (place[n].part(), declared[n].is_some()) { - // Its box is this widget's own, or a part of it in that - // box's own lengths: so what it holds for is a range on this - // widget's own box, which is what lets that box move without - // a redraw. A length it pinned is this widget's length - // wherever the part is the whole of it, and pins the same - // way. - (Part::All, false) => { - result.region[n] = holds.region[n]; - result.region_len[n] = holds.region_len[n]; - } // Its box is a part of this widget's own box, in that box's // own lengths, so what it holds for maps back through that // part into a range on this widget's box. A length it pinned @@ -614,7 +642,7 @@ impl Painter<'_> { }); } // Its box is a length this widget decided, from its own - // frame or from a sibling's answer: no length of this + // rel base or from a sibling's answer: no length of this // widget's box reaches it, so what it holds for is a range // on the window and none of it on that box. _ => { @@ -627,6 +655,14 @@ impl Painter<'_> { } } +/// A box of a widget's own, per axis, with the answer placed inside it. +fn region_places(region: UiRegion) -> [Place; 2] { + [ + Place::Within(Part::Of(region.x)), + Place::Within(Part::Of(region.y)), + ] +} + /// What a widget declares a length of its box to be. `leftover` is not one: a /// share of what is left over is only a length to the widget dividing one, /// so it passes up in the size instead. @@ -662,11 +698,11 @@ pub(crate) fn fills(reported: LayoutLen, declared: Option, decided: b /// it reported, on the side of the part its alignment says, and the whole /// part wherever the answer fills it. /// -/// The length it reported is a length of its frame, and the part is one too, +/// The length it reported is a length of its rel base, and the part is one too, /// so this takes one from the other rather than composing it into the part. /// That is what makes a fraction the same fraction wherever the part it is /// placed in sits and however long it is -- the fraction is resolved once, -/// here, against the frame it was reported of. +/// here, against the rel base it was reported of. pub(crate) fn placement( region: UiRegion, size: Size, @@ -689,27 +725,27 @@ pub(crate) fn placement( placed } -/// The frame length and the box a child is asked in, in the coordinates the +/// The rel base length and the box a child is asked in, in the coordinates the /// widget asking draws in. /// /// `own` is that widget's own box, and `place` what of it the child is -/// given. `narrow` is a frame the container decided for the child -- a row's -/// slot, or padding's frame less its pixels -- and [`Part::Sized`] one a +/// given. `narrow` 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 /// can name. The child's declaration is a fraction of whichever reached it, /// and is the only one of the three that also places the box: a box the /// caller decided is what `place` names. -pub(crate) fn frame_and_region( +pub(crate) fn rel_base_and_region( own: UiRegion, - parent_frame: UiVec2, + parent_rel_base: UiVec2, place: [Place; 2], narrow: [Option; 2], declared: [Option; 2], align: RegionAlign, ) -> (UiVec2, UiRegion) { let given = region_of(own, place, align); - let mut frame = parent_frame; + let mut rel_base = parent_rel_base; let mut region = given; for axis in AXES { let n = axis as usize; @@ -719,18 +755,18 @@ pub(crate) fn frame_and_region( }; let base = sized .or(narrow[n]) - .unwrap_or_else(|| parent_frame.axis(axis)); + .unwrap_or_else(|| parent_rel_base.axis(axis)); let len = declared[n] .map(|len| Len::from_parts(len.rel, len.px).within_len(base)) .unwrap_or(base); - *frame.axis_mut(axis) = len; + *rel_base.axis_mut(axis) = len; if declared[n].is_some() { let slot = given.axis(axis); let start = slot.start + (slot.len() - len).scale(align.axis(axis).rel()); *region.axis_mut(axis) = UiSpan::new(start, start + len); } } - (frame, region) + (rel_base, region) } /// The part of a widget's own box a `place` names, in the coordinates that diff --git a/core/src/ui/place.rs b/core/src/ui/place.rs index f722c00..e7264d2 100644 --- a/core/src/ui/place.rs +++ b/core/src/ui/place.rs @@ -3,14 +3,12 @@ use crate::{AxisAlign, Len, PrimitiveHandle, UiRegion, UiSpan}; /// What of a widget's own box a child is given, along one axis. #[derive(Clone, Copy, Debug, PartialEq)] pub enum Part { - /// The whole of it. - All, /// Window lengths from where the box starts, which is what a container /// dividing room among its children speaks: a child's report is a window /// length, so the cursor that sums those reports is one too. A moved box /// re-places every child by re-adding its start, exactly. A fraction /// here is a fraction of the window and not of the box -- the whole of a - /// box is [`Self::All`], not a `rel(1.0)` span. + /// box is `Of(UiSpan::FULL)`, not a `rel(1.0)` span. From(UiSpan), /// A part of the box in its own coordinates, which is what a container /// that insets one speaks: taking eleven pixels off the end needs no @@ -19,7 +17,7 @@ pub enum Part { /// then feeds back into the answer. Of(UiSpan), /// A box of this length, wherever in the parent's box the child's own - /// alignment puts it, and that same length as its frame. Unlike `From`, + /// alignment puts it, and that same length as its rel base. Unlike `From`, /// it is a length decided from above rather than a place along a /// container's cursor -- what a stack's sizing child decides for the /// rest. @@ -27,10 +25,13 @@ pub enum Part { } impl Part { + /// The whole of the box. Not a variant of its own: it composes and + /// inverts through the same expressions every other `Of` does. + pub const WHOLE: Self = Self::Of(UiSpan::FULL); + /// Where it lands in the coordinates `own` is in. pub(crate) fn of(self, own: UiSpan, align: AxisAlign) -> UiSpan { match self { - Self::All => own, Self::From(span) => UiSpan::new(own.start + span.start, own.start + span.end), Self::Of(span) => span.within(&own), Self::Sized(len) => { diff --git a/core/src/ui/render_state.rs b/core/src/ui/render_state.rs index a392047..5cc5a43 100644 --- a/core/src/ui/render_state.rs +++ b/core/src/ui/render_state.rs @@ -1,6 +1,6 @@ #[cfg(feature = "layout-diagnostics")] use crate::layout_diagnostics::{self as diag, Counter, ReuseOutcome, TimerKind}; -use crate::ui::painter::{declared_lens, frame_and_region, placement}; +use crate::ui::painter::{declared_lens, placement, rel_base_and_region}; use crate::{ ActiveData, Axis, DrawLayers, IdLike, LayoutHolds, LayoutLen, Len, MaskIdx, MoveIdx, Moves, Painter, Part, PixelRegion, Place, PxVec2, Rel, Size, StrongWidget, UiRegion, UiRsc, UiSpan, @@ -22,7 +22,7 @@ pub(super) struct DrawInfo { pub mask: MaskIdx, /// What a fraction declared or reported under this widget is a fraction /// of, as a length of the window. - pub frame: UiVec2, + pub rel_base: UiVec2, /// The box the widget is asked in, in its parent region node's /// coordinates. pub region: UiRegion, @@ -31,12 +31,12 @@ pub(super) struct DrawInfo { /// parent puts the answer somewhere else. pub placed: [Place; 2], pub asked: [Place; 2], - /// A frame the parent decided for it on each axis, as a length of the + /// A rel base the parent decided for it on each axis, as a length of the /// window, which the widget's own declaration is a fraction of. pub narrow: [Option; 2], /// Whether the parent already asked about this widget in this draw. pub re_asked: bool, - /// The frame in pixels, resolved once against the window. + /// The rel base in pixels, resolved once against the window. pub px: PxVec2, } @@ -53,7 +53,7 @@ impl DrawInfo { pub(super) struct Placing { pub id: WidgetId, pub region: UiRegion, - pub frame: UiVec2, + pub rel_base: UiVec2, pub window: PxVec2, pub depth: usize, pub move_idx: MoveIdx, @@ -120,13 +120,13 @@ impl UiRenderState { let Some(root) = self.old_root else { return }; let stands = self.active.get(&root).is_some_and(|active| { // Nothing above the root chose anything, so the box it was first - // asked about is the whole of its frame. Both its answer and its + // asked about is the whole of its rel base. Both its answer and its // drawing have to stand in the new window, since nothing above // it will ask either again. let answer = active .answer - .is_some_and(|(_, holds)| holds.contains(size, active.frame, active.region)); - answer && active.holds.contains(size, active.frame, active.region) + .is_some_and(|(_, holds)| holds.contains(size, active.rel_base, active.region)); + answer && active.holds.contains(size, active.rel_base, active.region) }); if !stands { widgets.needs_redraw.insert(root); @@ -134,9 +134,9 @@ impl UiRenderState { } /// The root is asked about in the output. Its own rules narrow both its - /// frame and box; nothing above it chose a different one. - fn root_info(&self, frame: UiVec2, region: UiRegion) -> DrawInfo { - let px = frame.to_px(self.output_size); + /// rel base and box; nothing above it chose a different one. + fn root_info(&self, rel_base: UiVec2, region: UiRegion) -> DrawInfo { + let px = rel_base.to_px(self.output_size); DrawInfo { layer: 0, parent: None, @@ -144,10 +144,10 @@ impl UiRenderState { parent_move: MoveIdx::NONE, region_node: false, mask: MaskIdx::NONE, - frame, + rel_base, region, - placed: [Place::Within(Part::All); 2], - asked: [Place::Within(Part::All); 2], + placed: [Place::Within(Part::WHOLE); 2], + asked: [Place::Within(Part::WHOLE); 2], narrow: [None; 2], re_asked: false, px, @@ -196,20 +196,20 @@ impl UiRenderState { let _layout = diag::timer(TimerKind::FullLayout); self.clear(rsc); if let Some(id) = root { - let (frame, region) = Self::root_layout(id.id(), rsc.widgets()); - let info = self.root_info(frame, region); + let (rel_base, region) = Self::root_layout(id.id(), rsc.widgets()); + let info = self.root_info(rel_base, region); self.draw_inner(id.id(), info, None, rsc); } } - /// The root's frame and box: the window, taken in by the root's own + /// The root's rel base and box: the window, taken in by the root's own /// rules. Nothing above it narrowed anything or chose where it goes, so /// its declaration is the whole of what decides either. fn root_layout(id: WidgetId, widgets: &Widgets) -> (UiVec2, UiRegion) { - frame_and_region( + rel_base_and_region( UiRegion::FULL, UiVec2::FULL_SIZE, - [Place::Within(Part::All); 2], + [Place::Within(Part::WHOLE); 2], [None; 2], declared_lens(widgets, id), widgets.alignment(id), @@ -269,10 +269,10 @@ impl UiRenderState { let drawing_holds = self.active[&id].holds; let active = self.active.get_mut(&id).unwrap(); - // Whoever asked owns how the boxes were reached: the frame it stated, + // Whoever asked owns how the boxes were reached: the rel base it stated, // and what of its own box it asked in. A local redraw asks the same // question again from these. - active.frame = info.frame; + active.rel_base = info.rel_base; active.narrow = info.narrow; active.re_asked = info.re_asked; active.answer = Some(answer); @@ -292,7 +292,7 @@ impl UiRenderState { (answer.0, answer.1, drawing_holds) } - /// Calls a widget's `draw` and keeps what it drew in `region` of `frame`. + /// Calls a widget's `draw` and keeps what it drew in `region`. fn draw_at( &mut self, id: WidgetId, @@ -301,7 +301,7 @@ impl UiRenderState { old: Option, rsc: &mut dyn UiRsc, ) -> (Size, LayoutHolds) { - let frame = info.frame; + let rel_base = info.rel_base; let (move_idx, region, retired_move) = match info.region_node { // A node entry is only a translation. Its local box keeps the // same window-unit length as the box in its parent's node. @@ -324,7 +324,7 @@ impl UiRenderState { let window = self.output_size; let mut painter = Painter { state: self, - frame, + rel_base, region, window, mask: info.mask, @@ -359,7 +359,7 @@ impl UiRenderState { let Painter { state: _, rsc: _, - frame: _, + rel_base: _, region: _, window: _, mask, @@ -387,18 +387,18 @@ impl UiRenderState { // A rule wins on the axis it names, and the draw answers the rest. // Applied here so it is one place rather than every widget that could // carry one, and so the widget under a rule never learns of it. The - // frame is the answer where the rule gave a length outright: it was - // resolved into the frame when the child was asked, and resolving it + // rel base is the answer where the rule gave a length outright: it was + // resolved into the rel base when the child was asked, and resolving it // again here would take the fraction of a fraction. let rules = rsc.widgets().size_rules(id); let ruled = |axis: Axis, reported: LayoutLen| match rules.axis(axis).exact() { None => reported, Some(len) if len.leftover == Weight::ZERO => LayoutLen { - rel: info.frame.axis(axis).rel, - px: info.frame.axis(axis).px, + rel: info.rel_base.axis(axis).rel, + px: info.rel_base.axis(axis).px, leftover: Weight::ZERO, }, - Some(len) => len.within_len(info.frame.axis(axis)), + Some(len) => len.within_len(info.rel_base.axis(axis)), }; let size = Size { x: ruled(Axis::X, size.x), @@ -428,27 +428,27 @@ impl UiRenderState { if let Some(idx) = retired_move { self.moves.remove(idx); } - // A rule that is a fraction of the frame is answered with the - // frame's own length, so the answer is that frame's and not just + // A rule that is a fraction of the rel base is answered with the + // rel base's own length, so the answer is that rel base's and not just // that many pixels of this window -- the same pin a widget that read - // its frame took for its drawing. - let frame_len = AXES.map(|axis| { + // its rel base took for its drawing. + let rel_base = AXES.map(|axis| { let fraction = rules .axis(axis) .exact() .is_some_and(|len| len.rel != Rel::ZERO); match fraction { - true => Some(info.frame.axis(axis)), - false => own.frame_len[axis as usize], + true => Some(info.rel_base.axis(axis)), + false => own.rel_base[axis as usize], } }); - let own_holds = LayoutHolds { frame_len, ..own }; + let own_holds = LayoutHolds { rel_base, ..own }; let answer_holds = own_holds.and(answer_under); let holds = under .into_iter() .fold(answer_holds, |holds, (_, child)| holds.and(child)); debug_assert!( - holds.contains(self.output_size, info.frame, region), + holds.contains(self.output_size, info.rel_base, region), "'{}' ({id:?}) drew in {px:?}, outside the ranges it reported: {holds:?}", rsc.widgets().label(id), ); @@ -466,10 +466,10 @@ impl UiRenderState { parent_move: move_idx, region_node: false, mask, - frame: UiVec2::FULL_SIZE, + rel_base: UiVec2::FULL_SIZE, region: UiRegion::FULL, - placed: [Place::Within(Part::All); 2], - asked: [Place::Within(Part::All); 2], + placed: [Place::Within(Part::WHOLE); 2], + asked: [Place::Within(Part::WHOLE); 2], narrow: [None; 2], re_asked: false, px, @@ -483,7 +483,7 @@ impl UiRenderState { let active = ActiveData { id, placement: region, - frame: info.frame, + rel_base: info.rel_base, narrow: info.narrow, placed: info.placed, asked: info.asked, @@ -555,7 +555,7 @@ impl UiRenderState { let answer = active.answer?; answer .1 - .contains(self.output_size, info.frame, region) + .contains(self.output_size, info.rel_base, region) .then_some(answer) } @@ -620,10 +620,13 @@ impl UiRenderState { // In pixels, because the box is a fraction of the window and that // may be what changed -- an unchanged fraction of a window half the // size is half the widget. - if !active.holds.contains(self.output_size, info.frame, region) { + if !active + .holds + .contains(self.output_size, info.rel_base, region) + { #[cfg(feature = "layout-diagnostics")] { - // Which of the three said no, so a frame that redraws more + // Which of the three said no, so a rel base that redraws more // than it should says where to look. They overlap: a drawing // can be outside two of them at once. let holds = active.holds; @@ -633,9 +636,10 @@ impl UiRenderState { diag::bump(Counter::OutsidePinnedLen); } if !holds.window[n].contains(self.output_size.axis(axis)) - || holds.frame_len[n].is_some_and(|pinned| pinned != info.frame.axis(axis)) + || holds.rel_base[n] + .is_some_and(|pinned| pinned != info.rel_base.axis(axis)) { - diag::bump(Counter::OutsideFrame); + diag::bump(Counter::OutsideRelBase); } if !holds.region[n] .contains(region.axis(axis).len().to_px(self.output_size.axis(axis))) @@ -677,7 +681,7 @@ impl UiRenderState { } self.redepth(id, info.depth); let active = self.active.get_mut(&id).unwrap(); - active.frame = info.frame; + active.rel_base = info.rel_base; active.placed = info.placed; #[cfg(feature = "layout-diagnostics")] { @@ -718,7 +722,7 @@ impl UiRenderState { rsc: &mut dyn UiRsc, ) { let active = &self.active[&child]; - let (frame, region) = Self::ask_again(active, at, place); + let (rel_base, region) = Self::ask_again(active, at, place); let placed = placement( region, active.measured().unwrap_or(active.size), @@ -733,25 +737,25 @@ impl UiRenderState { parent_move: at.move_idx, region_node: active.move_idx != active.parent_move, mask: at.mask, - frame, + rel_base, region, placed: place, asked: active.asked, narrow: active.narrow, re_asked: active.re_asked, - px: frame.to_px(at.window), + px: rel_base.to_px(at.window), }; self.relocate(child, placed, info, rsc); } - /// The frame and the box a widget already drawn is given at `place` of - /// the box its parent is being taken as. What narrowed its frame and what + /// The rel base and the box a widget already drawn is given at `place` of + /// the box its parent is being taken as. What narrowed its rel base and what /// it declared are its own record's, so both are resolved against that - /// parent's frame again exactly as the first ask resolved them. + /// parent's rel base again exactly as the first ask resolved them. fn ask_again(active: &ActiveData, at: &Placing, place: [Place; 2]) -> (UiVec2, UiRegion) { - frame_and_region( + rel_base_and_region( at.region, - at.frame, + at.rel_base, place, active.narrow, active.declared, @@ -776,7 +780,7 @@ impl UiRenderState { let at = Placing { id, region: placed, - frame: info.frame, + rel_base: info.rel_base, window: self.output_size, depth: info.depth, move_idx: active.move_idx, @@ -881,10 +885,10 @@ impl UiRenderState { ActiveData { id, placement: UiRegion::FULL, - frame: UiVec2::FULL_SIZE, + rel_base: UiVec2::FULL_SIZE, narrow: [None; 2], - placed: [Place::Within(Part::All); 2], - asked: [Place::Within(Part::All); 2], + placed: [Place::Within(Part::WHOLE); 2], + asked: [Place::Within(Part::WHOLE); 2], region: UiRegion::FULL, answer: None, re_asked: false, @@ -1112,10 +1116,10 @@ impl UiRenderState { // box is its own to work out again against the output. Every other // widget was given one. let Some(parent) = active.parent else { - let (frame, region) = Self::root_layout(id, rsc.widgets()); + let (rel_base, region) = Self::root_layout(id, rsc.widgets()); let info = DrawInfo { mask: active.parent_mask, - ..self.root_info(frame, region) + ..self.root_info(rel_base, region) }; #[cfg(feature = "layout-diagnostics")] diag::bump(Counter::LocalRedraws); @@ -1130,7 +1134,7 @@ impl UiRenderState { // parent's answer put its own drawing is not a question anybody // asked, and nothing is asked in it here either. let parent_at = self.placing_of(parent, self.active[&parent].region); - let (frame, region) = Self::ask_again(active, &parent_at, active.asked); + let (rel_base, region) = Self::ask_again(active, &parent_at, active.asked); let info = DrawInfo { layer: active.layer, parent: active.parent, @@ -1138,13 +1142,13 @@ impl UiRenderState { parent_move: active.parent_move, region_node: rsc.widgets().is_region_node(id), mask: active.parent_mask, - frame, + rel_base, region, placed: active.asked, asked: active.asked, narrow: active.narrow, re_asked: false, - px: frame.to_px(self.output_size), + px: rel_base.to_px(self.output_size), }; #[cfg(feature = "layout-diagnostics")] diag::bump(Counter::LocalRedraws); @@ -1161,7 +1165,7 @@ impl UiRenderState { active.answer = was_answer; } if active.holds.covers(was_holds) - && was_holds.contains(self.output_size, active.frame, active.placement) + && was_holds.contains(self.output_size, active.rel_base, active.placement) { active.holds = was_holds; } @@ -1192,7 +1196,7 @@ impl UiRenderState { Placing { id, region, - frame: active.frame, + rel_base: active.rel_base, window: self.output_size, depth: active.depth, move_idx: active.move_idx, diff --git a/src/random.rs b/src/random.rs index 5f7bb3f..5c0299b 100644 --- a/src/random.rs +++ b/src/random.rs @@ -120,7 +120,7 @@ impl Widget for Branch { let cut = Len::from_parts(Rel::ZERO, Px::from_int(40)); let top = Place::Within(Part::From(UiSpan::new(Len::ZERO, cut))); let measured = painter - .widget_at(&self.probe, [None; 2], [Place::Within(Part::All), top]) + .widget_at(&self.probe, [None; 2], [Place::Within(Part::WHOLE), top]) .len(Axis::X); let len = measured.apply_leftover(); let px = painter.to_px(len, Axis::X); @@ -135,7 +135,7 @@ impl Widget for Branch { painter.window_holds(Axis::X, holds.through(len)); let below = Place::Within(Part::From(UiSpan::new(cut, painter.region_len(Axis::Y)))); - let place = [Place::Within(Part::All), below]; + let place = [Place::Within(Part::WHOLE), below]; match px > threshold { true => painter.widget_at(&self.wide, [None; 2], place), false => painter.widget_at(&self.narrow, [None; 2], place), diff --git a/src/widget/position/offset.rs b/src/widget/position/offset.rs index 758fdcd..572f5f5 100644 --- a/src/widget/position/offset.rs +++ b/src/widget/position/offset.rs @@ -7,14 +7,8 @@ pub struct Offset { impl Widget for Offset { fn draw(&mut self, painter: &mut Painter) -> Size { - // The whole of this widget's box, moved: the frame passes through, so - // what the child declares or reports means the same as it would - // without the offset. - let moved = |len: Len, amt: Len| Place::Within(Part::From(UiSpan::new(amt, len + amt))); - let place = [ - moved(painter.region_len(Axis::X), self.amt.x), - moved(painter.region_len(Axis::Y), self.amt.y), - ]; - painter.widget_at(&self.inner, [None; 2], place).size() + painter + .widget_within(&self.inner, UiRegion::FULL.offset(self.amt)) + .size() } } diff --git a/src/widget/position/pad.rs b/src/widget/position/pad.rs index 474c993..7d001ae 100644 --- a/src/widget/position/pad.rs +++ b/src/widget/position/pad.rs @@ -14,31 +14,14 @@ impl Widget for Pad { // widget -- the slack is the inner's to sit in, and forcing the near // edge pinned it to a corner it had not asked for. // - // Padding is an inset of both: it comes off the frame, so `rel(1)` + // Padding is an inset of both: it comes off the rel base, so `rel(1)` // under it fills this widget rather than overflowing it by the // padding, and it comes off the box, so what is drawn sits inside. // The two stay distinct -- the box can be narrower still, where a row // asked this widget in the room left, and a text wraps at that. - let inset = |lead: Px, trail: Px| { - Place::Within(Part::Of(UiSpan::new( - Len::from_parts(Rel::ZERO, lead), - Len::from_parts(Rel::ONE, -trail), - ))) - }; - let place = [ - inset(self.padding.left, self.padding.right), - inset(self.padding.top, self.padding.bottom), - ]; - // Read from this widget's own frame rather than written as a - // fraction of it: a frame is a length of the window like everything - // else here, and taking the padding off is the whole of what this - // widget does to it. - let narrow = [ - (Axis::X, self.padding.left + self.padding.right), - (Axis::Y, self.padding.top + self.padding.bottom), - ] - .map(|(axis, pixels)| Some(painter.frame_len(axis) - Len::from_parts(Rel::ZERO, pixels))); - let inner = painter.widget_at(&self.inner, narrow, place).size(); + let inner = painter + .widget_within(&self.inner, self.padding.region()) + .size(); Size { x: LayoutLen { px: inner.x.px + self.padding.left + self.padding.right, diff --git a/src/widget/position/scroll.rs b/src/widget/position/scroll.rs index b04c1a5..1369a95 100644 --- a/src/widget/position/scroll.rs +++ b/src/widget/position/scroll.rs @@ -14,7 +14,7 @@ impl Widget for Scroll { let container_len = painter.px_len(self.axis); // Asked in the whole viewport, then put at the scrolled offset. let answer_len = painter - .widget_at(&self.inner, [None; 2], [Place::Fill(Part::All); 2]) + .widget_at(&self.inner, [None; 2], [Place::Fill(Part::WHOLE); 2]) .len(self.axis); let fixed = painter.to_px(Len::from_parts(answer_len.rel, answer_len.px), self.axis); self.container_len = container_len; @@ -56,15 +56,17 @@ impl Widget for Scroll { let start = Len::from_parts(Rel::ZERO, anchor - self.amt); Part::From(UiSpan::new(start, start.offset(self.content_len))) } - false => Part::All, + false => Part::WHOLE, }; - // The viewport is the inner's frame, so a fraction it declares or + // The viewport is the inner's rel base, so a fraction it declares or // reports is a fraction of what is on screen rather than of the // content box its own answer decided. Where it goes is the content // box, scrolled: its drawing moved there, not made again there. painter.place_at( &self.inner, - self.axis.pair(Place::Fill(content), Place::Fill(Part::All)), + [None; 2], + self.axis + .pair(Place::Fill(content), Place::Fill(Part::WHOLE)), ); // What it occupies is its box, on both axes: it clips its content to // that box, so it can neither take less of one nor honestly ask for diff --git a/src/widget/position/span.rs b/src/widget/position/span.rs index cd84f70..f6c3c97 100644 --- a/src/widget/position/span.rs +++ b/src/widget/position/span.rs @@ -10,7 +10,7 @@ pub struct Span { impl Widget for Span { fn draw(&mut self, painter: &mut Painter) -> Size { let axis = self.dir.axis; - // The row: this span's own box, as a length of the frame its children + // The row: this span's own box, as a length of the rel base its children // are laid out against. Its start is nothing's business -- a slot is // a length from it -- so what this reads is the length alone. let far = painter.region_len(axis); @@ -21,29 +21,23 @@ impl Widget for Span { // Across itself the child sits where its own alignment says, in the // whole of the row: a span is what contains its children there, and // nothing divides that axis. - let across = Place::Within(Part::All); + let across = Place::Within(Part::WHOLE); // A length for every child before their final slots are chosen: from - // a hint where one says, and from drawing otherwise. The frame passes + // a hint where one says, and from drawing otherwise. The rel base passes // through unchanged, so `rel(0.5)` is half the area this span was // given whatever else is in it and wherever this child sits among // them; what a drawn child is asked in is the room left from the // cursor, because a text has to wrap at the width actually there. let mut cursor = Len::rel_min(); let mut lens = Vec::with_capacity(self.children.len()); - let mut drawn_across = Vec::with_capacity(self.children.len()); for child in &self.children { let len = match painter.size_hint(child, axis) { - Some(len) => { - drawn_across.push(None); - len - } + Some(len) => len, None => { let room = Place::Within(Part::From(along(cursor, far))); - let size = painter + painter .widget_at(child, [None; 2], axis.pair(room, across)) - .size(); - drawn_across.push(Some(size.axis(!axis))); - size.axis(axis) + .len(axis) } }; cursor.px += len.px + self.gap; @@ -63,7 +57,7 @@ impl Widget for Span { ); // What is left for the shares to divide: the row less everything - // fixed, as a length of the frame rather than a number of pixels. + // fixed, as a length of the rel base rather than a number of pixels. let room = far - Len::from_parts(total.rel, total.px); // Whether anything is left over is a question in pixels: `rel(0.5)` // beside 300 px is full at 600 and overfull at 400. Asked of `room` @@ -100,7 +94,7 @@ impl Widget for Span { let mut taken = Weight::ZERO; let mut start = Len::rel_min(); let mut ortho = LayoutLen::ZERO; - for ((child, &len), &across_len) in self.children.iter().zip(&lens).zip(&drawn_across) { + for (child, &len) in self.children.iter().zip(&lens) { // A child asking for nothing but a part of what is left over, // when nothing is, is not drawn at all. One that also asked for // pixels or a fraction keeps those and overflows. @@ -121,7 +115,7 @@ impl Widget for Span { // Along the row the span says where the child goes, and that slot // is the child's box outright rather than something to place an // answer inside again. A share is decided here and nowhere - // else: its slot narrows its frame, and the child is asked in + // else: its slot narrows its rel base, and the child is asked in // it, since a text wraps at the width it is actually given. A // fixed child's slot is its own answer, so a drawing made in the // room is put there as it is, and one not made yet is made here. @@ -131,13 +125,7 @@ impl Widget for Span { if len.leftover > Weight::ZERO && shares { narrow[axis as usize] = Some(slot.len()); } - let used = match (across_len, narrow[axis as usize]) { - (Some(across_len), None) => { - painter.place_at(child, place); - across_len - } - _ => painter.widget_at(child, narrow, place).len(!axis), - }; + let used = painter.place_at(child, narrow, place).len(!axis); if shrinks { // Choosing between a fixed and a relative length from the // span's own eventual width admits multiple fixed points. diff --git a/src/widget/position/stack.rs b/src/widget/position/stack.rs index 05f97fd..7157618 100644 --- a/src/widget/position/stack.rs +++ b/src/widget/position/stack.rs @@ -23,7 +23,7 @@ impl Widget for Stack { Some((i, child)) => { painter.child_layer_at(i); painter - .widget_at(child, [None; 2], [Place::Fill(Part::All); 2]) + .widget_at(child, [None; 2], [Place::Fill(Part::WHOLE); 2]) .size() } None => Size::LEFTOVER, @@ -37,7 +37,7 @@ impl Widget for Stack { let len = size.axis(axis); match len.leftover == Weight::ZERO { true => Place::Fill(Part::Sized(Len::from_parts(len.rel, len.px))), - false => Place::Within(Part::All), + false => Place::Within(Part::WHOLE), } }); for (i, child) in self.children.iter().enumerate() { diff --git a/tests/cases/determinism.rs b/tests/cases/determinism.rs index 4e1eeb5..76dd590 100644 --- a/tests/cases/determinism.rs +++ b/tests/cases/determinism.rs @@ -24,12 +24,12 @@ impl Widget for BranchesOnMeasurement { let cut = Len::from_parts(Rel::ZERO, Px::from_int(40)); let top = Place::Within(Part::From(UiSpan::new(Len::ZERO, cut))); let measured = painter - .widget_at(&self.probe, [None; 2], [Place::Within(Part::All), top]) + .widget_at(&self.probe, [None; 2], [Place::Within(Part::WHOLE), top]) .len(Axis::X); let px = painter.to_px(measured.apply_leftover(), Axis::X); let below = Place::Within(Part::From(UiSpan::new(cut, painter.region_len(Axis::Y)))); - let place = [Place::Within(Part::All), below]; + let place = [Place::Within(Part::WHOLE), below]; match px > Px::from_f32(self.threshold) { true => painter.widget_at(&self.wide, [None; 2], place), false => painter.widget_at(&self.narrow, [None; 2], place), diff --git a/tests/cases/layout.rs b/tests/cases/layout.rs index 301b40f..a62d857 100644 --- a/tests/cases/layout.rs +++ b/tests/cases/layout.rs @@ -108,7 +108,7 @@ const PARAGRAPH: &str = "Wrapping shapes one source into as many lines as the bo /// the icon's width, while a wrapping text beside it is asked in the room /// left, 900 - 24 - 32, and wraps there. #[test] -fn padding_keeps_the_frame_distinct_from_the_room_left_in_a_row() { +fn padding_keeps_the_rel_base_distinct_from_the_room_left_in_a_row() { let mut h = Harness::new((900, 200)); let icon = rect(Color::RED).width(24).add(&mut h.rsc); let fill = rect(Color::GREEN).width(rel(1.0)).add(&mut h.rsc); @@ -125,7 +125,7 @@ fn padding_keeps_the_frame_distinct_from_the_room_left_in_a_row() { let active = &h.render.active[&text.id()]; let window = h.render.output_size().x; let asked = active.region.x.len().to_px(window); - assert_eq!(active.frame.x.to_px(window), Px::from_int(868)); + assert_eq!(active.rel_base.x.to_px(window), Px::from_int(868)); assert_eq!(asked, Px::from_int(844)); } @@ -155,7 +155,7 @@ fn a_share_inside_padding_fills_the_slot_it_was_given() { /// The same padding in a share instead: the slot is 450, so both the /// fraction and the wrap are the slot less the padding, and the two agree. #[test] -fn padding_narrows_both_frame_and_box_inside_a_share() { +fn padding_narrows_both_rel_base_and_box_inside_a_share() { let mut h = Harness::new((900, 200)); let fill = rect(Color::GREEN).width(rel(1.0)).add(&mut h.rsc); let padded = fill.pad(16).width(leftover(1)).add(&mut h.rsc); @@ -170,7 +170,7 @@ fn padding_narrows_both_frame_and_box_inside_a_share() { h.set_root((padded, other).span(Dir::RIGHT).width(rel(1.0))); let active = &h.render.active[&text.id()]; let window = h.render.output_size().x; - assert_eq!(active.frame.x.to_px(window), Px::from_int(418)); + assert_eq!(active.rel_base.x.to_px(window), Px::from_int(418)); assert_eq!(active.region.x.len().to_px(window), Px::from_int(418)); } diff --git a/tests/cases/retained.rs b/tests/cases/retained.rs index 3e6e6dd..5e20f96 100644 --- a/tests/cases/retained.rs +++ b/tests/cases/retained.rs @@ -217,7 +217,7 @@ impl Widget for FromHint { painter.widget_at( &self.inner, [None; 2], - [Place::Within(Part::All), Place::Within(Part::From(top))], + [Place::Within(Part::WHOLE), Place::Within(Part::From(top))], ); Size::LEFTOVER } diff --git a/tests/scenario/mod.rs b/tests/scenario/mod.rs index ca9fabf..b7aa7be 100644 --- a/tests/scenario/mod.rs +++ b/tests/scenario/mod.rs @@ -406,8 +406,8 @@ fn describe_widget(id: WidgetId, h: &Harness) -> String { fn record(id: WidgetId, h: &Harness) -> String { let active = &h.render.active[&id]; format!( - "frame {} region {} placement {} size {}", - active.frame, active.region, active.placement, active.size, + "rel_base {} region {} placement {} size {}", + active.rel_base, active.region, active.placement, active.size, ) }