Use f32 in Length::Units and rename it to Fixed

This commit is contained in:
Héctor Ramón Jiménez 2023-02-04 12:24:13 +01:00
parent f75e020257
commit 7b8b01f560
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
43 changed files with 269 additions and 262 deletions

View file

@ -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
}