pub struct Button<'a> {
image: Option<Image<'a>>,
text: Option<WidgetText>,
shortcut_text: WidgetText,
wrap_mode: Option<TextWrapMode>,
fill: Option<Color32>,
stroke: Option<Stroke>,
sense: Sense,
small: bool,
frame: Option<bool>,
min_size: Vec2,
rounding: Option<Rounding>,
selected: bool,
}
Expand description
Clickable button with text.
See also Ui::button
.
if ui.add(egui::Button::new("Click me")).clicked() {
do_stuff();
}
// A greyed-out and non-interactive button:
if ui.add_enabled(false, egui::Button::new("Can't click this")).clicked() {
unreachable!();
}
Fields§
§image: Option<Image<'a>>
§text: Option<WidgetText>
§shortcut_text: WidgetText
§wrap_mode: Option<TextWrapMode>
§fill: Option<Color32>
None means default for interact
stroke: Option<Stroke>
§sense: Sense
§small: bool
§frame: Option<bool>
§min_size: Vec2
§rounding: Option<Rounding>
§selected: bool
Implementations§
source§impl<'a> Button<'a>
impl<'a> Button<'a>
pub fn new(text: impl Into<WidgetText>) -> Self
sourcepub fn image(image: impl Into<Image<'a>>) -> Self
pub fn image(image: impl Into<Image<'a>>) -> Self
Creates a button with an image. The size of the image as displayed is defined by the provided size.
sourcepub fn image_and_text(
image: impl Into<Image<'a>>,
text: impl Into<WidgetText>,
) -> Self
pub fn image_and_text( image: impl Into<Image<'a>>, text: impl Into<WidgetText>, ) -> Self
Creates a button with an image to the left of the text. The size of the image as displayed is defined by the provided size.
pub fn opt_image_and_text( image: Option<Image<'a>>, text: Option<WidgetText>, ) -> Self
sourcepub fn wrap_mode(self, wrap_mode: TextWrapMode) -> Self
pub fn wrap_mode(self, wrap_mode: TextWrapMode) -> Self
Set the wrap mode for the text.
By default, Ui::wrap_mode
will be used, which can be overridden with Style::wrap_mode
.
Note that any \n
in the text will always produce a new line.
sourcepub fn wrap(self) -> Self
pub fn wrap(self) -> Self
Set Self::wrap_mode
to TextWrapMode::Wrap
.
sourcepub fn fill(self, fill: impl Into<Color32>) -> Self
pub fn fill(self, fill: impl Into<Color32>) -> Self
Override background fill color. Note that this will override any on-hover effects. Calling this will also turn on the frame.
sourcepub fn stroke(self, stroke: impl Into<Stroke>) -> Self
pub fn stroke(self, stroke: impl Into<Stroke>) -> Self
Override button stroke. Note that this will override any on-hover effects. Calling this will also turn on the frame.
sourcepub fn sense(self, sense: Sense) -> Self
pub fn sense(self, sense: Sense) -> Self
By default, buttons senses clicks.
Change this to a drag-button with Sense::drag()
.
sourcepub fn shortcut_text(self, shortcut_text: impl Into<WidgetText>) -> Self
pub fn shortcut_text(self, shortcut_text: impl Into<WidgetText>) -> 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
).
The text can be created with Context::format_shortcut
.