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

+7 -3
View File
@@ -13,9 +13,13 @@ impl Widget for Scroll {
fn draw(&mut self, painter: &mut Painter) -> Size {
let output_len = painter.output_size().axis(self.axis);
let container_len = UiScalar::abs(painter.px_size().axis(self.axis));
// Drawn in the whole container to learn its length, then placed at
// the scrolled offset.
let child = painter.place(&self.inner, UiRegion::FULL).size();
// Its last measured size stays valid while neither the child nor this
// container's constraints changed. Otherwise draw it in the whole
// container to learn its length, then place it at the scrolled offset.
let child = match painter.retained_size(&self.inner) {
Some(size) => size,
None => painter.place(&self.inner, UiRegion::FULL).size(),
};
let content_len = child
.axis(self.axis)
.apply_rest()