Merge pull request #1639 from iced-rs/fix/limits-clamp
Stop using `f32::clamp` altogether in `layout::Limits`
This commit is contained in:
commit
ba20ac8e49
1 changed files with 9 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue