Avoid speculative layout when retained answers suffice
This commit is contained in:
1 parent
cdec29351a
commit
a640c6cce2
5 files changed
+116
-27
No files matched your search
@@ -12,14 +12,24 @@ impl Widget for Span {
|
||||
let axis = self.dir.axis;
|
||||
// A length for every child before any is placed: from its own hint
|
||||
// where it has one, and from drawing it where it does not.
|
||||
let lens: Vec<Len> = self
|
||||
.children
|
||||
.iter()
|
||||
.map(|child| match painter.size_hint(child, axis) {
|
||||
let mut cursor = UiScalar::rel_min();
|
||||
let mut lens = Vec::with_capacity(self.children.len());
|
||||
for child in &self.children {
|
||||
let len = match painter.size_hint(child, axis) {
|
||||
Some(len) => len,
|
||||
None => painter.place(child, UiRegion::FULL).len(axis),
|
||||
})
|
||||
.collect();
|
||||
None => {
|
||||
let mut span = UiSpan::new(cursor, UiScalar::rel_max());
|
||||
if self.dir.sign == Sign::Neg {
|
||||
span.flip();
|
||||
}
|
||||
let region = UiRegion::from_axis(axis, span, UiSpan::FULL);
|
||||
painter.place(child, region).len(axis)
|
||||
}
|
||||
};
|
||||
cursor.abs += len.abs + self.gap;
|
||||
cursor.rel += len.rel;
|
||||
lens.push(len);
|
||||
}
|
||||
|
||||
let gap = self.gap * self.children.len().saturating_sub(1) as f32;
|
||||
let total = lens.iter().fold(Len::abs(gap), |sum, len| sum + *len);
|
||||
|
||||
Reference in new issue
Block a user