-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Constrain padding to resolved inner / outer widget sizes #1494
Changes from all commits
2c103f8
ea4b3cd
7476663
914f099
24d031b
04087b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,22 @@ impl Size { | |
height: self.height + padding.vertical() as f32, | ||
} | ||
} | ||
|
||
/// Returns the minimum of each component of this size and another | ||
pub fn min(self, other: Self) -> Self { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was just thinking that I wanted to add this to Iced the other day. Yay 🥳 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be worth to use euclid for geometric primitives. It also allow to create different types for different coordinate systems in order to not mix them. |
||
Size { | ||
width: self.width.min(other.width), | ||
height: self.height.min(other.height), | ||
} | ||
} | ||
|
||
/// Returns the maximum of each component of this size and another | ||
pub fn max(self, other: Self) -> Self { | ||
Size { | ||
width: self.width.max(other.width), | ||
height: self.height.max(other.height), | ||
} | ||
} | ||
} | ||
|
||
impl From<[f32; 2]> for Size { | ||
|
@@ -68,3 +84,14 @@ impl From<Size> for Vector<f32> { | |
Vector::new(size.width, size.height) | ||
} | ||
} | ||
|
||
impl std::ops::Sub for Size { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. while ur in here, a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure these make sense for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Area is the big thing I was working with the other day, yeah. Probably could be a separate struct though. |
||
type Output = Size; | ||
|
||
fn sub(self, rhs: Self) -> Self::Output { | ||
Size { | ||
width: self.width - rhs.width, | ||
height: self.height - rhs.height, | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed these lines so we perform the cast to
u16
first and then divide by 2. Integer division by 2 is way faster, and I believe both approaches produce equivalent results in the end.