Struct Button

Source
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>

Source

pub fn new(text: impl Into<WidgetText>) -> Button<'a>

Source

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.

Source

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.

Source

pub fn opt_image_and_text( image: Option<Image<'a>>, text: Option<WidgetText>, ) -> Button<'a>

Source

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.

Source

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.

Source

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.

Source

pub fn small(self) -> Button<'a>

Make this a small button, suitable for embedding into text.

Source

pub fn frame(self, frame: bool) -> Button<'a>

Turn off the frame

Source

pub fn sense(self, sense: Sense) -> Button<'a>

By default, buttons senses clicks. Change this to a drag-button with Sense::drag().

Source

pub fn min_size(self, min_size: Vec2) -> Button<'a>

Set the minimum size of the button.

Source

pub fn rounding(self, rounding: impl Into<Rounding>) -> Button<'a>

Set the rounding of the button.

Source

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.

Source

pub fn selected(self, selected: bool) -> Button<'a>

If true, mark this button as “selected”.

Trait Implementations§

Source§

impl Widget for Button<'_>

Source§

fn ui(self, ui: &mut Ui) -> Response

Allocate space, interact, paint, and return a Response. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,