summaryrefslogtreecommitdiffstats
path: root/native/src/layout
diff options
context:
space:
mode:
authorLibravatar Bingus <shankern@protonmail.com>2023-02-17 11:45:34 -0800
committerLibravatar Bingus <shankern@protonmail.com>2023-02-17 11:45:34 -0800
commit744cef5608a91fe55cbbe1adb73a9a0b5e266668 (patch)
treef88ca6ae3c481e2de74178bb3f0d1f1b685e1740 /native/src/layout
parent8da098330b58542cc929f4f24d02e26bd654bae4 (diff)
parent7dc1fb488ddbd12519571b51d75ae0c28875911d (diff)
downloadiced-744cef5608a91fe55cbbe1adb73a9a0b5e266668.tar.gz
iced-744cef5608a91fe55cbbe1adb73a9a0b5e266668.tar.bz2
iced-744cef5608a91fe55cbbe1adb73a9a0b5e266668.zip
Merge remote-tracking branch 'origin/master' into feat/multi-window-support
# Conflicts: # winit/src/window.rs
Diffstat (limited to 'native/src/layout')
-rw-r--r--native/src/layout/flex.rs2
-rw-r--r--native/src/layout/limits.rs42
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`].