1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 12:50:04 -04:00

Add Rounding::at_least and Rounding::at_most

This commit is contained in:
Emil Ernerfeldt
2022-04-27 10:05:09 +02:00
parent e3b77e320a
commit 06802cb0a0
3 changed files with 24 additions and 13 deletions

View File

@@ -535,6 +535,28 @@ impl Rounding {
pub fn is_same(&self) -> bool {
self.nw == self.ne && self.nw == self.sw && self.nw == self.se
}
/// Make sure each corner has a rounding of at least this.
#[inline]
pub fn at_least(&self, min: f32) -> Self {
Self {
nw: self.nw.max(min),
ne: self.ne.max(min),
sw: self.sw.max(min),
se: self.se.max(min),
}
}
/// Make sure each corner has a rounding of at most this.
#[inline]
pub fn at_most(&self, max: f32) -> Self {
Self {
nw: self.nw.min(max),
ne: self.ne.min(max),
sw: self.sw.min(max),
se: self.se.min(max),
}
}
}
// ----------------------------------------------------------------------------

View File

@@ -257,13 +257,7 @@ pub mod path {
let half_width = rect.width() * 0.5;
let half_height = rect.height() * 0.5;
let max_cr = half_width.min(half_height);
Rounding {
nw: rounding.nw.at_most(max_cr).at_least(0.0),
ne: rounding.ne.at_most(max_cr).at_least(0.0),
sw: rounding.sw.at_most(max_cr).at_least(0.0),
se: rounding.se.at_most(max_cr).at_least(0.0),
}
rounding.at_most(max_cr).at_least(0.0)
}
}