[button] Add ability to turn off button frame
This commit is contained in:
parent
84f06ed09a
commit
02b1e82a6e
1 changed files with 22 additions and 7 deletions
|
@ -288,6 +288,7 @@ pub struct Button {
|
||||||
fill: Option<Srgba>,
|
fill: Option<Srgba>,
|
||||||
sense: Sense,
|
sense: Sense,
|
||||||
small: bool,
|
small: bool,
|
||||||
|
frame: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Button {
|
impl Button {
|
||||||
|
@ -299,6 +300,7 @@ impl Button {
|
||||||
fill: Default::default(),
|
fill: Default::default(),
|
||||||
sense: Sense::click(),
|
sense: Sense::click(),
|
||||||
small: false,
|
small: false,
|
||||||
|
frame: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,6 +331,12 @@ impl Button {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Turn off the frame
|
||||||
|
pub fn frame(mut self, frame: bool) -> Self {
|
||||||
|
self.frame = frame;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// By default, buttons senses clicks.
|
/// By default, buttons senses clicks.
|
||||||
/// Change this to a drag-button with `Sense::drag()`.
|
/// Change this to a drag-button with `Sense::drag()`.
|
||||||
pub fn sense(mut self, sense: Sense) -> Self {
|
pub fn sense(mut self, sense: Sense) -> Self {
|
||||||
|
@ -355,6 +363,7 @@ impl Widget for Button {
|
||||||
fill,
|
fill,
|
||||||
sense,
|
sense,
|
||||||
small,
|
small,
|
||||||
|
frame,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let mut button_padding = ui.style().spacing.button_padding;
|
let mut button_padding = ui.style().spacing.button_padding;
|
||||||
|
@ -379,23 +388,29 @@ impl Widget for Button {
|
||||||
|
|
||||||
let id = ui.make_position_id();
|
let id = ui.make_position_id();
|
||||||
let response = ui.interact(rect, id, sense);
|
let response = ui.interact(rect, id, sense);
|
||||||
|
|
||||||
let visuals = ui.style().interact(&response);
|
let visuals = ui.style().interact(&response);
|
||||||
let text_cursor = ui
|
let text_cursor = ui
|
||||||
.layout()
|
.layout()
|
||||||
.align_size_within_rect(galley.size, response.rect.shrink2(button_padding))
|
.align_size_within_rect(galley.size, response.rect.shrink2(button_padding))
|
||||||
.min;
|
.min;
|
||||||
let fill = fill.unwrap_or(visuals.bg_fill);
|
|
||||||
ui.painter().rect(
|
if frame {
|
||||||
response.rect,
|
let fill = fill.unwrap_or(visuals.bg_fill);
|
||||||
visuals.corner_radius,
|
ui.painter().rect(
|
||||||
fill,
|
response.rect,
|
||||||
visuals.bg_stroke,
|
visuals.corner_radius,
|
||||||
);
|
fill,
|
||||||
|
visuals.bg_stroke,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let text_color = text_color
|
let text_color = text_color
|
||||||
.or(ui.style().visuals.override_text_color)
|
.or(ui.style().visuals.override_text_color)
|
||||||
.unwrap_or_else(|| visuals.text_color());
|
.unwrap_or_else(|| visuals.text_color());
|
||||||
ui.painter()
|
ui.painter()
|
||||||
.galley(text_cursor, galley, text_style, text_color);
|
.galley(text_cursor, galley, text_style, text_color);
|
||||||
|
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue