pub enum ButtonVariant {
Primary,
Secondary,
Ghost,
Outlined,
Danger,
}Expand description
Button variant for different emphasis levels
Semantic variants communicate importance and action type visually.
Variants§
Primary
High emphasis - inverse colors (Save, Submit, Confirm)
Use for primary actions that are the main call-to-action on a screen.
Secondary
Medium emphasis - subtle background (Cancel, Reset)
Use for secondary actions that support the primary action.
Ghost
Low emphasis - transparent background (default toolbar buttons)
Use for tertiary actions or when you need buttons to blend in.
Outlined
Border stroke - alternative to Secondary
Use when you need a button that’s more prominent than Ghost but less prominent than Secondary.
Danger
Destructive action - red colors (Delete, Remove)
Use for actions that are destructive or irreversible.
Implementations§
Source§impl ButtonVariant
impl ButtonVariant
Sourcepub fn bg_color(&self, ui: &Ui, hovered: bool, pressed: bool) -> Color32
pub fn bg_color(&self, ui: &Ui, hovered: bool, pressed: bool) -> Color32
Get the background color for this variant in the given state.
Primary and Danger use the theme’s opaque state shades. Ghost and Outlined
share egui’s hover and pressed fills; Secondary retains its filled state ladder.
In a disabled ui, Primary and Danger paint as Secondary so fading keeps
their text readable.
Sourcepub fn fg_color(&self, ui: &Ui) -> Color32
pub fn fg_color(&self, ui: &Ui) -> Color32
Get the foreground (text/icon) color for this variant
Sourcepub fn border_color(&self, ui: &Ui) -> Option<Color32>
pub fn border_color(&self, ui: &Ui) -> Option<Color32>
Get the border color for this variant: Outlined, and a disabled Primary, which keeps an accent outline so a disabled selected button still reads as selected
Sourcepub fn apply_to_style(&self, ui: &mut Ui, hovered: bool, active: bool)
pub fn apply_to_style(&self, ui: &mut Ui, hovered: bool, active: bool)
Apply this variant’s styling to ui’s widget visuals
Call it inside ui.scope so the style is restored after rendering the button.
Sourcepub fn is_inverse(&self) -> bool
pub fn is_inverse(&self) -> bool
Check if this variant uses inverse colors (light text on dark bg)
Sourcepub fn has_background(&self) -> bool
pub fn has_background(&self) -> bool
Check if this variant has a visible background
Trait Implementations§
Source§impl Clone for ButtonVariant
impl Clone for ButtonVariant
Source§fn clone(&self) -> ButtonVariant
fn clone(&self) -> ButtonVariant
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ButtonVariant
Source§impl Debug for ButtonVariant
impl Debug for ButtonVariant
Source§impl Default for ButtonVariant
impl Default for ButtonVariant
Source§fn default() -> ButtonVariant
fn default() -> ButtonVariant
impl Eq for ButtonVariant
Source§impl PartialEq for ButtonVariant
impl PartialEq for ButtonVariant
impl StructuralPartialEq for ButtonVariant
Auto Trait Implementations§
impl Freeze for ButtonVariant
impl RefUnwindSafe for ButtonVariant
impl Send for ButtonVariant
impl Sync for ButtonVariant
impl Unpin for ButtonVariant
impl UnsafeUnpin for ButtonVariant
impl UnwindSafe for ButtonVariant
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
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