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>
impl<'a> MaterialButton<'a>
Sourcepub fn filled(text: impl Into<WidgetText>) -> Self
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
Sourcepub fn outlined(text: impl Into<WidgetText>) -> Self
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
Sourcepub fn text(text: impl Into<WidgetText>) -> Self
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
Sourcepub fn elevated(text: impl Into<WidgetText>) -> Self
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
Sourcepub fn filled_tonal(text: impl Into<WidgetText>) -> Self
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
pub fn new(text: impl Into<WidgetText>) -> Self
Sourcepub fn image(image: impl Into<Image<'a>>) -> Self
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.
Sourcepub fn image_and_text(
image: impl Into<Image<'a>>,
text: impl Into<WidgetText>,
) -> Self
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.
Sourcepub fn opt_image_and_text(
image: Option<Image<'a>>,
text: Option<WidgetText>,
) -> Self
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 displaytext
: Optional text content
Sourcepub fn opt_image_and_text_with_variant(
variant: MaterialButtonVariant,
image: Option<Image<'a>>,
text: Option<WidgetText>,
) -> Self
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 useimage
: Optional icon/image to displaytext
: Optional text content
Sourcepub fn wrap_mode(self, wrap_mode: TextWrapMode) -> Self
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.
Sourcepub fn wrap(self) -> Self
pub fn wrap(self) -> Self
Set Self::wrap_mode
to TextWrapMode::Wrap
.
Sourcepub fn fill(self, fill: impl Into<Color32>) -> Self
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.
Sourcepub fn stroke(self, stroke: impl Into<Stroke>) -> Self
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.
Sourcepub fn sense(self, sense: Sense) -> Self
pub fn sense(self, sense: Sense) -> Self
By default, buttons senses clicks.
Change this to a drag-button with Sense::drag()
.
Sourcepub fn corner_radius(self, corner_radius: impl Into<CornerRadius>) -> Self
pub fn corner_radius(self, corner_radius: impl Into<CornerRadius>) -> Self
Set the rounding of the button.
pub fn rounding(self, corner_radius: impl Into<CornerRadius>) -> Self
corner_radius
Sourcepub fn image_tint_follows_text_color(
self,
image_tint_follows_text_color: bool,
) -> Self
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
.
Sourcepub fn shortcut_text(self, shortcut_text: impl Into<WidgetText>) -> Self
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
.
Sourcepub fn leading_icon(self, _icon: impl Into<String>) -> Self
pub fn leading_icon(self, _icon: impl Into<String>) -> Self
Add a leading icon to the button.
Sourcepub fn trailing_icon(self, _icon: impl Into<String>) -> Self
pub fn trailing_icon(self, _icon: impl Into<String>) -> Self
Add a trailing icon to the button.
Trait Implementations§
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> 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> 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> DowncastSync for T
impl<T> DowncastSync for T
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 more