Introduce useful helpers in layout module

This commit is contained in:
Héctor Ramón Jiménez 2024-01-09 06:35:33 +01:00
parent d24e50c1a6
commit d62bb8193c
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
26 changed files with 189 additions and 127 deletions

View file

@ -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);
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
},
),
);
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::Node::with_children(size, vec![content])
layout_content(renderer, &child_limits)
})
}
/// Processes an [`Event`] and updates the [`State`] of a [`Scrollable`]