Skip to main content

Button

Struct Button 

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

A button widget with support for semantic variants

Button provides distinct visual variants that communicate different levels of importance and action types.

§Example

use egui_charts::icons::icons;
use egui_charts::ui_kit::buttons::Button;

// Primary button (high emphasis)
if Button::new("Save Changes").primary().show(ui).clicked() {
    // save
}

// Ghost button with icon (low emphasis)
Button::icon_and_text(&icons::SETTINGS, "Settings")
    .ghost()
    .show(ui);

// Danger button (destructive action)
Button::new("Delete")
    .danger()
    .show(ui);

Implementations§

Source§

impl<'a> Button<'a>

Source

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

Create a new button with text

Source

pub fn icon(icon: &'a Icon) -> Self

Create a new button with only an icon

Source

pub fn icon_and_text(icon: &'a Icon, text: impl Into<String>) -> Self

Create a new button with both icon and text

Source

pub fn variant(self, variant: ButtonVariant) -> Self

Set the button variant

Source

pub fn primary(self) -> Self

Make this a primary button (high emphasis)

Source

pub fn secondary(self) -> Self

Make this a secondary button (medium emphasis)

Source

pub fn ghost(self) -> Self

Make this a ghost button (low emphasis, transparent)

Source

pub fn outlined(self) -> Self

Make this an outlined button (border stroke)

Source

pub fn danger(self) -> Self

Make this a danger button (destructive action)

Source

pub fn text_color(self, color: Color32) -> Self

Override only the label colour, retaining the variant’s fill and icon colour.

Source

pub fn size(self, size: ButtonSize) -> Self

Set the button size

Source

pub fn small(self) -> Self

Make this a small button

Source

pub fn large(self) -> Self

Make this a large button

Source

pub fn tooltip(self, text: impl Into<String>) -> Self

Set the tooltip text

Source

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

Set whether the button is enabled

Source

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

Set whether the button appears selected/active

Source

pub fn icon_scale(self, scale: f32) -> Self

Set the icon size as a fraction of the button height (0.1-1.0).

By default the icon is 16, 20 or 24 px for small, medium and larger buttons.

Source

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

Show the button and return the response

Trait Implementations§

Source§

impl<'a> Widget for Button<'a>

Source§

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

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

fn boxed<'a>(self) -> Box<dyn FnOnce(&mut Ui) -> Response + 'a>
where Self: Sized + 'a,

Box this widget for dynamic dispatch.

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

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> MaybeSend for T
where T: Send + Sync + ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

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.