diff options
author | 2024-01-09 06:35:33 +0100 | |
---|---|---|
committer | 2024-01-10 10:01:49 +0100 | |
commit | d62bb8193c1c43f565fcc5c52293d564c91e215d (patch) | |
tree | 7f2d33d2f18a3dfb4e4e8e46b4e968523ca43bc6 /widget/src/scrollable.rs | |
parent | d24e50c1a61eee7bca887224ad583eca60e14d32 (diff) | |
download | iced-d62bb8193c1c43f565fcc5c52293d564c91e215d.tar.gz iced-d62bb8193c1c43f565fcc5c52293d564c91e215d.tar.bz2 iced-d62bb8193c1c43f565fcc5c52293d564c91e215d.zip |
Introduce useful helpers in `layout` module
Diffstat (limited to 'widget/src/scrollable.rs')
-rw-r--r-- | widget/src/scrollable.rs | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 5197afde..70db490a 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -469,28 +469,25 @@ pub fn layout<Renderer>( direction: &Direction, layout_content: impl FnOnce(&Renderer, &layout::Limits) -> layout::Node, ) -> layout::Node { - let limits = limits.width(width).height(height); - - let child_limits = layout::Limits::new( - Size::new(limits.min().width, limits.min().height), - Size::new( - if direction.horizontal().is_some() { - f32::INFINITY - } else { - limits.max().width - }, - if direction.vertical().is_some() { - f32::MAX - } else { - limits.max().height - }, - ), - ); - - let content = layout_content(renderer, &child_limits); - let size = limits.resolve(content.size(), width, height); + layout::contained(limits, width, height, |limits| { + let child_limits = layout::Limits::new( + Size::new(limits.min().width, limits.min().height), + Size::new( + if direction.horizontal().is_some() { + f32::INFINITY + } else { + limits.max().width + }, + if direction.vertical().is_some() { + f32::MAX + } else { + limits.max().height + }, + ), + ); - layout::Node::with_children(size, vec![content]) + layout_content(renderer, &child_limits) + }) } /// Processes an [`Event`] and updates the [`State`] of a [`Scrollable`] |