Skip to content

Commit

Permalink
feat(container): add min_height and min_height
Browse files Browse the repository at this point in the history
  • Loading branch information
mmstick committed Sep 23, 2024
1 parent 74e9a62 commit 733cec7
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion widget/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ pub struct Container<
padding: Padding,
width: Length,
height: Length,
min_width: f32,
max_width: f32,
min_height: f32,
max_height: f32,
horizontal_alignment: alignment::Horizontal,
vertical_alignment: alignment::Vertical,
Expand All @@ -57,7 +59,9 @@ where
padding: Padding::ZERO,
width: size.width.fluid(),
height: size.height.fluid(),
min_width: 0.0,
max_width: f32::INFINITY,
min_height: 0.0,
max_height: f32::INFINITY,
horizontal_alignment: alignment::Horizontal::Left,
vertical_alignment: alignment::Vertical::Top,
Expand All @@ -84,12 +88,24 @@ where
self
}

/// Sets the minimum width of the [`Container`].
pub fn min_width(mut self, min_width: impl Into<Pixels>) -> Self {
self.min_width = min_width.into().0;
self
}

/// Sets the maximum width of the [`Container`].
pub fn max_width(mut self, max_width: impl Into<Pixels>) -> Self {
self.max_width = max_width.into().0;
self
}

/// Sets the minimum height of the [`Container`].
pub fn min_height(mut self, min_height: impl Into<Pixels>) -> Self {
self.min_height = min_height.into().0;
self
}

/// Sets the maximum height of the [`Container`].
pub fn max_height(mut self, max_height: impl Into<Pixels>) -> Self {
self.max_height = max_height.into().0;
Expand Down Expand Up @@ -166,7 +182,9 @@ where
limits,
self.width,
self.height,
self.min_width,
self.max_width,
self.min_height,
self.max_height,
self.padding,
self.horizontal_alignment,
Expand Down Expand Up @@ -347,15 +365,21 @@ pub fn layout(
limits: &layout::Limits,
width: Length,
height: Length,
min_width: f32,
max_width: f32,
min_height: f32,
max_height: f32,
padding: Padding,
horizontal_alignment: alignment::Horizontal,
vertical_alignment: alignment::Vertical,
layout_content: impl FnOnce(&layout::Limits) -> layout::Node,
) -> layout::Node {
layout::positioned(
&limits.max_width(max_width).max_height(max_height),
&limits
.min_width(min_width)
.max_width(max_width)
.min_height(min_height)
.max_height(max_height),
width,
height,
padding,
Expand Down

0 comments on commit 733cec7

Please sign in to comment.