Track retained layout validity explicitly
This commit is contained in:
1 parent
691e3eb23c
commit
29c7881c8a
25 files changed
+836
-795
No files matched your search
@@ -32,12 +32,44 @@ impl Widget for Span {
|
||||
let gap = self.gap * self.children.len().saturating_sub(1) as f32;
|
||||
let total = lens.iter().fold(Len::px(gap), |sum, len| sum + *len);
|
||||
|
||||
// Whether anything is left over is a question in pixels: `rel(0.5)`
|
||||
// beside 300 px is full at 600 and overfull at 400. The answer is
|
||||
// the same on either side of the length the fixed parts alone fill.
|
||||
let fixed = 1.0 - total.rel;
|
||||
let shares = total.leftover > 0.0 && fixed * painter.px_len(axis) > total.px;
|
||||
if total.leftover > 0.0 {
|
||||
let range = if fixed > 0.0 {
|
||||
let full = total.px / fixed;
|
||||
match shares {
|
||||
true => full..=f32::INFINITY,
|
||||
false => f32::NEG_INFINITY..=full,
|
||||
}
|
||||
} else if fixed < 0.0 {
|
||||
let full = total.px / fixed;
|
||||
match shares {
|
||||
true => f32::NEG_INFINITY..=full,
|
||||
false => full..=f32::INFINITY,
|
||||
}
|
||||
} else {
|
||||
f32::NEG_INFINITY..=f32::INFINITY
|
||||
};
|
||||
painter.holds(axis, range);
|
||||
}
|
||||
|
||||
let mut start = UiScalar::rel_min();
|
||||
let mut ortho = Len::ZERO;
|
||||
for (child, len) in self.children.iter().zip(&lens) {
|
||||
// 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.
|
||||
if len.leftover > 0.0 && len.px == 0.0 && len.rel == 0.0 && !shares {
|
||||
painter.undraw(child);
|
||||
start.px += self.gap;
|
||||
continue;
|
||||
}
|
||||
let mut span = UiSpan::FULL;
|
||||
span.start = start;
|
||||
if len.leftover > 0.0 {
|
||||
if len.leftover > 0.0 && shares {
|
||||
let offset = UiScalar::new(total.rel, total.px);
|
||||
let rel_end = UiScalar::rel(len.leftover / total.leftover);
|
||||
let end = (UiScalar::rel_max() + start) - offset;
|
||||
@@ -70,12 +102,6 @@ impl Widget for Span {
|
||||
let along = total;
|
||||
Size::from_axis(axis, along, ortho)
|
||||
}
|
||||
|
||||
/// Every child is placed in fractions and offsets of the span's own box,
|
||||
/// so a longer box holds the same layout and the children follow it.
|
||||
fn on_resize(&self, _: Axis) -> OnResize {
|
||||
OnResize::Scale
|
||||
}
|
||||
}
|
||||
|
||||
impl Span {
|
||||
|
||||
Reference in new issue
Block a user