Say region and placement, not extent
The split box was named `region` and `placement` on 2026-09-17; `frame` came back as a length and survived, `extent` did not. It stayed as the name for both halves, distinguished only by prose: `draw_at` bound the caller's `part` to a parameter called `extent`, and `ActiveData` held two `UiRegion`s that `draw_at` wrote `part: extent` from. The box a parent asks a widget in is now the region, and where its drawing ends up is its placement. `Painter`'s four holds accumulators become the one `LayoutHolds` they were assembled into, which also drops the name mapping between them. The cold dump of 400 depth-5 trees is byte-identical across the change.
This commit is contained in:
1 parent
84dad211f5
commit
5642f2010a
13 files changed
+212
-227
No files matched your search
@@ -54,11 +54,11 @@ pub(crate) enum Counter {
|
||||
GlyphPlacements,
|
||||
OutsidePinnedLen,
|
||||
OutsideFrame,
|
||||
OutsideExtent,
|
||||
OutsideRegion,
|
||||
}
|
||||
|
||||
impl Counter {
|
||||
const COUNT: usize = Self::OutsideExtent as usize + 1;
|
||||
const COUNT: usize = Self::OutsideRegion as usize + 1;
|
||||
|
||||
const NAMES: [&'static str; Self::COUNT] = [
|
||||
"updates",
|
||||
@@ -90,7 +90,7 @@ impl Counter {
|
||||
"glyph placements",
|
||||
"reuse outside: the length it was pinned to",
|
||||
"reuse outside: a frame length",
|
||||
"reuse outside: an extent length",
|
||||
"reuse outside: a region length",
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::{
|
||||
pub struct ActiveData {
|
||||
pub id: WidgetId,
|
||||
/// Where its drawing goes, in its region node's coordinates.
|
||||
pub extent: UiRegion,
|
||||
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,
|
||||
@@ -29,7 +29,7 @@ pub struct ActiveData {
|
||||
/// The box it was asked in, in the parent's region-node coordinates: the
|
||||
/// box its drawing was made in and the one its contract is about. Its
|
||||
/// drawing is placed elsewhere by re-expression, never by asking again.
|
||||
pub part: UiRegion,
|
||||
pub region: UiRegion,
|
||||
/// The measured answer and its dependencies. A hint-only dependency or
|
||||
/// a widget first encountered during placement has no measurement yet.
|
||||
pub answer: Option<(Size, LayoutHolds)>,
|
||||
@@ -40,8 +40,8 @@ pub struct ActiveData {
|
||||
pub re_asked: bool,
|
||||
/// What the widget reported, in window-unit lengths.
|
||||
pub size: Size,
|
||||
/// The window and extent reads that this drawing holds for, and the
|
||||
/// frame and box it pinned.
|
||||
/// The window and region reads that this drawing holds for, and the
|
||||
/// frame and region it pinned.
|
||||
pub holds: LayoutHolds,
|
||||
pub drawn: bool,
|
||||
pub parent: Option<WidgetId>,
|
||||
@@ -51,7 +51,7 @@ pub struct ActiveData {
|
||||
pub depth: usize,
|
||||
pub textures: Vec<TextureHandle>,
|
||||
/// Its primitives, each keeping the box it was written in -- in this
|
||||
/// widget's extent coordinates, which is what a move recomposes from.
|
||||
/// widget's placement coordinates, which is what a move recomposes from.
|
||||
pub primitives: Vec<RetainedPrimitive>,
|
||||
/// An owned mask holds one reference independently of its primitives.
|
||||
pub mask_region: Option<UiRegion>,
|
||||
@@ -68,8 +68,8 @@ pub struct ActiveData {
|
||||
/// Its alignment when it was last drawn, which a change to the property
|
||||
/// is found against.
|
||||
pub own_align: RegionAlign,
|
||||
/// The movable region whose coordinates `extent` uses when this widget
|
||||
/// does not own a region node.
|
||||
/// The movable region whose coordinates its placement is in when this
|
||||
/// widget does not own a region node.
|
||||
pub parent_move: MoveIdx,
|
||||
/// The mask its drawing is clipped to: one it set itself, or the one it
|
||||
/// inherited from whoever drew it.
|
||||
|
||||
+16
-16
@@ -22,34 +22,34 @@ const AXES: [Axis; 2] = [Axis::X, Axis::Y];
|
||||
pub struct LayoutHolds {
|
||||
pub window: [Holds; 2],
|
||||
pub frame_len: [Option<Len>; 2],
|
||||
pub extent: [Holds; 2],
|
||||
pub extent_len: [Option<Len>; 2],
|
||||
pub region: [Holds; 2],
|
||||
pub region_len: [Option<Len>; 2],
|
||||
}
|
||||
|
||||
impl LayoutHolds {
|
||||
pub const ANY: Self = Self {
|
||||
window: [Holds::ANY; 2],
|
||||
frame_len: [None; 2],
|
||||
extent: [Holds::ANY; 2],
|
||||
extent_len: [None; 2],
|
||||
region: [Holds::ANY; 2],
|
||||
region_len: [None; 2],
|
||||
};
|
||||
|
||||
pub fn and(self, other: Self) -> Self {
|
||||
let mut result = Self::ANY;
|
||||
for n in 0..2 {
|
||||
result.window[n] = self.window[n].and(other.window[n]);
|
||||
result.extent[n] = self.extent[n].and(other.extent[n]);
|
||||
result.region[n] = self.region[n].and(other.region[n]);
|
||||
debug_assert!(
|
||||
self.extent_len[n].is_none()
|
||||
|| other.extent_len[n].is_none()
|
||||
|| self.extent_len[n] == other.extent_len[n]
|
||||
self.region_len[n].is_none()
|
||||
|| other.region_len[n].is_none()
|
||||
|| 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]
|
||||
);
|
||||
result.extent_len[n] = self.extent_len[n].or(other.extent_len[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
|
||||
@@ -59,21 +59,21 @@ impl LayoutHolds {
|
||||
(0..2).all(|n| {
|
||||
self.window[n].lo <= other.window[n].lo
|
||||
&& self.window[n].hi >= other.window[n].hi
|
||||
&& self.extent[n].lo <= other.extent[n].lo
|
||||
&& self.extent[n].hi >= other.extent[n].hi
|
||||
&& self.extent_len[n].is_none_or(|len| other.extent_len[n] == Some(len))
|
||||
&& 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))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn contains(self, window: PxVec2, frame: UiVec2, extent: UiRegion) -> bool {
|
||||
pub fn contains(self, window: PxVec2, frame: UiVec2, region: UiRegion) -> bool {
|
||||
AXES.into_iter().all(|axis| {
|
||||
let n = axis as usize;
|
||||
let len = extent.axis(axis).len();
|
||||
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.extent[n].contains(len.to_px(window.axis(axis)))
|
||||
&& self.extent_len[n].is_none_or(|pinned| pinned == len)
|
||||
&& self.region[n].contains(len.to_px(window.axis(axis)))
|
||||
&& self.region_len[n].is_none_or(|pinned| pinned == len)
|
||||
})
|
||||
}
|
||||
}
|
||||
+59
-64
@@ -22,12 +22,9 @@ pub struct Painter<'a> {
|
||||
/// 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,
|
||||
/// Where this widget's drawing goes, in its region node's coordinates.
|
||||
pub(super) extent: UiRegion,
|
||||
/// The extent's symbolic length where this draw read it, which makes the
|
||||
/// drawing one that holds for that length alone -- the way reading a
|
||||
/// length in pixels makes it hold for that number of pixels.
|
||||
pub(super) extent_len: [Option<Len>; 2],
|
||||
/// 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,
|
||||
/// The window in pixels. Frames and boxes become pixels against this one
|
||||
/// unit, regardless of region-node boundaries.
|
||||
pub(super) window: PxVec2,
|
||||
@@ -42,14 +39,12 @@ pub struct Painter<'a> {
|
||||
pub(super) children: Vec<WidgetId>,
|
||||
/// The children whose size this widget read while drawing.
|
||||
pub(super) size_deps: Vec<WidgetId>,
|
||||
/// What this draw itself read of the window in pixels, per axis: every
|
||||
/// window until it reads one, then that one, unless it says otherwise.
|
||||
pub(super) window_own: [Holds; 2],
|
||||
/// Its frame's symbolic length where this draw read it, which makes the
|
||||
/// drawing one that holds for that frame alone.
|
||||
pub(super) frame_own_len: [Option<Len>; 2],
|
||||
/// The window reads' equivalent for its own box.
|
||||
pub(super) extent_own: [Holds; 2],
|
||||
/// 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
|
||||
/// region length it read symbolically, each of which makes the drawing
|
||||
/// hold for that length alone.
|
||||
pub(super) own: LayoutHolds,
|
||||
/// What each child's drawing depends on. Asking a child again replaces
|
||||
/// its drawing, so it replaces this too rather than narrowing it.
|
||||
pub(super) under: Vec<(WidgetId, LayoutHolds)>,
|
||||
@@ -75,10 +70,10 @@ impl<'a> Painter<'a> {
|
||||
self.write_resolved(kind, primitive, region, self.resolve(region));
|
||||
}
|
||||
|
||||
/// A box in this widget's extent coordinates, composed into its region
|
||||
/// node's coordinates.
|
||||
/// A box in this widget's region, composed into its region node's
|
||||
/// coordinates.
|
||||
fn resolve(&self, region: UiRegion) -> UiRegion {
|
||||
region.within(&self.extent)
|
||||
region.within(&self.region)
|
||||
}
|
||||
|
||||
fn write_resolved<P: Primitive>(
|
||||
@@ -182,12 +177,12 @@ 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, extent) =
|
||||
frame_and_extent(self.extent, self.frame, place, narrow, declared, align);
|
||||
let (frame, region) =
|
||||
frame_and_region(self.region, self.frame, place, narrow, declared, align);
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
if region_node {
|
||||
diag::bump(Counter::RegionNodeDraws);
|
||||
diag::region_node(id.id(), self.id, extent);
|
||||
diag::region_node(id.id(), self.id, region);
|
||||
}
|
||||
// A child listed twice would be moved twice.
|
||||
let re_asked = self.children.contains(&id.id());
|
||||
@@ -205,7 +200,7 @@ impl<'a> Painter<'a> {
|
||||
region_node,
|
||||
mask: self.mask,
|
||||
frame,
|
||||
part: extent,
|
||||
region,
|
||||
placed: place,
|
||||
asked: place,
|
||||
narrow,
|
||||
@@ -215,8 +210,8 @@ impl<'a> Painter<'a> {
|
||||
None,
|
||||
self.rsc,
|
||||
);
|
||||
let holds = self.in_parent(holds, extent, place, narrow, declared);
|
||||
let answer_holds = self.in_parent(answer_holds, extent, place, narrow, declared);
|
||||
let holds = self.in_parent(holds, region, place, narrow, declared);
|
||||
let answer_holds = self.in_parent(answer_holds, region, place, narrow, declared);
|
||||
match self.under.iter_mut().find(|(child, _)| *child == id.id()) {
|
||||
Some((_, kept)) => *kept = holds,
|
||||
None => self.under.push((id.id(), holds)),
|
||||
@@ -256,7 +251,7 @@ impl<'a> Painter<'a> {
|
||||
fn placing(&self) -> Placing {
|
||||
Placing {
|
||||
id: self.id,
|
||||
extent: self.extent,
|
||||
region: self.region,
|
||||
frame: self.frame,
|
||||
window: self.window,
|
||||
depth: self.depth,
|
||||
@@ -303,7 +298,7 @@ impl<'a> Painter<'a> {
|
||||
// the child's own: resolved against a frame of pixels, none is
|
||||
// left to see it by.
|
||||
if hint.rel != Rel::ZERO {
|
||||
self.frame_own_len[axis as usize] = Some(frame);
|
||||
self.own.frame_len[axis as usize] = Some(frame);
|
||||
}
|
||||
}
|
||||
resolved
|
||||
@@ -327,11 +322,11 @@ impl<'a> Painter<'a> {
|
||||
ui.text.render(buffer, attrs, width)
|
||||
}
|
||||
|
||||
/// Writes glyphs in the selected frame or extent coordinates.
|
||||
/// Writes glyphs in the selected frame 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.
|
||||
// Only the shared origin needs composing through the extent.
|
||||
// Only the shared origin needs composing through the region.
|
||||
let resolved = self.resolve(origin);
|
||||
let kind = self.rsc.ui_mut().primitives.kind::<GlyphPrimitive>();
|
||||
for glyph in text.glyphs.iter() {
|
||||
@@ -368,9 +363,9 @@ impl<'a> Painter<'a> {
|
||||
/// starts, which is what lets a container move without being drawn
|
||||
/// again. One axis at a time, because a container that divides one axis
|
||||
/// holds for any length of the other.
|
||||
pub fn extent_len(&mut self, axis: Axis) -> Len {
|
||||
let len = self.extent.axis(axis).len();
|
||||
self.extent_len[axis as usize] = Some(len);
|
||||
pub fn region_len(&mut self, axis: Axis) -> Len {
|
||||
let len = self.region.axis(axis).len();
|
||||
self.own.region_len[axis as usize] = Some(len);
|
||||
len
|
||||
}
|
||||
|
||||
@@ -378,10 +373,10 @@ impl<'a> Painter<'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::extent_len`] pins it to the box.
|
||||
/// 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.frame_own_len[axis as usize] = Some(len);
|
||||
self.own.frame_len[axis as usize] = Some(len);
|
||||
len
|
||||
}
|
||||
|
||||
@@ -419,13 +414,13 @@ impl<'a> Painter<'a> {
|
||||
/// One axis of this widget's own box in pixels. Prefer this to
|
||||
/// [`Self::px_size`] when the other axis cannot affect the drawing.
|
||||
pub fn px_len(&mut self, axis: Axis) -> Px {
|
||||
let part = self.extent.axis(axis).len();
|
||||
let len = part.to_px(self.window.axis(axis));
|
||||
let own = &mut self.extent_own[axis as usize];
|
||||
let len = self.region.axis(axis).len();
|
||||
let px = len.to_px(self.window.axis(axis));
|
||||
let own = &mut self.own.region[axis as usize];
|
||||
if *own == Holds::ANY {
|
||||
*own = Holds::at(len);
|
||||
*own = Holds::at(px);
|
||||
}
|
||||
len
|
||||
px
|
||||
}
|
||||
|
||||
/// The lengths of this widget's own box on `axis` that what it is drawing
|
||||
@@ -433,15 +428,15 @@ impl<'a> Painter<'a> {
|
||||
/// of the box, and the same reported size. A widget that read its length
|
||||
/// in pixels holds for that one alone until it says otherwise.
|
||||
pub fn holds(&mut self, axis: Axis, holds: impl Into<Holds>) {
|
||||
let part = self.extent.axis(axis).len();
|
||||
let len = self.region.axis(axis).len();
|
||||
let holds = holds.into();
|
||||
debug_assert!(
|
||||
holds.contains(part.to_px(self.window.axis(axis))),
|
||||
holds.contains(len.to_px(self.window.axis(axis))),
|
||||
"'{}' ({:?}) says its drawing holds for lengths that leave out its own box",
|
||||
self.label(),
|
||||
self.id
|
||||
);
|
||||
self.extent_own[axis as usize] = holds;
|
||||
self.own.region[axis as usize] = holds;
|
||||
}
|
||||
|
||||
/// A window length in pixels, which is what every length in layout is
|
||||
@@ -451,7 +446,7 @@ impl<'a> Painter<'a> {
|
||||
pub fn to_px(&mut self, len: Len, axis: Axis) -> Px {
|
||||
let window = self.window.axis(axis);
|
||||
if len.rel != Rel::ZERO {
|
||||
let own = &mut self.window_own[axis as usize];
|
||||
let own = &mut self.own.window[axis as usize];
|
||||
if *own == Holds::ANY {
|
||||
*own = Holds::at(window);
|
||||
}
|
||||
@@ -471,7 +466,7 @@ impl<'a> Painter<'a> {
|
||||
self.label(),
|
||||
self.id
|
||||
);
|
||||
self.window_own[axis as usize] = holds;
|
||||
self.own.window[axis as usize] = holds;
|
||||
}
|
||||
|
||||
pub fn text_data(&mut self) -> &mut TextData {
|
||||
@@ -568,7 +563,7 @@ impl Painter<'_> {
|
||||
/// is what reached the child; where only pixels did, no length of this
|
||||
/// frame can change the child's and the pin stops here.
|
||||
///
|
||||
/// Extent validity maps back through the part of this widget's box,
|
||||
/// 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
|
||||
@@ -577,7 +572,7 @@ impl Painter<'_> {
|
||||
fn in_parent(
|
||||
&self,
|
||||
holds: LayoutHolds,
|
||||
extent: UiRegion,
|
||||
region: UiRegion,
|
||||
place: [Place; 2],
|
||||
narrow: [Option<Len>; 2],
|
||||
declared: [Option<LayoutLen>; 2],
|
||||
@@ -600,8 +595,8 @@ impl Painter<'_> {
|
||||
// wherever the part is the whole of it, and pins the same
|
||||
// way.
|
||||
(Part::All, false) => {
|
||||
result.extent[n] = holds.extent[n];
|
||||
result.extent_len[n] = holds.extent_len[n];
|
||||
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
|
||||
@@ -612,10 +607,10 @@ impl Painter<'_> {
|
||||
// widget's own length.
|
||||
(Part::Of(span), false) => {
|
||||
let part_len = span.len();
|
||||
result.extent[n] = holds.extent[n].through(part_len);
|
||||
result.extent_len[n] = holds.extent_len[n].map(|pinned| match part_len.rel {
|
||||
result.region[n] = holds.region[n].through(part_len);
|
||||
result.region_len[n] = holds.region_len[n].map(|pinned| match part_len.rel {
|
||||
Rel::ONE => pinned - Len::from_parts(Rel::ZERO, part_len.px),
|
||||
_ => self.extent.axis(axis).len(),
|
||||
_ => self.region.axis(axis).len(),
|
||||
});
|
||||
}
|
||||
// Its box is a length this widget decided, from its own
|
||||
@@ -624,7 +619,7 @@ impl Painter<'_> {
|
||||
// on the window and none of it on that box.
|
||||
_ => {
|
||||
result.window[n] =
|
||||
result.window[n].and(holds.extent[n].through(extent.axis(axis).len()));
|
||||
result.window[n].and(holds.region[n].through(region.axis(axis).len()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -672,14 +667,14 @@ pub(crate) fn fills(reported: LayoutLen, declared: Option<LayoutLen>, decided: b
|
||||
/// 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.
|
||||
pub(crate) fn placed_extent(
|
||||
part: UiRegion,
|
||||
pub(crate) fn placement(
|
||||
region: UiRegion,
|
||||
size: Size,
|
||||
declared: [Option<LayoutLen>; 2],
|
||||
fill: [bool; 2],
|
||||
align: RegionAlign,
|
||||
) -> UiRegion {
|
||||
let mut placed = part;
|
||||
let mut placed = region;
|
||||
for axis in AXES {
|
||||
let n = axis as usize;
|
||||
let reported = size.axis(axis);
|
||||
@@ -705,7 +700,7 @@ pub(crate) fn placed_extent(
|
||||
/// 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_extent(
|
||||
pub(crate) fn frame_and_region(
|
||||
own: UiRegion,
|
||||
parent_frame: UiVec2,
|
||||
place: [Place; 2],
|
||||
@@ -713,9 +708,9 @@ pub(crate) fn frame_and_extent(
|
||||
declared: [Option<LayoutLen>; 2],
|
||||
align: RegionAlign,
|
||||
) -> (UiVec2, UiRegion) {
|
||||
let part = part_of(own, place, align);
|
||||
let given = region_of(own, place, align);
|
||||
let mut frame = parent_frame;
|
||||
let mut extent = part;
|
||||
let mut region = given;
|
||||
for axis in AXES {
|
||||
let n = axis as usize;
|
||||
let sized = match place[n].part() {
|
||||
@@ -730,22 +725,22 @@ pub(crate) fn frame_and_extent(
|
||||
.unwrap_or(base);
|
||||
*frame.axis_mut(axis) = len;
|
||||
if declared[n].is_some() {
|
||||
let slot = part.axis(axis);
|
||||
let slot = given.axis(axis);
|
||||
let start = slot.start + (slot.len() - len).scale(align.axis(axis).rel());
|
||||
*extent.axis_mut(axis) = UiSpan::new(start, start + len);
|
||||
*region.axis_mut(axis) = UiSpan::new(start, start + len);
|
||||
}
|
||||
}
|
||||
(frame, extent)
|
||||
(frame, region)
|
||||
}
|
||||
|
||||
/// The part of a widget's own box a `place` names, in the coordinates that
|
||||
/// box is in.
|
||||
fn part_of(extent: UiRegion, place: [Place; 2], align: RegionAlign) -> UiRegion {
|
||||
let mut part = extent;
|
||||
fn region_of(own: UiRegion, place: [Place; 2], align: RegionAlign) -> UiRegion {
|
||||
let mut region = own;
|
||||
for axis in AXES {
|
||||
*part.axis_mut(axis) = place[axis as usize]
|
||||
*region.axis_mut(axis) = place[axis as usize]
|
||||
.part()
|
||||
.of(*extent.axis(axis), align.axis(axis));
|
||||
.of(*own.axis(axis), align.axis(axis));
|
||||
}
|
||||
part
|
||||
region
|
||||
}
|
||||
@@ -27,14 +27,14 @@ pub enum Part {
|
||||
}
|
||||
|
||||
impl Part {
|
||||
/// Where it lands in the coordinates `extent` is in.
|
||||
pub(crate) fn of(self, extent: UiSpan, align: AxisAlign) -> UiSpan {
|
||||
/// Where it lands in the coordinates `own` is in.
|
||||
pub(crate) fn of(self, own: UiSpan, align: AxisAlign) -> UiSpan {
|
||||
match self {
|
||||
Self::All => extent,
|
||||
Self::From(span) => UiSpan::new(extent.start + span.start, extent.start + span.end),
|
||||
Self::Of(span) => span.within(&extent),
|
||||
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) => {
|
||||
let start = extent.start + (extent.len() - len).scale(align.rel());
|
||||
let start = own.start + (own.len() - len).scale(align.rel());
|
||||
UiSpan::new(start, start + len)
|
||||
}
|
||||
}
|
||||
|
||||
+84
-94
@@ -1,10 +1,10 @@
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
use crate::layout_diagnostics::{self as diag, Counter, ReuseOutcome, TimerKind};
|
||||
use crate::ui::painter::{declared_lens, frame_and_extent, placed_extent};
|
||||
use crate::ui::painter::{declared_lens, frame_and_region, placement};
|
||||
use crate::{
|
||||
ActiveData, Axis, DrawLayers, Holds, IdLike, LayoutHolds, LayoutLen, Len, MaskIdx, MoveIdx,
|
||||
Moves, Painter, Part, PixelRegion, Place, PxVec2, Rel, Size, StrongWidget, UiRegion, UiRsc,
|
||||
UiSpan, UiVec2, Weight, WidgetId, Widgets,
|
||||
ActiveData, Axis, DrawLayers, IdLike, LayoutHolds, LayoutLen, Len, MaskIdx, MoveIdx, Moves,
|
||||
Painter, Part, PixelRegion, Place, PxVec2, Rel, Size, StrongWidget, UiRegion, UiRsc, UiSpan,
|
||||
UiVec2, Weight, WidgetId, Widgets,
|
||||
util::{HashMap, Vec2},
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ pub(super) struct DrawInfo {
|
||||
pub frame: UiVec2,
|
||||
/// The box the widget is asked in, in its parent region node's
|
||||
/// coordinates.
|
||||
pub part: UiRegion,
|
||||
pub region: UiRegion,
|
||||
/// Where the widget is put, and where it was asked, as parts of the
|
||||
/// parent's box. See [`Place`]. The two are one ask's place until the
|
||||
/// parent puts the answer somewhere else.
|
||||
@@ -52,7 +52,7 @@ impl DrawInfo {
|
||||
/// drawing is in, and what else one ask of a child is decided from.
|
||||
pub(super) struct Placing {
|
||||
pub id: WidgetId,
|
||||
pub extent: UiRegion,
|
||||
pub region: UiRegion,
|
||||
pub frame: UiVec2,
|
||||
pub window: PxVec2,
|
||||
pub depth: usize,
|
||||
@@ -125,8 +125,8 @@ impl UiRenderState {
|
||||
// it will ask either again.
|
||||
let answer = active
|
||||
.answer
|
||||
.is_some_and(|(_, holds)| holds.contains(size, active.frame, active.part));
|
||||
answer && active.holds.contains(size, active.frame, active.part)
|
||||
.is_some_and(|(_, holds)| holds.contains(size, active.frame, active.region));
|
||||
answer && active.holds.contains(size, active.frame, active.region)
|
||||
});
|
||||
if !stands {
|
||||
widgets.needs_redraw.insert(root);
|
||||
@@ -135,7 +135,7 @@ 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, extent: UiRegion) -> DrawInfo {
|
||||
fn root_info(&self, frame: UiVec2, region: UiRegion) -> DrawInfo {
|
||||
let px = frame.to_px(self.output_size);
|
||||
DrawInfo {
|
||||
layer: 0,
|
||||
@@ -145,7 +145,7 @@ impl UiRenderState {
|
||||
region_node: false,
|
||||
mask: MaskIdx::NONE,
|
||||
frame,
|
||||
part: extent,
|
||||
region,
|
||||
placed: [Place::Within(Part::All); 2],
|
||||
asked: [Place::Within(Part::All); 2],
|
||||
narrow: [None; 2],
|
||||
@@ -196,8 +196,8 @@ impl UiRenderState {
|
||||
let _layout = diag::timer(TimerKind::FullLayout);
|
||||
self.clear(rsc);
|
||||
if let Some(id) = root {
|
||||
let (frame, extent) = Self::root_layout(id.id(), rsc.widgets());
|
||||
let info = self.root_info(frame, extent);
|
||||
let (frame, region) = Self::root_layout(id.id(), rsc.widgets());
|
||||
let info = self.root_info(frame, region);
|
||||
self.draw_inner(id.id(), info, None, rsc);
|
||||
}
|
||||
}
|
||||
@@ -206,7 +206,7 @@ impl UiRenderState {
|
||||
/// 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_extent(
|
||||
frame_and_region(
|
||||
UiRegion::FULL,
|
||||
UiVec2::FULL_SIZE,
|
||||
[Place::Within(Part::All); 2],
|
||||
@@ -227,11 +227,11 @@ impl UiRenderState {
|
||||
.as_ref()
|
||||
.or_else(|| self.active.get(&id))
|
||||
.and_then(|a| a.parent);
|
||||
let part = info.part;
|
||||
let region = info.region;
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
{
|
||||
diag::bump(Counter::DrawRequests);
|
||||
diag::draw_request(id, info.parent, part, info.px, info.region_node);
|
||||
diag::draw_request(id, info.parent, region, info.px, info.region_node);
|
||||
}
|
||||
let align = rsc.widgets().alignment(id);
|
||||
let declared = declared_lens(rsc.widgets(), id);
|
||||
@@ -245,23 +245,24 @@ impl UiRenderState {
|
||||
// an answer is kept only with the drawing that gave it, and both
|
||||
// have to hold for the box asked about.
|
||||
let reused = (!stale)
|
||||
.then(|| self.retained_answer(id, part, info))
|
||||
.then(|| self.retained_answer(id, region, info))
|
||||
.flatten()
|
||||
.and_then(|answer| {
|
||||
let extent = placed_extent(part, answer.0, declared, info.fill(), align);
|
||||
self.try_reuse(id, part, extent, info, rsc).map(|()| answer)
|
||||
let placed = placement(region, answer.0, declared, info.fill(), align);
|
||||
self.try_reuse(id, region, placed, info, rsc)
|
||||
.map(|()| answer)
|
||||
});
|
||||
let answer = reused.unwrap_or_else(|| {
|
||||
if old.is_none() {
|
||||
old = self.remove(id, false, rsc);
|
||||
}
|
||||
let answer = self.draw_at(id, part, info, old.take(), rsc);
|
||||
let answer = self.draw_at(id, region, info, old.take(), rsc);
|
||||
// Where the drawing goes: the part its parent gave it, with the
|
||||
// answer placed inside that part on any axis the parent left
|
||||
// open.
|
||||
let extent = placed_extent(part, answer.0, declared, info.fill(), align);
|
||||
if extent != part {
|
||||
self.relocate(id, extent, info, rsc);
|
||||
let placed = placement(region, answer.0, declared, info.fill(), align);
|
||||
if placed != region {
|
||||
self.relocate(id, placed, info, rsc);
|
||||
}
|
||||
answer
|
||||
});
|
||||
@@ -276,7 +277,7 @@ impl UiRenderState {
|
||||
active.re_asked = info.re_asked;
|
||||
active.answer = Some(answer);
|
||||
active.asked = info.asked;
|
||||
active.part = part;
|
||||
active.region = region;
|
||||
active.placed = info.placed;
|
||||
active.own_align = align;
|
||||
// The previous parent must stop owning the subtree before it can
|
||||
@@ -291,27 +292,27 @@ impl UiRenderState {
|
||||
(answer.0, answer.1, drawing_holds)
|
||||
}
|
||||
|
||||
/// Calls a widget's `draw` and keeps what it drew in `extent` of `frame`.
|
||||
/// Calls a widget's `draw` and keeps what it drew in `region` of `frame`.
|
||||
fn draw_at(
|
||||
&mut self,
|
||||
id: WidgetId,
|
||||
extent: UiRegion,
|
||||
region: UiRegion,
|
||||
info: DrawInfo,
|
||||
old: Option<ActiveData>,
|
||||
rsc: &mut dyn UiRsc,
|
||||
) -> (Size, LayoutHolds) {
|
||||
let frame = info.frame;
|
||||
let (move_idx, extent, retired_move) = match info.region_node {
|
||||
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.
|
||||
true => (
|
||||
self.move_slot(id, info.parent_move, translation(extent)),
|
||||
local_region(extent),
|
||||
self.move_slot(id, info.parent_move, translation(region)),
|
||||
local_region(region),
|
||||
None,
|
||||
),
|
||||
// Keep the old entry alive until every descendant has migrated.
|
||||
// Reusing its index sooner could make an old parent look current.
|
||||
false => (info.parent_move, extent, self.slots.remove(&id)),
|
||||
false => (info.parent_move, region, self.slots.remove(&id)),
|
||||
};
|
||||
let mask_slot = old
|
||||
.as_ref()
|
||||
@@ -324,8 +325,7 @@ impl UiRenderState {
|
||||
let mut painter = Painter {
|
||||
state: self,
|
||||
frame,
|
||||
extent,
|
||||
extent_len: [None; 2],
|
||||
region,
|
||||
window,
|
||||
mask: info.mask,
|
||||
layer: info.layer,
|
||||
@@ -337,10 +337,8 @@ impl UiRenderState {
|
||||
mask_slot,
|
||||
children: Vec::new(),
|
||||
size_deps: Vec::new(),
|
||||
window_own: [Holds::ANY; 2],
|
||||
frame_own_len: [None; 2],
|
||||
own: LayoutHolds::ANY,
|
||||
under: Vec::new(),
|
||||
extent_own: [Holds::ANY; 2],
|
||||
answer_under: LayoutHolds::ANY,
|
||||
depth: info.depth,
|
||||
move_idx,
|
||||
@@ -362,20 +360,17 @@ impl UiRenderState {
|
||||
state: _,
|
||||
rsc: _,
|
||||
frame: _,
|
||||
extent: _,
|
||||
region: _,
|
||||
window: _,
|
||||
mask,
|
||||
textures,
|
||||
primitives,
|
||||
mask_region,
|
||||
mask_slot,
|
||||
extent_own,
|
||||
extent_len,
|
||||
own,
|
||||
answer_under,
|
||||
children,
|
||||
size_deps,
|
||||
window_own,
|
||||
frame_own_len,
|
||||
under,
|
||||
move_idx,
|
||||
layer,
|
||||
@@ -418,7 +413,7 @@ impl UiRenderState {
|
||||
mask == info.mask
|
||||
|| AXES
|
||||
.into_iter()
|
||||
.all(|axis| within_box(size, extent, self.output_size, axis)),
|
||||
.all(|axis| within_box(size, region, self.output_size, axis)),
|
||||
"'{}' ({id:?}) clips to {px:?} and reports {size}",
|
||||
rsc.widgets().label(id),
|
||||
);
|
||||
@@ -444,21 +439,16 @@ impl UiRenderState {
|
||||
.is_some_and(|len| len.rel != Rel::ZERO);
|
||||
match fraction {
|
||||
true => Some(info.frame.axis(axis)),
|
||||
false => frame_own_len[axis as usize],
|
||||
false => own.frame_len[axis as usize],
|
||||
}
|
||||
});
|
||||
let own_holds = LayoutHolds {
|
||||
window: window_own,
|
||||
frame_len,
|
||||
extent: extent_own,
|
||||
extent_len,
|
||||
};
|
||||
let own_holds = LayoutHolds { frame_len, ..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, extent),
|
||||
holds.contains(self.output_size, info.frame, region),
|
||||
"'{}' ({id:?}) drew in {px:?}, outside the ranges it reported: {holds:?}",
|
||||
rsc.widgets().label(id),
|
||||
);
|
||||
@@ -477,7 +467,7 @@ impl UiRenderState {
|
||||
region_node: false,
|
||||
mask,
|
||||
frame: UiVec2::FULL_SIZE,
|
||||
part: UiRegion::FULL,
|
||||
region: UiRegion::FULL,
|
||||
placed: [Place::Within(Part::All); 2],
|
||||
asked: [Place::Within(Part::All); 2],
|
||||
narrow: [None; 2],
|
||||
@@ -492,12 +482,12 @@ impl UiRenderState {
|
||||
|
||||
let active = ActiveData {
|
||||
id,
|
||||
extent,
|
||||
placement: region,
|
||||
frame: info.frame,
|
||||
narrow: info.narrow,
|
||||
placed: info.placed,
|
||||
asked: info.asked,
|
||||
part: extent,
|
||||
region,
|
||||
// Whoever asked writes the answer.
|
||||
answer: None,
|
||||
re_asked: info.re_asked,
|
||||
@@ -551,7 +541,7 @@ impl UiRenderState {
|
||||
fn retained_answer(
|
||||
&self,
|
||||
id: WidgetId,
|
||||
part: UiRegion,
|
||||
region: UiRegion,
|
||||
info: DrawInfo,
|
||||
) -> Option<(Size, LayoutHolds)> {
|
||||
let active = self.active.get(&id)?;
|
||||
@@ -565,17 +555,17 @@ impl UiRenderState {
|
||||
let answer = active.answer?;
|
||||
answer
|
||||
.1
|
||||
.contains(self.output_size, info.frame, part)
|
||||
.contains(self.output_size, info.frame, region)
|
||||
.then_some(answer)
|
||||
}
|
||||
|
||||
/// Keeps the retained drawing if its contract holds for `part`, the box
|
||||
/// asked about, and puts it at `extent`, where the answer places it.
|
||||
/// asked about, and puts it at `placed`, where the answer places it.
|
||||
fn try_reuse(
|
||||
&mut self,
|
||||
id: WidgetId,
|
||||
part: UiRegion,
|
||||
extent: UiRegion,
|
||||
region: UiRegion,
|
||||
placed: UiRegion,
|
||||
info: DrawInfo,
|
||||
rsc: &mut dyn UiRsc,
|
||||
) -> Option<()> {
|
||||
@@ -630,7 +620,7 @@ 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, part) {
|
||||
if !active.holds.contains(self.output_size, info.frame, region) {
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
{
|
||||
// Which of the three said no, so a frame that redraws more
|
||||
@@ -639,7 +629,7 @@ impl UiRenderState {
|
||||
let holds = active.holds;
|
||||
for axis in AXES {
|
||||
let n = axis as usize;
|
||||
if holds.extent_len[n].is_some_and(|pinned| pinned != part.axis(axis).len()) {
|
||||
if holds.region_len[n].is_some_and(|pinned| pinned != region.axis(axis).len()) {
|
||||
diag::bump(Counter::OutsidePinnedLen);
|
||||
}
|
||||
if !holds.window[n].contains(self.output_size.axis(axis))
|
||||
@@ -647,10 +637,10 @@ impl UiRenderState {
|
||||
{
|
||||
diag::bump(Counter::OutsideFrame);
|
||||
}
|
||||
if !holds.extent[n]
|
||||
.contains(part.axis(axis).len().to_px(self.output_size.axis(axis)))
|
||||
if !holds.region[n]
|
||||
.contains(region.axis(axis).len().to_px(self.output_size.axis(axis)))
|
||||
{
|
||||
diag::bump(Counter::OutsideExtent);
|
||||
diag::bump(Counter::OutsideRegion);
|
||||
}
|
||||
}
|
||||
diag::bump(Counter::ReuseOutside);
|
||||
@@ -658,14 +648,14 @@ impl UiRenderState {
|
||||
}
|
||||
return None;
|
||||
}
|
||||
self.relocate(id, extent, info, rsc);
|
||||
self.relocate(id, placed, info, rsc);
|
||||
Some(())
|
||||
}
|
||||
|
||||
/// Puts a retained drawing where its parent now has it, without drawing:
|
||||
/// a widget with a node of its own writes that node's translation, and
|
||||
/// one without re-expresses its own drawing and everything inside it.
|
||||
fn relocate(&mut self, id: WidgetId, extent: UiRegion, info: DrawInfo, rsc: &mut dyn UiRsc) {
|
||||
fn relocate(&mut self, id: WidgetId, placed: UiRegion, info: DrawInfo, rsc: &mut dyn UiRsc) {
|
||||
let active = &self.active[&id];
|
||||
debug_assert!(
|
||||
!rsc.widgets().needs_redraw.contains(&id),
|
||||
@@ -674,13 +664,13 @@ impl UiRenderState {
|
||||
);
|
||||
let has_region_node = active.move_idx != active.parent_move;
|
||||
let local = match has_region_node {
|
||||
true => local_region(extent),
|
||||
false => extent,
|
||||
true => local_region(placed),
|
||||
false => placed,
|
||||
};
|
||||
let moved = active.extent != local;
|
||||
let moved = active.placement != local;
|
||||
let slot = active.move_idx;
|
||||
if has_region_node {
|
||||
self.moves.set(slot, translation(extent));
|
||||
self.moves.set(slot, translation(placed));
|
||||
}
|
||||
if moved {
|
||||
self.reposition(id, local, info, rsc);
|
||||
@@ -728,9 +718,9 @@ impl UiRenderState {
|
||||
rsc: &mut dyn UiRsc,
|
||||
) {
|
||||
let active = &self.active[&child];
|
||||
let (frame, part) = Self::ask_again(active, at, place);
|
||||
let extent = placed_extent(
|
||||
part,
|
||||
let (frame, region) = Self::ask_again(active, at, place);
|
||||
let placed = placement(
|
||||
region,
|
||||
active.measured().unwrap_or(active.size),
|
||||
active.declared,
|
||||
place.map(Place::fills),
|
||||
@@ -744,14 +734,14 @@ impl UiRenderState {
|
||||
region_node: active.move_idx != active.parent_move,
|
||||
mask: at.mask,
|
||||
frame,
|
||||
part,
|
||||
region,
|
||||
placed: place,
|
||||
asked: active.asked,
|
||||
narrow: active.narrow,
|
||||
re_asked: active.re_asked,
|
||||
px: frame.to_px(at.window),
|
||||
};
|
||||
self.relocate(child, extent, info, rsc);
|
||||
self.relocate(child, placed, info, rsc);
|
||||
}
|
||||
|
||||
/// The frame and the box a widget already drawn is given at `place` of
|
||||
@@ -759,8 +749,8 @@ impl UiRenderState {
|
||||
/// it declared are its own record's, so both are resolved against that
|
||||
/// parent's frame again exactly as the first ask resolved them.
|
||||
fn ask_again(active: &ActiveData, at: &Placing, place: [Place; 2]) -> (UiVec2, UiRegion) {
|
||||
frame_and_extent(
|
||||
at.extent,
|
||||
frame_and_region(
|
||||
at.region,
|
||||
at.frame,
|
||||
place,
|
||||
active.narrow,
|
||||
@@ -773,19 +763,19 @@ impl UiRenderState {
|
||||
/// is placed as a part of that box, so each one's new box is its retained
|
||||
/// part re-added to the new start -- and a child whose own box then did
|
||||
/// not change is not touched at all.
|
||||
fn reposition(&mut self, id: WidgetId, extent: UiRegion, info: DrawInfo, rsc: &mut dyn UiRsc) {
|
||||
fn reposition(&mut self, id: WidgetId, placed: UiRegion, info: DrawInfo, rsc: &mut dyn UiRsc) {
|
||||
let active = self.active.get_mut(&id).unwrap();
|
||||
active.extent = extent;
|
||||
active.placement = placed;
|
||||
for primitive in &active.primitives {
|
||||
let handle = &primitive.handle;
|
||||
*self.layers[handle.layer].region_mut(handle) = primitive.region.within(&extent);
|
||||
*self.layers[handle.layer].region_mut(handle) = primitive.region.within(&placed);
|
||||
}
|
||||
if let Some(mask_region) = active.mask_region {
|
||||
rsc.ui_mut().masks.get_mut(active.mask).region = mask_region.within(&extent);
|
||||
rsc.ui_mut().masks.get_mut(active.mask).region = mask_region.within(&placed);
|
||||
}
|
||||
let at = Placing {
|
||||
id,
|
||||
extent,
|
||||
region: placed,
|
||||
frame: info.frame,
|
||||
window: self.output_size,
|
||||
depth: info.depth,
|
||||
@@ -890,12 +880,12 @@ impl UiRenderState {
|
||||
id,
|
||||
ActiveData {
|
||||
id,
|
||||
extent: UiRegion::FULL,
|
||||
placement: UiRegion::FULL,
|
||||
frame: UiVec2::FULL_SIZE,
|
||||
narrow: [None; 2],
|
||||
placed: [Place::Within(Part::All); 2],
|
||||
asked: [Place::Within(Part::All); 2],
|
||||
part: UiRegion::FULL,
|
||||
region: UiRegion::FULL,
|
||||
answer: None,
|
||||
re_asked: false,
|
||||
size,
|
||||
@@ -1080,7 +1070,7 @@ impl UiRenderState {
|
||||
let active = self.active.get(&id.id())?;
|
||||
active.drawn.then(|| {
|
||||
self.moves
|
||||
.resolve(active.move_idx, active.extent)
|
||||
.resolve(active.move_idx, active.placement)
|
||||
.to_px(self.output_size)
|
||||
})
|
||||
}
|
||||
@@ -1122,10 +1112,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, extent) = Self::root_layout(id, rsc.widgets());
|
||||
let (frame, region) = Self::root_layout(id, rsc.widgets());
|
||||
let info = DrawInfo {
|
||||
mask: active.parent_mask,
|
||||
..self.root_info(frame, extent)
|
||||
..self.root_info(frame, region)
|
||||
};
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
diag::bump(Counter::LocalRedraws);
|
||||
@@ -1139,8 +1129,8 @@ impl UiRenderState {
|
||||
// draw ran in and what its children's parts are of. Where the
|
||||
// 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].part);
|
||||
let (frame, part) = Self::ask_again(active, &parent_at, active.asked);
|
||||
let parent_at = self.placing_of(parent, self.active[&parent].region);
|
||||
let (frame, region) = Self::ask_again(active, &parent_at, active.asked);
|
||||
let info = DrawInfo {
|
||||
layer: active.layer,
|
||||
parent: active.parent,
|
||||
@@ -1149,7 +1139,7 @@ impl UiRenderState {
|
||||
region_node: rsc.widgets().is_region_node(id),
|
||||
mask: active.parent_mask,
|
||||
frame,
|
||||
part,
|
||||
region,
|
||||
placed: active.asked,
|
||||
asked: active.asked,
|
||||
narrow: active.narrow,
|
||||
@@ -1171,7 +1161,7 @@ impl UiRenderState {
|
||||
active.answer = was_answer;
|
||||
}
|
||||
if active.holds.covers(was_holds)
|
||||
&& was_holds.contains(self.output_size, active.frame, active.extent)
|
||||
&& was_holds.contains(self.output_size, active.frame, active.placement)
|
||||
{
|
||||
active.holds = was_holds;
|
||||
}
|
||||
@@ -1188,20 +1178,20 @@ impl UiRenderState {
|
||||
// The answer stands, so where the parent put it stands: the
|
||||
// fresh drawing goes back there -- the same place, of the box
|
||||
// the parent's answer chose rather than the one it was asked in.
|
||||
let at = self.placing_of(parent, self.active[&parent].extent);
|
||||
let at = self.placing_of(parent, self.active[&parent].placement);
|
||||
self.place_in(id, &at, was_place, rsc);
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
/// A drawn widget as the thing its children are placed within, with
|
||||
/// `extent` as the box their parts are of: the box it was asked in for
|
||||
/// `region` as the box their parts are of: the box it was asked in for
|
||||
/// asking one of them again, the box its answer chose for placing one.
|
||||
fn placing_of(&self, id: WidgetId, extent: UiRegion) -> Placing {
|
||||
fn placing_of(&self, id: WidgetId, region: UiRegion) -> Placing {
|
||||
let active = &self.active[&id];
|
||||
Placing {
|
||||
id,
|
||||
extent,
|
||||
region,
|
||||
frame: active.frame,
|
||||
window: self.output_size,
|
||||
depth: active.depth,
|
||||
@@ -1215,11 +1205,11 @@ impl UiRenderState {
|
||||
/// Both are lengths of the window, so the comparison is in its pixels. A
|
||||
/// share is a length only to whoever divides one, so it is not a claim about
|
||||
/// this box and cannot exceed it.
|
||||
fn within_box(size: Size, extent: UiRegion, window: PxVec2, axis: Axis) -> bool {
|
||||
fn within_box(size: Size, region: UiRegion, window: PxVec2, axis: Axis) -> bool {
|
||||
let len = size.axis(axis);
|
||||
let window = window.axis(axis);
|
||||
len.leftover != Weight::ZERO
|
||||
|| Len::from_parts(len.rel, len.px).to_px(window) <= extent.axis(axis).len().to_px(window)
|
||||
|| Len::from_parts(len.rel, len.px).to_px(window) <= region.axis(axis).len().to_px(window)
|
||||
}
|
||||
|
||||
/// A box in a fresh region node keeps its window-unit length and starts at
|
||||
|
||||
Reference in new issue
Block a user