mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 13:50:04 -04:00
Add rounding fn to Button, to enable rounded buttons (#2616)
This commit is contained in:
@@ -30,6 +30,7 @@ pub struct Button {
|
||||
small: bool,
|
||||
frame: Option<bool>,
|
||||
min_size: Vec2,
|
||||
rounding: Option<Rounding>,
|
||||
image: Option<widgets::Image>,
|
||||
}
|
||||
|
||||
@@ -45,6 +46,7 @@ impl Button {
|
||||
small: false,
|
||||
frame: None,
|
||||
min_size: Vec2::ZERO,
|
||||
rounding: None,
|
||||
image: None,
|
||||
}
|
||||
}
|
||||
@@ -117,6 +119,12 @@ impl Button {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the rounding of the button.
|
||||
pub fn rounding(mut self, rounding: impl Into<Rounding>) -> Self {
|
||||
self.rounding = Some(rounding.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Show some text on the right side of the button, in weak color.
|
||||
///
|
||||
/// Designed for menu buttons, for setting a keyboard shortcut text (e.g. `Ctrl+S`).
|
||||
@@ -140,6 +148,7 @@ impl Widget for Button {
|
||||
small,
|
||||
frame,
|
||||
min_size,
|
||||
rounding,
|
||||
image,
|
||||
} = self;
|
||||
|
||||
@@ -186,12 +195,9 @@ impl Widget for Button {
|
||||
if frame {
|
||||
let fill = fill.unwrap_or(visuals.bg_fill);
|
||||
let stroke = stroke.unwrap_or(visuals.bg_stroke);
|
||||
ui.painter().rect(
|
||||
rect.expand(visuals.expansion),
|
||||
visuals.rounding,
|
||||
fill,
|
||||
stroke,
|
||||
);
|
||||
let rounding = rounding.unwrap_or(visuals.rounding);
|
||||
ui.painter()
|
||||
.rect(rect.expand(visuals.expansion), rounding, fill, stroke);
|
||||
}
|
||||
|
||||
let text_pos = if let Some(image) = image {
|
||||
|
||||
Reference in New Issue
Block a user