summaryrefslogtreecommitdiffstats
path: root/widget/src/container.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-01-09 06:35:33 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-01-10 10:01:49 +0100
commitd62bb8193c1c43f565fcc5c52293d564c91e215d (patch)
tree7f2d33d2f18a3dfb4e4e8e46b4e968523ca43bc6 /widget/src/container.rs
parentd24e50c1a61eee7bca887224ad583eca60e14d32 (diff)
downloadiced-d62bb8193c1c43f565fcc5c52293d564c91e215d.tar.gz
iced-d62bb8193c1c43f565fcc5c52293d564c91e215d.tar.bz2
iced-d62bb8193c1c43f565fcc5c52293d564c91e215d.zip
Introduce useful helpers in `layout` module
Diffstat (limited to 'widget/src/container.rs')
-rw-r--r--widget/src/container.rs28
1 files changed, 10 insertions, 18 deletions
diff --git a/widget/src/container.rs b/widget/src/container.rs
index 93d8daba..c98de41c 100644
--- a/widget/src/container.rs
+++ b/widget/src/container.rs
@@ -321,27 +321,19 @@ pub fn layout(
vertical_alignment: alignment::Vertical,
layout_content: impl FnOnce(&layout::Limits) -> layout::Node,
) -> layout::Node {
- let limits = limits
- .width(width)
- .height(height)
- .max_width(max_width)
- .max_height(max_height);
-
- let content = layout_content(&limits.shrink(padding).loose());
- let padding = padding.fit(content.size(), limits.max());
- let size = limits
- .shrink(padding)
- .resolve(content.size(), width, height);
-
- layout::Node::with_children(
- size.expand(padding),
- vec![content
- .move_to(Point::new(padding.left, padding.top))
- .align(
+ layout::positioned(
+ &limits.max_width(max_width).max_height(max_height),
+ width,
+ height,
+ padding,
+ |limits| layout_content(&limits.loose()),
+ |content, size| {
+ content.align(
Alignment::from(horizontal_alignment),
Alignment::from(vertical_alignment),
size,
- )],
+ )
+ },
)
}