pub struct Button<'a> { /* private fields */ }Expand description
Clickable themed button, built on egui Atoms.
Reads ButtonVisuals from the installed Theme unless you pass
.visuals(...). Use Button::bg_color for a one-off
idle fill (semantic actions). Chromatic fills should use theme.colors.bg
as the text color so glyphs stay readable.
if ui.add(Button::new("Save")).clicked() {
// …
}Implementations§
Source§impl<'a> Button<'a>
impl<'a> Button<'a>
Sourcepub fn new(atoms: impl IntoAtoms<'a>) -> Self
pub fn new(atoms: impl IntoAtoms<'a>) -> Self
Create a button from atoms (text, images, or a mix).
Sourcepub fn selectable(selected: bool, atoms: impl IntoAtoms<'a>) -> Self
pub fn selectable(selected: bool, atoms: impl IntoAtoms<'a>) -> Self
Show a selectable button.
Equivalent to:
let selected = true;
ui.add(Button::new("toggle me").selected(selected).frame_when_inactive(!selected).frame(true));See also:
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.
Note: In contrast to Button::new, this limits the image size to the default font height
(using egui::AtomExt::atom_max_height_font_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.
Note: In contrast to Button::new, this limits the image size to the default font height
(using egui::AtomExt::atom_max_height_font_size).
Sourcepub fn opt_image_and_text(
image: Option<Image<'a>>,
text: Option<WidgetText>,
) -> Self
pub fn opt_image_and_text( image: Option<Image<'a>>, text: Option<WidgetText>, ) -> Self
Create a button with an optional image and optional text.
Note: In contrast to Button::new, this limits the image size to the default font height
(using egui::AtomExt::atom_max_height_font_size).
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, egui::Ui::wrap_mode will be used, which can be overridden with egui::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 frame_when_inactive(self, frame_when_inactive: bool) -> Self
pub fn frame_when_inactive(self, frame_when_inactive: bool) -> Self
If false, the button will not have a frame when inactive.
Default: true.
Note: When ui.visuals().button_frame is false, this setting
has no effect.
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 image_tint_follows_text_color(
self,
image_tint_follows_text_color: bool,
) -> Self
pub fn image_tint_follows_text_color( self, image_tint_follows_text_color: bool, ) -> Self
If true, the tint of the image is multiplied by the widget text color.
This makes sense for images that are white, that should have the same color as the text color. This will also make the icon color depend on hover state.
Default: false.
Sourcepub fn shortcut_text(self, shortcut_text: impl Into<Atom<'a>>) -> Self
pub fn shortcut_text(self, shortcut_text: impl Into<Atom<'a>>) -> 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 egui::Context::format_shortcut.
See also Self::right_text.
Sourcepub fn right_text(self, right_text: impl Into<Atom<'a>>) -> Self
pub fn right_text(self, right_text: impl Into<Atom<'a>>) -> Self
Show some text on the right side of the button.
Sourcepub fn visuals(self, visuals: ButtonVisuals) -> Self
pub fn visuals(self, visuals: ButtonVisuals) -> Self
Set the visuals of the button
Sourcepub fn atom_ui(self, ui: &mut Ui) -> AtomLayoutResponse
pub fn atom_ui(self, ui: &mut Ui) -> AtomLayoutResponse
Show the button and return a AtomLayoutResponse for painting custom contents.
Trait Implementations§
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Button<'a>
impl<'a> !Send for Button<'a>
impl<'a> !Sync for Button<'a>
impl<'a> !UnwindSafe for Button<'a>
impl<'a> Freeze for Button<'a>
impl<'a> Unpin for Button<'a>
impl<'a> UnsafeUnpin for Button<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more