pub struct Button<'a> {Show 13 fields
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,
image_tint_follows_text_color: 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>
§stroke: Option<Stroke>
§sense: Sense
§small: bool
§frame: Option<bool>
§min_size: Vec2
§rounding: Option<Rounding>
§selected: bool
§image_tint_follows_text_color: bool
Implementations§
§impl<'a> Button<'a>
impl<'a> Button<'a>
pub fn new(text: impl Into<WidgetText>) -> Button<'a>
pub 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.
pub 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>
pub fn wrap_mode(self, wrap_mode: TextWrapMode) -> Button<'a>
pub fn wrap_mode(self, wrap_mode: TextWrapMode) -> Button<'a>
Set the wrap mode for the text.
By default, crate::Ui::wrap_mode
will be used, which can be overridden with crate::Style::wrap_mode
.
Note that any \n
in the text will always produce a new line.
pub fn wrap(self) -> Button<'a>
pub fn wrap(self) -> Button<'a>
Set Self::wrap_mode
to TextWrapMode::Wrap
.
pub 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.
pub 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.
pub 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()
.
pub fn image_tint_follows_text_color(
self,
image_tint_follows_text_color: bool,
) -> Button<'a>
pub fn image_tint_follows_text_color( self, image_tint_follows_text_color: bool, ) -> Button<'a>
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
.
pub 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 crate::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<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request