summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2023-01-05 19:05:41 +0100
committerLibravatar GitHub <noreply@github.com>2023-01-05 19:05:41 +0100
commitba20ac8e49aedfa9d822d71784587d0635cec4f8 (patch)
treef76504a780e22d990471e81db1a695fbbbfae6d2
parentd29849df79ede48bafd6276b81d79eb5464af33b (diff)
parent200cf47fe8c1eb1c2ae61a279f28f344af6c1854 (diff)
downloadiced-ba20ac8e49aedfa9d822d71784587d0635cec4f8.tar.gz
iced-ba20ac8e49aedfa9d822d71784587d0635cec4f8.tar.bz2
iced-ba20ac8e49aedfa9d822d71784587d0635cec4f8.zip
Merge pull request #1639 from iced-rs/fix/limits-clamp
Stop using `f32::clamp` altogether in `layout::Limits`
-rw-r--r--native/src/layout/limits.rs16
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