diff options
author | 2023-01-05 18:51:48 +0100 | |
---|---|---|
committer | 2023-01-05 18:51:48 +0100 | |
commit | 200cf47fe8c1eb1c2ae61a279f28f344af6c1854 (patch) | |
tree | 59ade55418fa25502b1ac24991f095bf665ac927 | |
parent | 43374f1f4e865094032946907dbcf7569ee9487d (diff) | |
download | iced-200cf47fe8c1eb1c2ae61a279f28f344af6c1854.tar.gz iced-200cf47fe8c1eb1c2ae61a279f28f344af6c1854.tar.bz2 iced-200cf47fe8c1eb1c2ae61a279f28f344af6c1854.zip |
Stop using `f32::clamp` altogether in `layout::Limits`
-rw-r--r-- | native/src/layout/limits.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/native/src/layout/limits.rs b/native/src/layout/limits.rs index 0ddee91a..4cbb970d 100644 --- a/native/src/layout/limits.rs +++ b/native/src/layout/limits.rs @@ -1,3 +1,4 @@ +#![allow(clippy::manual_clamp)] use crate::{Length, Padding, Size}; /// A set of size constraints for layouting. @@ -51,7 +52,7 @@ impl Limits { } Length::Units(units) => { let new_width = - (units as f32).clamp(self.min.width, self.max.width); + (units as f32).min(self.max.width).max(self.min.width); self.min.width = new_width; self.max.width = new_width; @@ -73,7 +74,7 @@ impl Limits { } Length::Units(units) => { let new_height = - (units as f32).clamp(self.min.height, self.max.height); + (units as f32).min(self.max.height).max(self.min.height); self.min.height = new_height; self.max.height = new_height; @@ -86,14 +87,16 @@ 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.clamp(min_width as f32, self.max.width); + self.min.width = + self.min.width.max(min_width as f32).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.clamp(self.min.width, max_width as f32); + self.max.width = + self.max.width.min(max_width as f32).max(self.min.width); self } @@ -101,7 +104,7 @@ impl Limits { /// 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.clamp(min_height as f32, self.max.height); + self.min.height.max(min_height as f32).min(self.max.height); self } @@ -109,7 +112,7 @@ impl Limits { /// 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.clamp(self.min.height, max_height as f32); + self.max.height.min(max_height as f32).max(self.min.height); self } @@ -153,7 +156,6 @@ impl Limits { /// Computes the resulting [`Size`] that fits the [`Limits`] given the /// intrinsic size of some content. - #[allow(clippy::manual_clamp)] pub fn resolve(&self, intrinsic_size: Size) -> Size { Size::new( intrinsic_size |