Merge pull request #1390 from iced-rs/fix/container-layout

Fix `max_width` and `max_height` for `Container`
This commit is contained in:
Héctor Ramón 2022-07-19 18:34:39 +02:00 committed by GitHub
commit 785385d889
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 2 deletions

View file

@ -127,12 +127,20 @@ pub fn layout<Renderer>(
limits: &layout::Limits,
width: Length,
height: Length,
max_width: u32,
max_height: u32,
padding: Padding,
horizontal_alignment: alignment::Horizontal,
vertical_alignment: alignment::Vertical,
layout_content: impl FnOnce(&Renderer, &layout::Limits) -> layout::Node,
) -> layout::Node {
let limits = limits.loose().width(width).height(height).pad(padding);
let limits = limits
.loose()
.max_width(max_width)
.max_height(max_height)
.width(width)
.height(height)
.pad(padding);
let mut content = layout_content(renderer, &limits.loose());
let size = limits.resolve(content.size());
@ -171,6 +179,8 @@ where
limits,
self.width,
self.height,
self.max_width,
self.max_height,
self.padding,
self.horizontal_alignment,
self.vertical_alignment,

View file

@ -162,9 +162,10 @@ pub fn layout<Renderer>(
limits: &layout::Limits,
width: Length,
height: Length,
max_height: u32,
layout_content: impl FnOnce(&Renderer, &layout::Limits) -> layout::Node,
) -> layout::Node {
let limits = limits.width(width).height(height);
let limits = limits.max_height(max_height).width(width).height(height);
let child_limits = layout::Limits::new(
Size::new(limits.min().width, 0.0),
@ -648,6 +649,7 @@ where
limits,
Widget::<Message, Renderer>::width(self),
self.height,
self.max_height,
|renderer, limits| self.content.layout(renderer, limits),
)
}

View file

@ -156,6 +156,8 @@ where
limits,
self.width,
self.height,
self.max_width,
self.max_height,
self.padding,
self.horizontal_alignment,
self.vertical_alignment,

View file

@ -133,6 +133,7 @@ where
limits,
Widget::<Message, Renderer>::width(self),
self.height,
u32::MAX,
|renderer, limits| {
self.content.as_widget().layout(renderer, limits)
},