Skip third flex pass entirely if main axis is compressed
This commit is contained in:
parent
7711b49f6b
commit
3ad578e248
2 changed files with 50 additions and 48 deletions
|
|
@ -155,7 +155,9 @@ where
|
||||||
axis.pack(size.width, size.height)
|
axis.pack(size.width, size.height)
|
||||||
};
|
};
|
||||||
|
|
||||||
if main_size.fill_factor() == 0 && cross_size.fill_factor() != 0 {
|
if (main_compress || main_size.fill_factor() == 0)
|
||||||
|
&& cross_size.fill_factor() != 0
|
||||||
|
{
|
||||||
if let Length::Fixed(main) = main_size {
|
if let Length::Fixed(main) = main_size {
|
||||||
available -= main;
|
available -= main;
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -183,54 +185,57 @@ where
|
||||||
|
|
||||||
let remaining = available.max(0.0);
|
let remaining = available.max(0.0);
|
||||||
|
|
||||||
// THIRD PASS
|
// THIRD PASS (conditional)
|
||||||
// We lay out the elements that are fluid in the main axis.
|
// We lay out the elements that are fluid in the main axis.
|
||||||
// We use the remaining space to evenly allocate space based on fill factors.
|
// We use the remaining space to evenly allocate space based on fill factors.
|
||||||
for (i, (child, tree)) in items.iter_mut().zip(trees.iter_mut()).enumerate()
|
if !main_compress {
|
||||||
{
|
for (i, (child, tree)) in
|
||||||
let (fill_main_factor, fill_cross_factor) = {
|
items.iter_mut().zip(trees.iter_mut()).enumerate()
|
||||||
let size = child.as_widget().size();
|
{
|
||||||
|
let (fill_main_factor, fill_cross_factor) = {
|
||||||
|
let size = child.as_widget().size();
|
||||||
|
|
||||||
axis.pack(size.width.fill_factor(), size.height.fill_factor())
|
axis.pack(size.width.fill_factor(), size.height.fill_factor())
|
||||||
};
|
|
||||||
|
|
||||||
if !main_compress && fill_main_factor != 0 {
|
|
||||||
let max_main =
|
|
||||||
remaining * fill_main_factor as f32 / fill_main_sum as f32;
|
|
||||||
|
|
||||||
let max_main = if max_main.is_nan() {
|
|
||||||
f32::INFINITY
|
|
||||||
} else {
|
|
||||||
max_main
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let min_main = if max_main.is_infinite() {
|
if fill_main_factor != 0 {
|
||||||
0.0
|
let max_main =
|
||||||
} else {
|
remaining * fill_main_factor as f32 / fill_main_sum as f32;
|
||||||
max_main
|
|
||||||
};
|
|
||||||
|
|
||||||
let (min_width, min_height) = axis.pack(min_main, 0.0);
|
let max_main = if max_main.is_nan() {
|
||||||
let (max_width, max_height) = axis.pack(
|
f32::INFINITY
|
||||||
max_main,
|
|
||||||
if fill_cross_factor == 0 {
|
|
||||||
max_cross
|
|
||||||
} else {
|
} else {
|
||||||
cross
|
max_main
|
||||||
},
|
};
|
||||||
);
|
|
||||||
|
|
||||||
let child_limits = Limits::with_compression(
|
let min_main = if max_main.is_infinite() {
|
||||||
Size::new(min_width, min_height),
|
0.0
|
||||||
Size::new(max_width, max_height),
|
} else {
|
||||||
compression,
|
max_main
|
||||||
);
|
};
|
||||||
|
|
||||||
let layout =
|
let (min_width, min_height) = axis.pack(min_main, 0.0);
|
||||||
child.as_widget_mut().layout(tree, renderer, &child_limits);
|
let (max_width, max_height) = axis.pack(
|
||||||
cross = cross.max(axis.cross(layout.size()));
|
max_main,
|
||||||
|
if fill_cross_factor == 0 {
|
||||||
|
max_cross
|
||||||
|
} else {
|
||||||
|
cross
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
nodes[i] = layout;
|
let child_limits = Limits::with_compression(
|
||||||
|
Size::new(min_width, min_height),
|
||||||
|
Size::new(max_width, max_height),
|
||||||
|
compression,
|
||||||
|
);
|
||||||
|
|
||||||
|
let layout =
|
||||||
|
child.as_widget_mut().layout(tree, renderer, &child_limits);
|
||||||
|
cross = cross.max(axis.cross(layout.size()));
|
||||||
|
|
||||||
|
nodes[i] = layout;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -253,11 +258,8 @@ where
|
||||||
|
|
||||||
let (max_width, max_height) = axis.pack(main, cross);
|
let (max_width, max_height) = axis.pack(main, cross);
|
||||||
|
|
||||||
let child_limits = Limits::with_compression(
|
let child_limits =
|
||||||
Size::ZERO,
|
Limits::new(Size::ZERO, Size::new(max_width, max_height));
|
||||||
Size::new(max_width, max_height),
|
|
||||||
compression,
|
|
||||||
);
|
|
||||||
|
|
||||||
let layout =
|
let layout =
|
||||||
child.as_widget_mut().layout(tree, renderer, &child_limits);
|
child.as_widget_mut().layout(tree, renderer, &child_limits);
|
||||||
|
|
|
||||||
|
|
@ -94,14 +94,14 @@ impl Layout {
|
||||||
|
|
||||||
let controls = row([
|
let controls = row([
|
||||||
(!self.example.is_first()).then_some(
|
(!self.example.is_first()).then_some(
|
||||||
button("← Previous")
|
button(text("← Previous").shaping(text::Shaping::Advanced))
|
||||||
.padding([5, 10])
|
.padding([5, 10])
|
||||||
.on_press(Message::Previous)
|
.on_press(Message::Previous)
|
||||||
.into(),
|
.into(),
|
||||||
),
|
),
|
||||||
Some(horizontal_space().into()),
|
Some(horizontal_space().into()),
|
||||||
(!self.example.is_last()).then_some(
|
(!self.example.is_last()).then_some(
|
||||||
button("Next →")
|
button(text("Next →").shaping(text::Shaping::Advanced))
|
||||||
.padding([5, 10])
|
.padding([5, 10])
|
||||||
.on_press(Message::Next)
|
.on_press(Message::Next)
|
||||||
.into(),
|
.into(),
|
||||||
|
|
@ -294,7 +294,7 @@ fn quotes<'a>() -> Element<'a, Message> {
|
||||||
fn quote<'a>(
|
fn quote<'a>(
|
||||||
content: impl Into<Element<'a, Message>>,
|
content: impl Into<Element<'a, Message>>,
|
||||||
) -> Element<'a, Message> {
|
) -> Element<'a, Message> {
|
||||||
row![vertical_rule(2), content.into()]
|
row![vertical_rule(1), content.into()]
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.height(Shrink)
|
.height(Shrink)
|
||||||
.into()
|
.into()
|
||||||
|
|
@ -313,7 +313,7 @@ fn quotes<'a>() -> Element<'a, Message> {
|
||||||
"This is another reply",
|
"This is another reply",
|
||||||
),
|
),
|
||||||
horizontal_rule(1),
|
horizontal_rule(1),
|
||||||
"A separator ↑",
|
text("A separator ↑").shaping(text::Shaping::Advanced),
|
||||||
]
|
]
|
||||||
.width(Shrink)
|
.width(Shrink)
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue