diff options
| author | 2023-02-17 16:53:02 +0100 | |
|---|---|---|
| committer | 2023-02-17 16:53:02 +0100 | |
| commit | 7dc1fb488ddbd12519571b51d75ae0c28875911d (patch) | |
| tree | 92590830b23bb714ec8024766fef7273b041bbf3 /native/src/layout | |
| parent | f75e0202575ca6e3ebf7d817eecbf51e198506fd (diff) | |
| parent | fd1408693322f5bfdaee7f27bd098808658d7310 (diff) | |
| download | iced-7dc1fb488ddbd12519571b51d75ae0c28875911d.tar.gz iced-7dc1fb488ddbd12519571b51d75ae0c28875911d.tar.bz2 iced-7dc1fb488ddbd12519571b51d75ae0c28875911d.zip | |
Merge pull request #1711 from iced-rs/feature/generic-pixel-units
Generic pixel units
Diffstat (limited to '')
| -rw-r--r-- | native/src/layout/flex.rs | 2 | ||||
| -rw-r--r-- | native/src/layout/limits.rs | 42 | 
2 files changed, 18 insertions, 26 deletions
| diff --git a/native/src/layout/flex.rs b/native/src/layout/flex.rs index 94121d76..5d70c2fc 100644 --- a/native/src/layout/flex.rs +++ b/native/src/layout/flex.rs @@ -191,7 +191,7 @@ where          }      } -    let pad = axis.pack(padding.left as f32, padding.top as f32); +    let pad = axis.pack(padding.left, padding.top);      let mut main = pad.0;      for (i, node) in nodes.iter_mut().enumerate() { diff --git a/native/src/layout/limits.rs b/native/src/layout/limits.rs index 4cbb970d..5d3c1556 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,43 +85,36 @@ 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      }      /// Shrinks the current [`Limits`] to account for the given padding.      pub fn pad(&self, padding: Padding) -> Limits { -        self.shrink(Size::new( -            padding.horizontal() as f32, -            padding.vertical() as f32, -        )) +        self.shrink(Size::new(padding.horizontal(), padding.vertical()))      }      /// Shrinks the current [`Limits`] by the given [`Size`]. | 
