MaterialButton

Struct MaterialButton 

Source
pub struct MaterialButton<'a> { /* private fields */ }
Expand description

Material Design button widget implementing Material Design 3 button specifications

This widget provides a button that follows Material Design guidelines including:

  • Proper color schemes for different variants
  • Hover and pressed state animations
  • Material Design typography
  • Accessibility support
  • Icon and text support

Implementations§

Source§

impl<'a> MaterialButton<'a>

Source

pub fn filled(text: impl Into<WidgetText>) -> Self

Create a filled Material Design button with high emphasis

Filled buttons have the most visual impact and should be used for the primary action in a set of buttons.

§Material Design Spec
  • Background: Primary color
  • Text: On-primary color
  • Elevation: 0dp (no shadow)
  • Corner radius: 20dp
Source

pub fn outlined(text: impl Into<WidgetText>) -> Self

Create an outlined Material Design button with medium emphasis

Outlined buttons are medium-emphasis buttons. They contain actions that are important but aren’t the primary action in an app.

§Material Design Spec
  • Background: Transparent
  • Text: Primary color
  • Outline: 1dp primary color
  • Corner radius: 20dp
Source

pub fn text(text: impl Into<WidgetText>) -> Self

Create a text Material Design button with low emphasis

Text buttons are used for the least important actions in a UI. They’re often used for secondary actions.

§Material Design Spec
  • Background: Transparent
  • Text: Primary color
  • No outline or elevation
  • Corner radius: 20dp
Source

pub fn elevated(text: impl Into<WidgetText>) -> Self

Create an elevated Material Design button with medium emphasis

Elevated buttons are essentially filled buttons with a shadow. Use them to add separation between button and background.

§Material Design Spec
  • Background: Surface color
  • Text: Primary color
  • Elevation: 1dp shadow
  • Corner radius: 20dp
Source

pub fn filled_tonal(text: impl Into<WidgetText>) -> Self

Create a filled tonal Material Design button with medium emphasis

Filled tonal buttons are used to convey a secondary action that is still important, but not the primary action.

§Material Design Spec
  • Background: Secondary container color
  • Text: On-secondary-container color
  • Elevation: 0dp (no shadow)
  • Corner radius: 20dp
Source

pub fn new(text: impl Into<WidgetText>) -> Self

Source

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.

Source

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. 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>, ) -> Self

Creates a button with an image. The size of the image as displayed is defined by the provided size.

Use this when you need both or either an image and text, or when text might be None.

§Parameters
  • image: Optional icon/image to display
  • text: Optional text content
Source

pub fn opt_image_and_text_with_variant( variant: MaterialButtonVariant, image: Option<Image<'a>>, text: Option<WidgetText>, ) -> Self

Create a Material Design button with specific variant and optional image and text

This is the most flexible constructor allowing full control over button content.

§Parameters
  • variant: The Material Design button variant to use
  • image: Optional icon/image to display
  • text: Optional text content
Source

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.

Source

pub fn wrap(self) -> Self

Source

pub fn truncate(self) -> Self

Source

pub fn fill(self, fill: impl Into<Color32>) -> Self

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>) -> Self

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) -> Self

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

Source

pub fn frame(self, frame: bool) -> Self

Turn off the frame

Source

pub fn sense(self, sense: Sense) -> Self

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

Source

pub fn min_size(self, min_size: Vec2) -> Self

Set the minimum size of the button.

Source

pub fn corner_radius(self, corner_radius: impl Into<CornerRadius>) -> Self

Set the rounding of the button.

Source

pub fn rounding(self, corner_radius: impl Into<CornerRadius>) -> Self

👎Deprecated: Renamed to corner_radius
Source

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.

Source

pub fn shortcut_text(self, shortcut_text: impl Into<WidgetText>) -> 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.

Source

pub fn selected(self, selected: bool) -> Self

If true, mark this button as “selected”.

Source

pub fn enabled(self, enabled: bool) -> Self

Enable or disable the button.

Source

pub fn elevation(self, elevation: Shadow) -> Self

Set the elevation shadow for the button.

Source

pub fn leading_icon(self, _icon: impl Into<String>) -> Self

Add a leading icon to the button.

Source

pub fn trailing_icon(self, _icon: impl Into<String>) -> Self

Add a trailing icon to the button.

Trait Implementations§

Source§

impl Widget for MaterialButton<'_>

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 MaterialButton<'a>

§

impl<'a> RefUnwindSafe for MaterialButton<'a>

§

impl<'a> Send for MaterialButton<'a>

§

impl<'a> Sync for MaterialButton<'a>

§

impl<'a> Unpin for MaterialButton<'a>

§

impl<'a> UnwindSafe for MaterialButton<'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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

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

Convert 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)

Convert &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)

Convert &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> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<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, 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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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