Separate measured-answer dependencies from retained drawing validity
This commit is contained in:
1 parent
c44bd198ee
commit
f860f716e6
7 files changed
+188
-356
No files matched your search
+38
-62
@@ -66,13 +66,6 @@ pub struct UiRenderState {
|
||||
/// A widget's move slot, which outlives any one `ActiveData`: a redraw
|
||||
/// replaces that while its children go on pointing at the slot.
|
||||
slots: HashMap<WidgetId, MoveIdx>,
|
||||
/// Answers invalidated by a declared-length change below them. These are
|
||||
/// replaced even when retained placement means the redraw is not at the
|
||||
/// old offer.
|
||||
answer_invalid: crate::util::HashSet<WidgetId>,
|
||||
/// Whether this frame contains a declared-length change, so any dirty
|
||||
/// dependent replaces its answer too.
|
||||
replace_answers: bool,
|
||||
/// Widgets waiting for an ancestor to draw them, so the walk down the
|
||||
/// depths does not pick one up again at its own depth.
|
||||
deferred: crate::util::HashSet<WidgetId>,
|
||||
@@ -87,8 +80,6 @@ impl UiRenderState {
|
||||
output_size: PxVec2::ZERO,
|
||||
old_root: None,
|
||||
slots: Default::default(),
|
||||
answer_invalid: Default::default(),
|
||||
replace_answers: false,
|
||||
deferred: Default::default(),
|
||||
moves: Default::default(),
|
||||
resized: false,
|
||||
@@ -103,9 +94,8 @@ impl UiRenderState {
|
||||
/// retained entry at all.
|
||||
///
|
||||
/// The root is the only widget a resize marks, and only where the new
|
||||
/// output falls outside what its answer holds for: that range is the
|
||||
/// intersection of everything under it, so admitting the new output says
|
||||
/// the whole tree still stands. Where it does not, the ordinary walk
|
||||
/// output invalidates its answer or its drawing. The latter includes
|
||||
/// children whose size it never read. Where either fails, the ordinary walk
|
||||
/// draws the root, and each widget's own range decides how far down the
|
||||
/// new length reaches.
|
||||
pub fn resize(&mut self, size: impl Into<Vec2>, widgets: &mut Widgets) {
|
||||
@@ -116,10 +106,10 @@ impl UiRenderState {
|
||||
self.output_size = size;
|
||||
self.resized = true;
|
||||
let Some(root) = self.old_root else { return };
|
||||
let stands = self
|
||||
.active
|
||||
.get(&root)
|
||||
.is_some_and(|active| active.answers_at(active.given_region.size().to_px(size)));
|
||||
let stands = self.active.get(&root).is_some_and(|active| {
|
||||
let px = active.given_region.size().to_px(size);
|
||||
active.answers_at(px) && active.holds.contains(px, active.placement)
|
||||
});
|
||||
if !stands {
|
||||
widgets.needs_redraw.insert(root);
|
||||
}
|
||||
@@ -182,7 +172,6 @@ impl UiRenderState {
|
||||
if rsc.widgets().has_updates() {
|
||||
self.redraw_updates(rsc);
|
||||
}
|
||||
self.replace_answers = false;
|
||||
self.free(rsc);
|
||||
}
|
||||
|
||||
@@ -215,7 +204,7 @@ impl UiRenderState {
|
||||
mut old: Option<ActiveData>,
|
||||
measuring: bool,
|
||||
rsc: &mut dyn UiRsc,
|
||||
) -> (Size, LayoutHolds) {
|
||||
) -> (Size, LayoutHolds, LayoutHolds) {
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
{
|
||||
diag::bump(Counter::DrawRequests);
|
||||
@@ -226,8 +215,7 @@ impl UiRenderState {
|
||||
// one bottom-up walk, so anything deeper has settled or deferred to
|
||||
// its own parent, and a deferred one leaves that parent marked.
|
||||
let stale = rsc.widgets().needs_redraw.contains(&id);
|
||||
let replace_answer = self.answer_invalid.remove(&id) || (self.replace_answers && stale);
|
||||
let retained = match replace_answer || stale {
|
||||
let retained = match stale {
|
||||
true => None,
|
||||
false => self
|
||||
.retained_answer(id, info)
|
||||
@@ -284,7 +272,7 @@ impl UiRenderState {
|
||||
active.given_region = info.given_region;
|
||||
active.offer_len = info.offer_len;
|
||||
if info.placement == info.offer_placement && info.px == info.offered_px {
|
||||
active.answer = Some(settled);
|
||||
active.answer = Some(answer);
|
||||
active.offer_placement = info.offer_placement;
|
||||
}
|
||||
active.decided = info.decided();
|
||||
@@ -300,9 +288,9 @@ impl UiRenderState {
|
||||
&& let Some(old_parent) = self.active.get_mut(&old_parent)
|
||||
{
|
||||
old_parent.children.retain(|child| *child != id);
|
||||
old_parent.extent_children.retain(|(child, _)| *child != id);
|
||||
old_parent.inherited_children.retain(|child| *child != id);
|
||||
}
|
||||
settled
|
||||
(answer.0, answer.1, settled.1)
|
||||
}
|
||||
|
||||
/// Recompose retained geometry when the evaluation still holds at this extent.
|
||||
@@ -373,16 +361,16 @@ impl UiRenderState {
|
||||
textures: Vec::new(),
|
||||
primitives: Vec::new(),
|
||||
mask_region: None,
|
||||
extent_children: Vec::new(),
|
||||
inherited_children: Vec::new(),
|
||||
children: Vec::new(),
|
||||
offered: Vec::new(),
|
||||
offered_px: info.offered_px,
|
||||
at_offer,
|
||||
size_deps: Vec::new(),
|
||||
own: [Holds::ANY; 2],
|
||||
under: [Holds::ANY; 2],
|
||||
under: LayoutHolds::ANY,
|
||||
extent_own: [Holds::ANY; 2],
|
||||
extent_under: [Holds::ANY; 2],
|
||||
answer_under: LayoutHolds::ANY,
|
||||
depth: info.depth,
|
||||
move_idx,
|
||||
rsc,
|
||||
@@ -410,9 +398,9 @@ impl UiRenderState {
|
||||
textures,
|
||||
primitives,
|
||||
mask_region,
|
||||
extent_children,
|
||||
inherited_children,
|
||||
extent_own,
|
||||
extent_under,
|
||||
answer_under,
|
||||
children,
|
||||
offered: _,
|
||||
offered_px: _,
|
||||
@@ -450,14 +438,13 @@ impl UiRenderState {
|
||||
"'{}' ({id:?}) clips to {px:?} and reports {size}",
|
||||
rsc.widgets().label(id),
|
||||
);
|
||||
let holds = LayoutHolds {
|
||||
frame: [own[0].and(under[0]), own[1].and(under[1])],
|
||||
extent: [
|
||||
extent_own[0].and(extent_under[0]),
|
||||
extent_own[1].and(extent_under[1]),
|
||||
],
|
||||
let own_holds = LayoutHolds {
|
||||
frame: own,
|
||||
extent: extent_own,
|
||||
placement: reads_placement.then_some(placement),
|
||||
};
|
||||
let answer_holds = own_holds.and(answer_under);
|
||||
let holds = answer_holds.and(under);
|
||||
debug_assert!(
|
||||
holds.contains(px, placement),
|
||||
"'{}' ({id:?}) drew in {px:?}, outside the ranges it reported: {holds:?}",
|
||||
@@ -516,7 +503,7 @@ impl UiRenderState {
|
||||
textures,
|
||||
primitives,
|
||||
mask_region,
|
||||
extent_children,
|
||||
inherited_children,
|
||||
children,
|
||||
size_deps,
|
||||
declared: declared_lens(rsc.widgets(), id),
|
||||
@@ -530,7 +517,7 @@ impl UiRenderState {
|
||||
};
|
||||
rsc.on_draw(&active);
|
||||
self.active.insert(id, active);
|
||||
(size, holds)
|
||||
(size, answer_holds)
|
||||
}
|
||||
|
||||
/// Keeps a region node's entry across redraws because descendants retain
|
||||
@@ -765,18 +752,19 @@ impl UiRenderState {
|
||||
}
|
||||
let parent_move = active.move_idx;
|
||||
let mask = active.mask;
|
||||
let children = active.extent_children.len();
|
||||
let children = active.inherited_children.len();
|
||||
for index in 0..children {
|
||||
let (child, extent) = self.active[&id].extent_children[index];
|
||||
let (child_region, chosen) = extent.resolve(placement);
|
||||
let child = self.active[&id].inherited_children[index];
|
||||
let active = &self.active[&child];
|
||||
let (child_local, chosen) =
|
||||
ask_box(child_region, active.declared, active.own_align, chosen);
|
||||
// Keep the slot chosen from measurement: the final draw can
|
||||
// report a different size, for example after text reflows.
|
||||
let (child_local, chosen) = ask_box(
|
||||
UiRegion::FULL,
|
||||
active.declared,
|
||||
active.own_align,
|
||||
[Some(placement.x), Some(placement.y)],
|
||||
);
|
||||
let child_placement = UiRegion {
|
||||
x: chosen[0].unwrap_or(active.placement.x),
|
||||
y: chosen[1].unwrap_or(active.placement.y),
|
||||
x: chosen[0].unwrap_or(UiSpan::FULL),
|
||||
y: chosen[1].unwrap_or(UiSpan::FULL),
|
||||
};
|
||||
let child_info = DrawInfo {
|
||||
layer: active.layer,
|
||||
@@ -936,7 +924,7 @@ impl UiRenderState {
|
||||
textures: Vec::new(),
|
||||
primitives: Vec::new(),
|
||||
mask_region: None,
|
||||
extent_children: Vec::new(),
|
||||
inherited_children: Vec::new(),
|
||||
children: Vec::new(),
|
||||
size_deps: Vec::new(),
|
||||
move_idx: info.parent_move,
|
||||
@@ -958,8 +946,6 @@ impl UiRenderState {
|
||||
}
|
||||
}
|
||||
self.slots.clear();
|
||||
self.answer_invalid.clear();
|
||||
self.replace_answers = false;
|
||||
self.moves.clear();
|
||||
self.layers.clear();
|
||||
rsc.widgets_mut().needs_redraw.clear();
|
||||
@@ -973,7 +959,6 @@ impl UiRenderState {
|
||||
rsc.on_remove(id);
|
||||
self.remove(id, true, rsc);
|
||||
self.drop_slot(id);
|
||||
self.answer_invalid.remove(&id);
|
||||
}
|
||||
rsc.ui_mut().textures.free();
|
||||
}
|
||||
@@ -1110,15 +1095,6 @@ impl UiRenderState {
|
||||
if let Some(parent) = active.parent
|
||||
&& (declared_changed || alignment_changed || !active.drawn || active.answer.is_none())
|
||||
{
|
||||
if declared_changed {
|
||||
self.replace_answers = true;
|
||||
let mut at = Some(id);
|
||||
while let Some(next) = at {
|
||||
self.answer_invalid.insert(next);
|
||||
rsc.widgets_mut().needs_redraw.insert(next);
|
||||
at = self.active[&next].parent;
|
||||
}
|
||||
}
|
||||
// Both stay marked: the parent because it has this to draw, and
|
||||
// this because the parent must draw it rather than keep what it
|
||||
// has. The mark comes off in `draw_at`, where the parent draws.
|
||||
@@ -1172,7 +1148,7 @@ impl UiRenderState {
|
||||
placement: AXES
|
||||
.map(|axis| active.decided[axis as usize].then(|| *active.placement.axis(axis))),
|
||||
};
|
||||
let (given, was_answer) = (active.region, active.answer);
|
||||
let (given, was_answer, was_holds) = (active.region, active.answer, active.holds);
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
diag::bump(Counter::LocalRedraws);
|
||||
|
||||
@@ -1187,9 +1163,9 @@ impl UiRenderState {
|
||||
if info.placement != offered.placement {
|
||||
self.draw_inner(id, given, info, None, false, rsc);
|
||||
}
|
||||
if Some(answer) != was_answer {
|
||||
// Its parent chose its box knowing the old answer, so it lays out
|
||||
// again and chooses the box the new one asks for.
|
||||
if Some((answer.0, answer.1)) != was_answer || self.active[&id].holds != was_holds {
|
||||
// The parent retains both the answer and the drawing's validity;
|
||||
// even an unchanged size can narrow the range safe for a resize.
|
||||
#[cfg(feature = "layout-diagnostics")]
|
||||
{
|
||||
diag::bump(Counter::SizeChanges);
|
||||
|
||||
Reference in new issue
Block a user