Keep only what a room drawing is still needed for
A span measuring a child in the room kept its whole `Size`, of which the along axis is already in `lens` and only the across one is read again when the drawing is placed. Keep that length alone, which also retires the rebinding of the match's result and the one in the placing loop. The placement comment already says what becomes of a drawing made in the room, so the measuring pass no longer says it a second time.
This commit is contained in:
1 parent
38b3a81053
commit
cadfba05dd
1 file changed
+8
-13
@@ -28,16 +28,13 @@ impl Widget for Span {
|
||||
// given whatever else is in it and wherever this child sits among
|
||||
// them; what a drawn child is asked in is the room left from the
|
||||
// cursor, because a text has to wrap at the width actually there.
|
||||
// This is the one ask a drawn fixed child gets: its slot is its
|
||||
// answer, and the drawing is moved there once the shares are known.
|
||||
// A hinted child is asked once, in its slot.
|
||||
let mut cursor = Len::rel_min();
|
||||
let mut lens = Vec::with_capacity(self.children.len());
|
||||
let mut measured = Vec::with_capacity(self.children.len());
|
||||
let mut drawn_across = Vec::with_capacity(self.children.len());
|
||||
for child in &self.children {
|
||||
let size = match painter.size_hint(child, axis) {
|
||||
let len = match painter.size_hint(child, axis) {
|
||||
Some(len) => {
|
||||
measured.push(None);
|
||||
drawn_across.push(None);
|
||||
len
|
||||
}
|
||||
None => {
|
||||
@@ -45,11 +42,10 @@ impl Widget for Span {
|
||||
let size = painter
|
||||
.widget_at(child, [None; 2], axis.pair(room, across))
|
||||
.size();
|
||||
measured.push(Some(size));
|
||||
drawn_across.push(Some(size.axis(!axis)));
|
||||
size.axis(axis)
|
||||
}
|
||||
};
|
||||
let len = size;
|
||||
cursor.px += len.px + self.gap;
|
||||
cursor.rel += len.rel;
|
||||
lens.push(len);
|
||||
@@ -104,8 +100,7 @@ impl Widget for Span {
|
||||
let mut taken = Weight::ZERO;
|
||||
let mut start = Len::rel_min();
|
||||
let mut ortho = LayoutLen::ZERO;
|
||||
for ((child, len), measured) in self.children.iter().zip(&lens).zip(&measured) {
|
||||
let len = *len;
|
||||
for ((child, &len), &across_len) in self.children.iter().zip(&lens).zip(&drawn_across) {
|
||||
// A child asking for nothing but a part of what is left over,
|
||||
// when nothing is, is not drawn at all. One that also asked for
|
||||
// pixels or a fraction keeps those and overflows.
|
||||
@@ -135,10 +130,10 @@ impl Widget for Span {
|
||||
if len.leftover > Weight::ZERO && shares {
|
||||
narrow[axis as usize] = Some(slot.len());
|
||||
}
|
||||
let used = match (measured, narrow[axis as usize]) {
|
||||
(Some(size), None) => {
|
||||
let used = match (across_len, narrow[axis as usize]) {
|
||||
(Some(across_len), None) => {
|
||||
painter.place_at(child, place);
|
||||
size.axis(!axis)
|
||||
across_len
|
||||
}
|
||||
_ => painter.widget_at(child, narrow, place).len(!axis),
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user