Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62a16b5608 | ||
|
|
34cafb6edc |
No files matched your search
@@ -18,6 +18,9 @@ pub struct ActiveData {
|
||||
/// The original frame in its parent widget's coordinates. Recomposition
|
||||
/// and pixel-length evaluation both follow this chain.
|
||||
pub given_region: UiRegion,
|
||||
/// The frame it was first asked in, in the same coordinates: the offer's
|
||||
/// frame, which its parent's placing draw may since have narrowed.
|
||||
pub offer_region: UiRegion,
|
||||
/// The lengths of the box its parent first asked about it in, as
|
||||
/// lengths of the box the parent was itself offered. Any later box it
|
||||
/// was given was decided knowing its answer, so this is the question
|
||||
@@ -43,8 +46,8 @@ pub struct ActiveData {
|
||||
pub mask_region: Option<DrawRegion>,
|
||||
/// The children whose box is a part of this widget's extent rather than
|
||||
/// of its frame, and which part each was given. Moving the extent
|
||||
/// re-places them, so this widget's drawing does not have to depend on
|
||||
/// where its own drawing sits.
|
||||
/// re-places them through that part, so the drawing need not depend on
|
||||
/// where it sits.
|
||||
pub(crate) extent_children: Vec<(WidgetId, ExtentPlacement)>,
|
||||
pub children: Vec<WidgetId>,
|
||||
/// The children whose size this widget read while drawing.
|
||||
|
||||
+25
-21
@@ -185,12 +185,10 @@ impl<'a> Painter<'a> {
|
||||
/// resolves declared lengths and reports against that frame, then places
|
||||
/// its drawing by its own alignment.
|
||||
///
|
||||
/// `DrawRegion::Extent` gives a part of where this widget's own drawing
|
||||
/// sits instead, which is what a container whose children belong inside
|
||||
/// its drawing rather than inside the box it was offered wants. The
|
||||
/// child's box then follows the extent without this widget's drawing
|
||||
/// depending on where that extent is, so moving it re-places the child
|
||||
/// rather than drawing this widget again.
|
||||
/// `DrawRegion::Extent` gives a part of where this widget's drawing sits
|
||||
/// instead, for a container whose children belong inside that rather than
|
||||
/// inside the box it was offered. The part is what is kept, so moving the
|
||||
/// extent re-places the child rather than drawing this widget again.
|
||||
pub fn widget_within<'s, W: ?Sized>(
|
||||
&'s mut self,
|
||||
id: &'s StrongWidget<W>,
|
||||
@@ -273,6 +271,14 @@ impl<'a> Painter<'a> {
|
||||
.get(&id.id())
|
||||
.map_or(given_len, |a| a.offer_len),
|
||||
};
|
||||
let offer_region = match first_ask {
|
||||
true => local,
|
||||
false => self
|
||||
.state
|
||||
.active
|
||||
.get(&id.id())
|
||||
.map_or(local, |a| a.offer_region),
|
||||
};
|
||||
let offer_placement = if first_ask {
|
||||
placement
|
||||
} else {
|
||||
@@ -297,6 +303,7 @@ impl<'a> Painter<'a> {
|
||||
region_node,
|
||||
mask: self.mask,
|
||||
given_region: local,
|
||||
offer_region,
|
||||
offer_len,
|
||||
offer_placement,
|
||||
px,
|
||||
@@ -322,20 +329,18 @@ impl<'a> Painter<'a> {
|
||||
result.placement = Some(self.placement);
|
||||
}
|
||||
}
|
||||
// Its box is a part of this widget's extent, so both what
|
||||
// it was given and what it took of that are ranges on the
|
||||
// extent and none of them a range on the frame. That is
|
||||
// what lets this widget's drawing move without being made
|
||||
// again: only the part's length reaches the child, and
|
||||
// where the part sits is re-placed rather than redrawn.
|
||||
// Its box is a part of this widget's extent, so what it
|
||||
// holds for is a range on that extent and none of it a
|
||||
// range on the frame. Only the part's length reaches it,
|
||||
// which is what lets the extent move without a redraw.
|
||||
Some(ExtentPlacement::Within(part)) if declared[n].is_none() => {
|
||||
result.extent[n] = holds.frame[n]
|
||||
.and(holds.extent[n].through(chosen))
|
||||
.through(part.axis(axis).len());
|
||||
}
|
||||
// A declared length is a length of this widget's frame
|
||||
// wherever the box it sits in came from, so what the child
|
||||
// holds for is a range on the frame either way.
|
||||
// Its box is a length of this widget's frame: an
|
||||
// ordinary ask, or a declared length, which is that
|
||||
// length wherever the box it sits in came from.
|
||||
_ => {
|
||||
result.frame[n] = holds.frame[n].through(local.axis(axis).len()).and(
|
||||
holds.extent[n]
|
||||
@@ -349,12 +354,10 @@ impl<'a> Painter<'a> {
|
||||
};
|
||||
self.under = self.under.and(in_parent(holds));
|
||||
let mut answer_holds = in_parent(answer_holds);
|
||||
// What it reports is a fraction of the box it was given, and that box
|
||||
// is a part of this widget's extent -- so the same fraction is a
|
||||
// different length once the extent is. Only the report: where the
|
||||
// extent moved without changing what it holds, the drawing under it
|
||||
// is re-placed rather than made again, which is what the extent ask
|
||||
// is for. Pixels come up unchanged and say nothing.
|
||||
// What it reports is a fraction of the box it was given, which is a
|
||||
// part of this widget's extent -- so the same fraction is a different
|
||||
// length once that extent is, and pixels are not. The answer only:
|
||||
// the drawing this holds is re-placed rather than made again.
|
||||
if matches!(extent, Some(ExtentPlacement::Within(_)))
|
||||
&& AXES.into_iter().any(|axis| {
|
||||
declared[axis as usize].is_none() && size.axis(axis).rel != crate::Rel::ZERO
|
||||
@@ -433,6 +436,7 @@ impl<'a> Painter<'a> {
|
||||
self.offered.push(child.id());
|
||||
let active = self.state.active.get_mut(&child.id()).unwrap();
|
||||
active.offer_len = local.size();
|
||||
active.offer_region = local;
|
||||
active.offer_placement = placement;
|
||||
}
|
||||
let placement = UiRegion {
|
||||
|
||||
+53
-27
@@ -24,6 +24,8 @@ pub(super) struct DrawInfo {
|
||||
pub given_region: UiRegion,
|
||||
/// The original offer's lengths relative to the parent's own offer.
|
||||
pub offer_len: UiVec2,
|
||||
/// The offer's frame in the parent widget's coordinates.
|
||||
pub offer_region: UiRegion,
|
||||
pub offer_placement: [Option<UiSpan>; 2],
|
||||
/// This ask's box in pixels, and the offer's: one multiply from the
|
||||
/// parent's own, which is where every pixel length in layout comes from.
|
||||
@@ -70,8 +72,7 @@ pub struct UiRenderState {
|
||||
/// depths does not pick one up again at its own depth.
|
||||
deferred: crate::util::HashSet<WidgetId>,
|
||||
/// What the walk has left to settle, deepest last. Ordered rather than
|
||||
/// searched: the set is scanned once a frame, and every mark made while
|
||||
/// the walk runs puts itself in place.
|
||||
/// searched for, so finding the next one is not a pass over the marks.
|
||||
pending: std::collections::BTreeSet<(usize, WidgetId)>,
|
||||
pub moves: Moves,
|
||||
}
|
||||
@@ -135,6 +136,7 @@ impl UiRenderState {
|
||||
region_node: false,
|
||||
mask: MaskIdx::NONE,
|
||||
given_region: region,
|
||||
offer_region: region,
|
||||
offer_len: UiVec2::FULL_SIZE,
|
||||
offer_placement: [None; 2],
|
||||
px,
|
||||
@@ -275,6 +277,7 @@ impl UiRenderState {
|
||||
// same question again from these.
|
||||
active.region = region;
|
||||
active.given_region = info.given_region;
|
||||
active.offer_region = info.offer_region;
|
||||
active.offer_len = info.offer_len;
|
||||
if info.placement == info.offer_placement && info.px == info.offered_px {
|
||||
active.answer = Some(answer);
|
||||
@@ -479,6 +482,7 @@ impl UiRenderState {
|
||||
region_node: false,
|
||||
mask,
|
||||
given_region: UiRegion::FULL,
|
||||
offer_region: UiRegion::FULL,
|
||||
offer_len: UiVec2::FULL_SIZE,
|
||||
offer_placement: [None; 2],
|
||||
px,
|
||||
@@ -496,6 +500,7 @@ impl UiRenderState {
|
||||
region,
|
||||
placement,
|
||||
given_region: info.given_region,
|
||||
offer_region: info.offer_region,
|
||||
offer_len: info.offer_len,
|
||||
offer_placement: info.offer_placement,
|
||||
// Whoever asked writes the answer, if this was the asking.
|
||||
@@ -725,6 +730,7 @@ impl UiRenderState {
|
||||
let active = self.active.get_mut(&id).unwrap();
|
||||
active.region = region;
|
||||
active.given_region = info.given_region;
|
||||
active.offer_region = info.offer_region;
|
||||
active.offer_len = info.offer_len;
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
{
|
||||
@@ -796,6 +802,7 @@ impl UiRenderState {
|
||||
region_node: active.move_idx != active.parent_move,
|
||||
mask,
|
||||
given_region: child_local,
|
||||
offer_region: active.offer_region,
|
||||
offer_len: active.offer_len,
|
||||
offer_placement: active.offer_placement,
|
||||
px: child_local.size().to_px(info.px),
|
||||
@@ -935,6 +942,7 @@ impl UiRenderState {
|
||||
region: UiRegion::FULL,
|
||||
placement: UiRegion::FULL,
|
||||
given_region: UiRegion::FULL,
|
||||
offer_region: UiRegion::FULL,
|
||||
offer_len: UiVec2::FULL_SIZE,
|
||||
offer_placement: [None; 2],
|
||||
answer: None,
|
||||
@@ -999,20 +1007,29 @@ impl UiRenderState {
|
||||
// something below is about to change it -- which is the whole class
|
||||
// of defect where a widget settles inside its parent's draw, clears
|
||||
// its mark there, and tells nobody its answer moved.
|
||||
let marked: Vec<WidgetId> = rsc.widgets().needs_redraw.iter().copied().collect();
|
||||
for id in marked {
|
||||
// The queue is that set, ordered: a mark made while the walk runs
|
||||
// queues itself through `mark`. What ends the walk is still the set
|
||||
// being spent, not the queue, so a mark that reached it another way
|
||||
// cannot be left for the next frame.
|
||||
loop {
|
||||
for &id in rsc.widgets().needs_redraw.iter() {
|
||||
if !self.deferred.contains(&id) {
|
||||
let depth = self.depth(id);
|
||||
self.pending.insert((depth, id));
|
||||
}
|
||||
while let Some(&(depth, id)) = self.pending.last() {
|
||||
self.pending.remove(&(depth, id));
|
||||
// A widget settled inside an ancestor's draw, or deferred to one,
|
||||
// is left here by the mark that queued it.
|
||||
}
|
||||
if self.pending.is_empty() {
|
||||
break;
|
||||
}
|
||||
while let Some((depth, id)) = self.pending.pop_last() {
|
||||
// Settled inside an ancestor's draw, or deferred to one,
|
||||
// since the mark that queued it.
|
||||
if self.deferred.contains(&id) || !rsc.widgets().needs_redraw.contains(&id) {
|
||||
continue;
|
||||
}
|
||||
// A subtree that changed hands takes its descendants' depths with
|
||||
// it, so an entry queued before that move names the wrong one.
|
||||
// A subtree that changed hands takes its descendants' depths
|
||||
// with it, so an entry queued before that move names the
|
||||
// depth it had under the parent it left.
|
||||
let now = self.depth(id);
|
||||
if now != depth {
|
||||
self.pending.insert((now, id));
|
||||
@@ -1024,12 +1041,11 @@ impl UiRenderState {
|
||||
self.deferred.insert(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.deferred.clear();
|
||||
}
|
||||
|
||||
/// Marks a widget for the walk to settle. Every mark made while a frame
|
||||
/// is being laid out goes through here, so the queue holds what the set
|
||||
/// holds without being searched again.
|
||||
/// Marks a widget for the walk to settle, and queues it at its depth.
|
||||
fn mark(&mut self, id: WidgetId, widgets: &mut Widgets) {
|
||||
if widgets.needs_redraw.insert(id) && !self.deferred.contains(&id) {
|
||||
let depth = self.depth(id);
|
||||
@@ -1163,16 +1179,6 @@ impl UiRenderState {
|
||||
return true;
|
||||
};
|
||||
let (given_px, offered_px) = self.asked_px(id);
|
||||
// Asked again in the box its parent gave it, which is the question
|
||||
// its parent asked only while that box is as long as the offer. Any
|
||||
// other box is a different question, so the parent asks it, with the
|
||||
// mark left on. Lengths and not whole boxes: what a drawing depends
|
||||
// on is its lengths, so the same lengths elsewhere is one question.
|
||||
if given_px != offered_px {
|
||||
self.mark(id, rsc.widgets_mut());
|
||||
self.mark(parent, rsc.widgets_mut());
|
||||
return false;
|
||||
}
|
||||
let info = DrawInfo {
|
||||
layer: active.layer,
|
||||
parent: active.parent,
|
||||
@@ -1181,6 +1187,7 @@ impl UiRenderState {
|
||||
region_node: rsc.widgets().is_region_node(id),
|
||||
mask: active.parent_mask,
|
||||
given_region: active.given_region,
|
||||
offer_region: active.offer_region,
|
||||
offer_len: active.offer_len,
|
||||
offer_placement: active.offer_placement,
|
||||
px: given_px,
|
||||
@@ -1195,14 +1202,33 @@ impl UiRenderState {
|
||||
diag::bump(Counter::LocalRedraws);
|
||||
|
||||
let old = self.remove(id, false, rsc);
|
||||
// Refresh the original measurement before restoring the assigned slot.
|
||||
// Its lengths may differ even though the fraction reference is unchanged.
|
||||
// Asked again where its parent asked: the offer's frame, composed
|
||||
// where the given one is, at the offer's lengths and placement. That
|
||||
// is the question its answer came from, whatever box the parent then
|
||||
// chose from the answer -- which is often a different frame, since a
|
||||
// span hands its children its own placement across itself. The
|
||||
// parent draws in its own frame, or in `FULL` where it is a region
|
||||
// node.
|
||||
let parent_frame = match self.active.get(&parent) {
|
||||
Some(p) if p.move_idx == p.parent_move => p.region,
|
||||
_ => UiRegion::FULL,
|
||||
};
|
||||
let offer_frame = match info.offer_region == UiRegion::FULL {
|
||||
true => parent_frame,
|
||||
false => info.offer_region.within(&parent_frame),
|
||||
};
|
||||
let offered = DrawInfo {
|
||||
placement: info.offer_placement,
|
||||
given_region: info.offer_region,
|
||||
px: offered_px,
|
||||
..info
|
||||
};
|
||||
let answer = self.draw_inner(id, given, offered, old, false, rsc);
|
||||
if info.placement != offered.placement {
|
||||
// Where the given differs from the offer, the first draw is only the
|
||||
// measurement and the second puts the drawing where the parent did.
|
||||
let placed_apart =
|
||||
info.placement != offered.placement || info.px != offered.px || given != offer_frame;
|
||||
let answer = self.draw_inner(id, offer_frame, offered, old, placed_apart, rsc);
|
||||
if placed_apart {
|
||||
self.draw_inner(id, given, info, None, false, rsc);
|
||||
}
|
||||
let active = self.active.get_mut(&id).unwrap();
|
||||
|
||||
Reference in new issue
Block a user