Skip to main content

Button

Struct Button 

Source
pub struct Button { /* private fields */ }
Expand description

Button component styled like shadcn/ui

§Example

use armas_basic::components::{Button, ButtonVariant, ButtonSize};

if Button::new("Save")
    .variant(ButtonVariant::Default)
    .size(ButtonSize::Default)
    .show(ui)
    .clicked()
{
    // handle click
}

Implementations§

Source§

impl Button

Source

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

Create a new button with text

Source

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

Set the button variant

Source

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

Set the button size

Source

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

Set enabled state

Source

pub const fn full_width(self, full: bool) -> Self

Make button take full width of container

Source

pub const fn min_width(self, width: f32) -> Self

Set minimum width for the button

Source

pub const fn height(self, height: f32) -> Self

Set explicit height (overrides size-based height)

Source

pub const fn content_width(self, width: f32) -> Self

Set explicit content area width for custom content buttons.

When using show_ui, this controls the inner width available for the closure. If not set, defaults to a square (height-based) layout.

Source

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

Show the button with a text label.

Source

pub fn show_ui( self, ui: &mut Ui, content: impl FnOnce(&mut Ui, &ContentContext), ) -> Response

Show the button with custom content instead of a text label.

The closure receives a &mut Ui (with override text color set) and a ContentContext with the state-dependent color, font size, and active state.

Use content_width to control the inner width. If not set, the button defaults to a square layout (width = height).

§Example
use armas_basic::components::{Button, ButtonVariant};

// Icon-only button (square)
Button::new("")
    .variant(ButtonVariant::Ghost)
    .show_ui(ui, |ui, ctx| {
        ui.label("X");
    });

// Icon + text button
Button::new("")
    .content_width(80.0)
    .show_ui(ui, |ui, ctx| {
        // render_icon(ui.painter(), my_icon, ctx.color);
        ui.label("Save");
    });

Auto Trait Implementations§

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