Add Rounding::at_least and Rounding::at_most
This commit is contained in:
parent
e3b77e320a
commit
06802cb0a0
3 changed files with 24 additions and 13 deletions
|
@ -90,13 +90,8 @@ fn color_button(ui: &mut Ui, color: Color32, open: bool) -> Response {
|
|||
ui.painter().rect_filled(left_half, 0.0, color);
|
||||
ui.painter().rect_filled(right_half, 0.0, color.to_opaque());
|
||||
|
||||
let rounding = Rounding {
|
||||
nw: visuals.rounding.nw.at_most(2.0),
|
||||
ne: visuals.rounding.ne.at_most(2.0),
|
||||
sw: visuals.rounding.sw.at_most(2.0),
|
||||
se: visuals.rounding.se.at_most(2.0),
|
||||
};
|
||||
|
||||
let rounding = visuals.rounding.at_most(2.0);
|
||||
ui.painter()
|
||||
.rect_stroke(rect, rounding, (2.0, visuals.bg_fill)); // fill is intentional, because default style has no border
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue