Remove complex cross-axis layout logic from Column and Row
This commit is contained in:
parent
af9fb367f3
commit
cbe4603579
2 changed files with 25 additions and 84 deletions
|
|
@ -80,14 +80,9 @@ where
|
||||||
|
|
||||||
let mut fill_main_sum = 0;
|
let mut fill_main_sum = 0;
|
||||||
let mut cross = match axis {
|
let mut cross = match axis {
|
||||||
Axis::Horizontal => match height {
|
Axis::Vertical if width == Length::Shrink => 0.0,
|
||||||
Length::Shrink => 0.0,
|
Axis::Horizontal if height == Length::Shrink => 0.0,
|
||||||
_ => max_cross,
|
_ => max_cross,
|
||||||
},
|
|
||||||
Axis::Vertical => match width {
|
|
||||||
Length::Shrink => 0.0,
|
|
||||||
_ => max_cross,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut available = axis.main(limits.max()) - total_spacing;
|
let mut available = axis.main(limits.max()) - total_spacing;
|
||||||
|
|
@ -103,35 +98,14 @@ where
|
||||||
};
|
};
|
||||||
|
|
||||||
if fill_main_factor == 0 {
|
if fill_main_factor == 0 {
|
||||||
if fill_cross_factor == 0 {
|
let (max_width, max_height) = axis.pack(
|
||||||
let (max_width, max_height) = axis.pack(available, max_cross);
|
available,
|
||||||
|
if fill_cross_factor == 0 {
|
||||||
let child_limits =
|
max_cross
|
||||||
Limits::new(Size::ZERO, Size::new(max_width, max_height));
|
} else {
|
||||||
|
cross
|
||||||
let layout =
|
},
|
||||||
child.as_widget().layout(tree, renderer, &child_limits);
|
);
|
||||||
let size = layout.size();
|
|
||||||
|
|
||||||
available -= axis.main(size);
|
|
||||||
cross = cross.max(axis.cross(size));
|
|
||||||
|
|
||||||
nodes[i] = layout;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fill_main_sum += fill_main_factor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i, (child, tree)) in items.iter().zip(trees.iter_mut()).enumerate() {
|
|
||||||
let (fill_main_factor, fill_cross_factor) = {
|
|
||||||
let size = child.as_widget().size();
|
|
||||||
|
|
||||||
axis.pack(size.width.fill_factor(), size.height.fill_factor())
|
|
||||||
};
|
|
||||||
|
|
||||||
if fill_main_factor == 0 && fill_cross_factor != 0 {
|
|
||||||
let (max_width, max_height) = axis.pack(available, cross);
|
|
||||||
|
|
||||||
let child_limits =
|
let child_limits =
|
||||||
Limits::new(Size::ZERO, Size::new(max_width, max_height));
|
Limits::new(Size::ZERO, Size::new(max_width, max_height));
|
||||||
|
|
@ -141,9 +115,11 @@ where
|
||||||
let size = layout.size();
|
let size = layout.size();
|
||||||
|
|
||||||
available -= axis.main(size);
|
available -= axis.main(size);
|
||||||
cross = cross.max(axis.cross(layout.size()));
|
cross = cross.max(axis.cross(size));
|
||||||
|
|
||||||
nodes[i] = layout;
|
nodes[i] = layout;
|
||||||
|
} else {
|
||||||
|
fill_main_sum += fill_main_factor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -175,14 +151,15 @@ where
|
||||||
max_main
|
max_main
|
||||||
};
|
};
|
||||||
|
|
||||||
let max_cross = if fill_cross_factor == 0 {
|
|
||||||
max_cross
|
|
||||||
} else {
|
|
||||||
cross
|
|
||||||
};
|
|
||||||
|
|
||||||
let (min_width, min_height) = axis.pack(min_main, 0.0);
|
let (min_width, min_height) = axis.pack(min_main, 0.0);
|
||||||
let (max_width, max_height) = axis.pack(max_main, max_cross);
|
let (max_width, max_height) = axis.pack(
|
||||||
|
max_main,
|
||||||
|
if fill_cross_factor == 0 {
|
||||||
|
max_cross
|
||||||
|
} else {
|
||||||
|
cross
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
let child_limits = Limits::new(
|
let child_limits = Limits::new(
|
||||||
Size::new(min_width, min_height),
|
Size::new(min_width, min_height),
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ use iced::mouse;
|
||||||
use iced::theme;
|
use iced::theme;
|
||||||
use iced::widget::{
|
use iced::widget::{
|
||||||
button, canvas, checkbox, column, container, horizontal_space, pick_list,
|
button, canvas, checkbox, column, container, horizontal_space, pick_list,
|
||||||
row, scrollable, text, vertical_rule,
|
row, scrollable, text,
|
||||||
};
|
};
|
||||||
use iced::{
|
use iced::{
|
||||||
color, Alignment, Application, Color, Command, Element, Font, Length,
|
color, Alignment, Application, Command, Element, Font, Length, Point,
|
||||||
Point, Rectangle, Renderer, Settings, Subscription, Theme,
|
Rectangle, Renderer, Settings, Subscription, Theme,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn main() -> iced::Result {
|
pub fn main() -> iced::Result {
|
||||||
|
|
@ -167,10 +167,6 @@ impl Example {
|
||||||
title: "Application",
|
title: "Application",
|
||||||
view: application,
|
view: application,
|
||||||
},
|
},
|
||||||
Self {
|
|
||||||
title: "Nested Quotes",
|
|
||||||
view: nested_quotes,
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
fn is_first(self) -> bool {
|
fn is_first(self) -> bool {
|
||||||
|
|
@ -304,38 +300,6 @@ fn application<'a>() -> Element<'a, Message> {
|
||||||
column![header, row![sidebar, content]].into()
|
column![header, row![sidebar, content]].into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nested_quotes<'a>() -> Element<'a, Message> {
|
|
||||||
(1..5)
|
|
||||||
.fold(column![text("Original text")].padding(10), |quotes, i| {
|
|
||||||
column![
|
|
||||||
container(
|
|
||||||
row![vertical_rule(2), quotes].height(Length::Shrink)
|
|
||||||
)
|
|
||||||
.style(|theme: &Theme| {
|
|
||||||
let palette = theme.extended_palette();
|
|
||||||
|
|
||||||
container::Appearance::default().with_background(
|
|
||||||
if palette.is_dark {
|
|
||||||
Color {
|
|
||||||
a: 0.01,
|
|
||||||
..Color::WHITE
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Color {
|
|
||||||
a: 0.08,
|
|
||||||
..Color::BLACK
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}),
|
|
||||||
text(format!("Reply {i}"))
|
|
||||||
]
|
|
||||||
.spacing(10)
|
|
||||||
.padding(10)
|
|
||||||
})
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn square<'a>(size: impl Into<Length> + Copy) -> Element<'a, Message> {
|
fn square<'a>(size: impl Into<Length> + Copy) -> Element<'a, Message> {
|
||||||
struct Square;
|
struct Square;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue