mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 14:20:04 -04:00
Add rounding fn to Button, to enable rounded buttons (#2616)
This commit is contained in:
@@ -13,6 +13,7 @@ NOTE: [`epaint`](crates/epaint/CHANGELOG.md), [`eframe`](crates/eframe/CHANGELOG
|
|||||||
* Add `ScrollArea::drag_to_scroll` if you want to turn off that feature.
|
* Add `ScrollArea::drag_to_scroll` if you want to turn off that feature.
|
||||||
* Add `Response::on_hover_and_drag_cursor`.
|
* Add `Response::on_hover_and_drag_cursor`.
|
||||||
* Add `Window::default_open` ([#2539](https://github.com/emilk/egui/pull/2539))
|
* Add `Window::default_open` ([#2539](https://github.com/emilk/egui/pull/2539))
|
||||||
|
* Add `Button::rounding` to enable round buttons ([#2539](https://github.com/emilk/egui/pull/2539))
|
||||||
|
|
||||||
### Changed 🔧
|
### Changed 🔧
|
||||||
* Improved plot grid appearance ([#2412](https://github.com/emilk/egui/pull/2412)).
|
* Improved plot grid appearance ([#2412](https://github.com/emilk/egui/pull/2412)).
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ pub struct Button {
|
|||||||
small: bool,
|
small: bool,
|
||||||
frame: Option<bool>,
|
frame: Option<bool>,
|
||||||
min_size: Vec2,
|
min_size: Vec2,
|
||||||
|
rounding: Option<Rounding>,
|
||||||
image: Option<widgets::Image>,
|
image: Option<widgets::Image>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@ impl Button {
|
|||||||
small: false,
|
small: false,
|
||||||
frame: None,
|
frame: None,
|
||||||
min_size: Vec2::ZERO,
|
min_size: Vec2::ZERO,
|
||||||
|
rounding: None,
|
||||||
image: None,
|
image: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,6 +119,12 @@ impl Button {
|
|||||||
self
|
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.
|
/// 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`).
|
/// Designed for menu buttons, for setting a keyboard shortcut text (e.g. `Ctrl+S`).
|
||||||
@@ -140,6 +148,7 @@ impl Widget for Button {
|
|||||||
small,
|
small,
|
||||||
frame,
|
frame,
|
||||||
min_size,
|
min_size,
|
||||||
|
rounding,
|
||||||
image,
|
image,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
@@ -186,12 +195,9 @@ impl Widget for Button {
|
|||||||
if frame {
|
if frame {
|
||||||
let fill = fill.unwrap_or(visuals.bg_fill);
|
let fill = fill.unwrap_or(visuals.bg_fill);
|
||||||
let stroke = stroke.unwrap_or(visuals.bg_stroke);
|
let stroke = stroke.unwrap_or(visuals.bg_stroke);
|
||||||
ui.painter().rect(
|
let rounding = rounding.unwrap_or(visuals.rounding);
|
||||||
rect.expand(visuals.expansion),
|
ui.painter()
|
||||||
visuals.rounding,
|
.rect(rect.expand(visuals.expansion), rounding, fill, stroke);
|
||||||
fill,
|
|
||||||
stroke,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let text_pos = if let Some(image) = image {
|
let text_pos = if let Some(image) = image {
|
||||||
|
|||||||
Reference in New Issue
Block a user