pub struct Button<'a> { /* private fields */ }
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!();
}
Implementations§
Source§impl<'a> Button<'a>
impl<'a> Button<'a>
pub fn new(text: impl Into<WidgetText>) -> Button<'a>
Sourcepub fn image(image: impl Into<Image<'a>>) -> Button<'a>
pub fn image(image: impl Into<Image<'a>>) -> Button<'a>
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>,
) -> Button<'a>
pub fn image_and_text( image: impl Into<Image<'a>>, text: impl Into<WidgetText>, ) -> Button<'a>
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>, ) -> Button<'a>
Sourcepub fn wrap(self, wrap: bool) -> Button<'a>
pub fn wrap(self, wrap: bool) -> Button<'a>
If true
, the text will wrap to stay within the max width of the Ui
.
By default Self::wrap
will be true in vertical layouts
and horizontal layouts with wrapping,
and false on non-wrapping horizontal layouts.
Note that any \n
in the text will always produce a new line.
Sourcepub fn fill(self, fill: impl Into<Color32>) -> Button<'a>
pub fn fill(self, fill: impl Into<Color32>) -> Button<'a>
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>) -> Button<'a>
pub fn stroke(self, stroke: impl Into<Stroke>) -> Button<'a>
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) -> Button<'a>
pub fn sense(self, sense: Sense) -> Button<'a>
By default, buttons senses clicks.
Change this to a drag-button with Sense::drag()
.
Sourcepub fn rounding(self, rounding: impl Into<Rounding>) -> Button<'a>
pub fn rounding(self, rounding: impl Into<Rounding>) -> Button<'a>
Set the rounding of the button.
Sourcepub fn shortcut_text(self, shortcut_text: impl Into<WidgetText>) -> Button<'a>
pub fn shortcut_text(self, shortcut_text: impl Into<WidgetText>) -> Button<'a>
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
.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Button<'a>
impl<'a> RefUnwindSafe for Button<'a>
impl<'a> Send for Button<'a>
impl<'a> Sync for Button<'a>
impl<'a> Unpin for Button<'a>
impl<'a> UnwindSafe 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
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.