Avoid speculative layout when retained answers suffice

This commit is contained in:
iris-ai committed 2026-09-14 15:33:39 -04:00
1 parent cdec29351a
commit a640c6cce2
5 files changed
+116 -27

No files matched your search

+17
View File
@@ -22,6 +22,8 @@ pub struct Painter<'a> {
/// The children whose size this widget read while drawing.
pub(super) size_deps: Vec<WidgetId>,
pub(super) reads_output: bool,
/// Whether this widget is drawing in the same pixel-sized box as before.
pub(super) same_box: bool,
/// The slot this widget's primitives are positioned through: its own if
/// its parent placed it, otherwise the nearest ancestor that has one.
pub(super) move_idx: MoveIdx,
@@ -144,6 +146,21 @@ impl<'a> Painter<'a> {
Some(hint)
}
/// A clean child's retained size, when this widget's own constraints are
/// unchanged. This is the answer from its last real draw, not a guess.
pub fn retained_size<W: ?Sized>(&mut self, id: &StrongWidget<W>) -> Option<Size> {
if !self.same_box || self.rsc.widgets().needs_redraw.contains(&id.id()) {
return None;
}
let active = self.state.active.get(&id.id())?;
if active.parent != Some(self.id) {
return None;
}
let size = active.size;
self.depend_on_size(id);
Some(size)
}
fn depend_on_size<W: ?Sized>(&mut self, child: &StrongWidget<W>) {
if !self.size_deps.contains(&child.id()) {
self.size_deps.push(child.id());