Skip to main content

Button

Struct Button 

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

A clickable button widget

Implementations§

Source§

impl Button

Source

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

Create a new button with a label

Source

pub fn icon(self, icon: char) -> Self

Set an icon to display before the label

§Example
use revue::prelude::*;

let btn = Button::new("Save")
    .icon('💾')
    .variant(ButtonVariant::Primary);

// Using Nerd Font icons
let btn = Button::new("Settings")
    .icon('\u{f013}');  // Gear icon
Source

pub fn primary(label: impl Into<String>) -> Self

Create a primary button

Source

pub fn danger(label: impl Into<String>) -> Self

Create a danger button

Source

pub fn ghost(label: impl Into<String>) -> Self

Create a ghost button

Source

pub fn success(label: impl Into<String>) -> Self

Create a success button

Source

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

Set button variant

Source

pub fn width(self, width: u16) -> Self

Set minimum width

Source

pub fn handle_key(&mut self, key: &Key) -> bool

Handle key input, returns true if button was “clicked”

Source

pub fn handle_mouse(&mut self, event: &MouseEvent, area: Rect) -> (bool, bool)

Handle mouse input, returns (needs_render, was_clicked)

The area parameter should be the button’s rendered area.

§Example
let (needs_render, clicked) = button.handle_mouse(&mouse, button_area);
if clicked {
    // Button was clicked
}
Source

pub fn is_pressed(&self) -> bool

Check if button is pressed

Source

pub fn is_hovered(&self) -> bool

Check if button is hovered

Source§

impl Button

Source

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

Set focused state

Source

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

Set disabled state

Source

pub fn fg(self, color: Color) -> Self

Set foreground color

Source

pub fn bg(self, color: Color) -> Self

Set background color

Source

pub fn is_focused(&self) -> bool

Check if widget is focused

Source

pub fn is_disabled(&self) -> bool

Check if widget is disabled

Source

pub fn set_focused(&mut self, focused: bool)

Set focused state (mutable)

Source§

impl Button

Source

pub fn element_id(self, id: impl Into<String>) -> Self

Set element ID for CSS selector (#id)

Source

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

Add a CSS class

Source

pub fn classes<I, S>(self, classes: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Add multiple CSS classes

Trait Implementations§

Source§

impl Clone for Button

Source§

fn clone(&self) -> Button

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Button

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Button

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Interactive for Button

Source§

fn handle_key(&mut self, event: &KeyEvent) -> EventResult

Handle keyboard event Read more
Source§

fn handle_mouse(&mut self, event: &MouseEvent, area: Rect) -> EventResult

Handle mouse event Read more
Source§

fn focusable(&self) -> bool

Check if the widget can receive focus
Source§

fn on_focus(&mut self)

Called when the widget receives focus
Source§

fn on_blur(&mut self)

Called when the widget loses focus
Source§

impl StyledView for Button

Source§

fn set_id(&mut self, id: impl Into<String>)

Set element ID
Source§

fn add_class(&mut self, class: impl Into<String>)

Add a CSS class
Source§

fn remove_class(&mut self, class: &str)

Remove a CSS class
Source§

fn toggle_class(&mut self, class: &str)

Toggle a CSS class
Source§

fn has_class(&self, class: &str) -> bool

Check if has class
Source§

impl View for Button

Source§

fn render(&self, ctx: &mut RenderContext<'_>)

Render the view
Source§

fn id(&self) -> Option<&str>

Get element ID (for CSS #id selectors)
Source§

fn classes(&self) -> &[String]

Get CSS classes (for CSS .class selectors)
Source§

fn meta(&self) -> WidgetMeta

Get widget metadata for DOM
Source§

fn widget_type(&self) -> &'static str

Get widget type name (for CSS type selectors)
Source§

fn children(&self) -> &[Box<dyn View>]

Get child views (for container widgets) Read more

Auto Trait Implementations§

§

impl Freeze for Button

§

impl RefUnwindSafe for Button

§

impl Send for Button

§

impl Sync for Button

§

impl Unpin for Button

§

impl UnwindSafe for Button

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.