summaryrefslogtreecommitdiffstats
path: root/native/src/layout
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-02-04 12:24:13 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-02-17 15:40:17 +0100
commit7b8b01f560569ae18d9337a31ba94f6c1c2ba0dd (patch)
treeac9aac5eb82f175990da17813985d2f864897080 /native/src/layout
parentf75e0202575ca6e3ebf7d817eecbf51e198506fd (diff)
downloadiced-7b8b01f560569ae18d9337a31ba94f6c1c2ba0dd.tar.gz
iced-7b8b01f560569ae18d9337a31ba94f6c1c2ba0dd.tar.bz2
iced-7b8b01f560569ae18d9337a31ba94f6c1c2ba0dd.zip
Use `f32` in `Length::Units` and rename it to `Fixed`
Diffstat (limited to 'native/src/layout')
-rw-r--r--native/src/layout/limits.rs37
1 files changed, 16 insertions, 21 deletions
diff --git a/native/src/layout/limits.rs b/native/src/layout/limits.rs
index 4cbb970d..137a054c 100644
--- a/native/src/layout/limits.rs
+++ b/native/src/layout/limits.rs
@@ -42,17 +42,16 @@ impl Limits {
}
/// Applies a width constraint to the current [`Limits`].
- pub fn width(mut self, width: Length) -> Limits {
- match width {
+ pub fn width(mut self, width: impl Into<Length>) -> Limits {
+ match width.into() {
Length::Shrink => {
self.fill.width = self.min.width;
}
Length::Fill | Length::FillPortion(_) => {
self.fill.width = self.fill.width.min(self.max.width);
}
- Length::Units(units) => {
- let new_width =
- (units as f32).min(self.max.width).max(self.min.width);
+ Length::Fixed(amount) => {
+ let new_width = amount.min(self.max.width).max(self.min.width);
self.min.width = new_width;
self.max.width = new_width;
@@ -64,17 +63,17 @@ impl Limits {
}
/// Applies a height constraint to the current [`Limits`].
- pub fn height(mut self, height: Length) -> Limits {
- match height {
+ pub fn height(mut self, height: impl Into<Length>) -> Limits {
+ match height.into() {
Length::Shrink => {
self.fill.height = self.min.height;
}
Length::Fill | Length::FillPortion(_) => {
self.fill.height = self.fill.height.min(self.max.height);
}
- Length::Units(units) => {
+ Length::Fixed(amount) => {
let new_height =
- (units as f32).min(self.max.height).max(self.min.height);
+ amount.min(self.max.height).max(self.min.height);
self.min.height = new_height;
self.max.height = new_height;
@@ -86,33 +85,29 @@ impl Limits {
}
/// Applies a minimum width constraint to the current [`Limits`].
- pub fn min_width(mut self, min_width: u32) -> Limits {
- self.min.width =
- self.min.width.max(min_width as f32).min(self.max.width);
+ pub fn min_width(mut self, min_width: f32) -> Limits {
+ self.min.width = self.min.width.max(min_width).min(self.max.width);
self
}
/// Applies a maximum width constraint to the current [`Limits`].
- pub fn max_width(mut self, max_width: u32) -> Limits {
- self.max.width =
- self.max.width.min(max_width as f32).max(self.min.width);
+ pub fn max_width(mut self, max_width: f32) -> Limits {
+ self.max.width = self.max.width.min(max_width).max(self.min.width);
self
}
/// Applies a minimum height constraint to the current [`Limits`].
- pub fn min_height(mut self, min_height: u32) -> Limits {
- self.min.height =
- self.min.height.max(min_height as f32).min(self.max.height);
+ pub fn min_height(mut self, min_height: f32) -> Limits {
+ self.min.height = self.min.height.max(min_height).min(self.max.height);
self
}
/// Applies a maximum height constraint to the current [`Limits`].
- pub fn max_height(mut self, max_height: u32) -> Limits {
- self.max.height =
- self.max.height.min(max_height as f32).max(self.min.height);
+ pub fn max_height(mut self, max_height: f32) -> Limits {
+ self.max.height = self.max.height.min(max_height).max(self.min.height);
self
}