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(atoms: impl IntoAtoms<'a>) -> Button<'a>
Sourcepub fn selectable(selected: bool, atoms: impl IntoAtoms<'a>) -> Button<'a>
pub fn selectable(selected: bool, atoms: impl IntoAtoms<'a>) -> Button<'a>
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>>) -> 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.
Note: In contrast to Button::new, this limits the image size to the default font height
(using crate::AtomExt::atom_max_height_font_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.
Note: In contrast to Button::new, this limits the image size to the default font height
(using crate::AtomExt::atom_max_height_font_size).
Sourcepub fn opt_image_and_text(
image: Option<Image<'a>>,
text: Option<WidgetText>,
) -> Button<'a>
pub fn opt_image_and_text( image: Option<Image<'a>>, text: Option<WidgetText>, ) -> Button<'a>
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 crate::AtomExt::atom_max_height_font_size).
Sourcepub 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.
Sourcepub fn wrap(self) -> Button<'a>
pub fn wrap(self) -> Button<'a>
Set Self::wrap_mode to TextWrapMode::Wrap.
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 frame_when_inactive(self, frame_when_inactive: bool) -> Button<'a>
pub fn frame_when_inactive(self, frame_when_inactive: bool) -> Button<'a>
If false, the button will not have a frame when inactive.
Default: true.
Note: When Self::frame (or ui.visuals().button_frame) is false, this setting
has no effect.
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 corner_radius(self, corner_radius: impl Into<CornerRadius>) -> Button<'a>
pub fn corner_radius(self, corner_radius: impl Into<CornerRadius>) -> Button<'a>
Set the rounding of the button.
pub fn rounding(self, corner_radius: impl Into<CornerRadius>) -> Button<'a>
Renamed to corner_radius
Sourcepub 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.
Sourcepub fn shortcut_text(self, shortcut_text: impl IntoAtoms<'a>) -> Button<'a>
pub fn shortcut_text(self, shortcut_text: impl IntoAtoms<'a>) -> 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.
See also Self::right_text.
Sourcepub fn left_text(self, left_text: impl IntoAtoms<'a>) -> Button<'a>
pub fn left_text(self, left_text: impl IntoAtoms<'a>) -> Button<'a>
Show some text on the left side of the button.
Sourcepub fn right_text(self, right_text: impl IntoAtoms<'a>) -> Button<'a>
pub fn right_text(self, right_text: impl IntoAtoms<'a>) -> Button<'a>
Show some text on the right side 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§
Source§impl<'a> ReButtonExt<'a> for Button<'a>
impl<'a> ReButtonExt<'a> for Button<'a>
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> UnsafeUnpin 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<'a, T> BoxedWidgetLocalExt<'a> for Twhere
T: 'a + Widget,
impl<'a, T> BoxedWidgetLocalExt<'a> for Twhere
T: 'a + Widget,
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>
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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.Source§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.Source§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.Source§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.Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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::RequestSource§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
Source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
Source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Source§impl<'a, T> OnResponseExt<'a> for Twhere
T: Widget,
impl<'a, T> OnResponseExt<'a> for Twhere
T: Widget,
type Target = T
fn into_on_response(self) -> OnResponse<'a, <T as OnResponseExt<'a>>::Target>
Source§fn on_response(
self,
on_response: impl FnOnce(Response) -> Response + 'a,
) -> OnResponse<'a, Self::Target>
fn on_response( self, on_response: impl FnOnce(Response) -> Response + 'a, ) -> OnResponse<'a, Self::Target>
Source§fn on_click(self, on_click: impl FnOnce() + 'a) -> OnResponse<'a, Self::Target>
fn on_click(self, on_click: impl FnOnce() + 'a) -> OnResponse<'a, Self::Target>
Source§fn on_hover_ui(
self,
on_hover_ui: impl FnOnce(&mut Ui) + 'a,
) -> OnResponse<'a, Self::Target>
fn on_hover_ui( self, on_hover_ui: impl FnOnce(&mut Ui) + 'a, ) -> OnResponse<'a, Self::Target>
Source§fn on_disabled_hover_ui(
self,
on_hover_ui: impl FnOnce(&mut Ui) + 'a,
) -> OnResponse<'a, Self::Target>
fn on_disabled_hover_ui( self, on_hover_ui: impl FnOnce(&mut Ui) + 'a, ) -> OnResponse<'a, Self::Target>
Source§fn on_hover_text(
self,
hover_text: impl Into<WidgetText> + 'a,
) -> OnResponse<'a, Self::Target>
fn on_hover_text( self, hover_text: impl Into<WidgetText> + 'a, ) -> OnResponse<'a, Self::Target>
Source§fn on_disabled_hover_text(
self,
hover_text: impl Into<WidgetText> + 'a,
) -> OnResponse<'a, Self::Target>
fn on_disabled_hover_text( self, hover_text: impl Into<WidgetText> + 'a, ) -> OnResponse<'a, Self::Target>
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<T> StrictAs for T
impl<T> StrictAs for T
Source§fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
Source§impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
Source§fn strict_cast_from(src: Src) -> Dst
fn strict_cast_from(src: Src) -> Dst
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.