pub struct Button { /* private fields */ }Expand description
A clickable, focusable button. Activates on click, Enter or Space.
use std::cell::Cell;
use std::rc::Rc;
use ravenrs_widgets::{Button, ButtonStyle, IconName, Ui};
let saved = Rc::new(Cell::new(false));
let flag = saved.clone();
let button = Button::new("Save")
.icon(IconName::Check)
.style(ButtonStyle::Secondary)
.on_click(move || flag.set(true));
let mut ui = Ui::new(button, ravenrs_style::Theme::raven_dark());
ui.update();Implementations§
Source§impl Button
impl Button
Sourcepub fn new(label: impl Into<String>) -> Self
pub fn new(label: impl Into<String>) -> Self
A primary, medium button with this label. An empty label makes it icon-only.
Sourcepub fn accessible_name(self, name: impl Into<String>) -> Self
pub fn accessible_name(self, name: impl Into<String>) -> Self
Sets the name screen readers announce, instead of the label. Icon-only buttons should always have one.
Sourcepub fn accessible_description(self, text: impl Into<String>) -> Self
pub fn accessible_description(self, text: impl Into<String>) -> Self
Sets what screen readers say after its name, such as what it does. Its shortcut and whether it is busy follow.
Sourcepub fn on_click(self, handler: impl Fn() + 'static) -> Self
pub fn on_click(self, handler: impl Fn() + 'static) -> Self
Runs handler when the button is clicked or activated with Enter or Space.
Sourcepub fn style(self, style: ButtonStyle) -> Self
pub fn style(self, style: ButtonStyle) -> Self
Sets the visual emphasis (Primary by default).
Sourcepub fn size(self, size: ButtonSize) -> Self
pub fn size(self, size: ButtonSize) -> Self
Sets the height and padding (Medium by default).
Sourcepub fn trailing_icon(self, icon: IconName) -> Self
pub fn trailing_icon(self, icon: IconName) -> Self
An icon after the label (e.g. a chevron for menus).
Sourcepub fn disabled(self, disabled: bool) -> Self
pub fn disabled(self, disabled: bool) -> Self
Greys the button out and ignores clicks and focus.
Sourcepub fn full_width(self) -> Self
pub fn full_width(self) -> Self
Stretches across the parent stack.
Sourcepub fn loading(self, loading: bool) -> Self
pub fn loading(self, loading: bool) -> Self
Shows an animated indicator over the content, which keeps its place so that the button does not change width, and ignores clicks until it is done. It keeps keyboard focus, and screen readers hear that it is loading and unavailable.
Sourcepub fn selected(self, selected: bool) -> Self
pub fn selected(self, selected: bool) -> Self
Lights the button up as being on, and announces it as a button that toggles.
What a click does is still up to Self::on_click.
Sourcepub fn shortcut(self, keys: impl Into<String>) -> Self
pub fn shortcut(self, keys: impl Into<String>) -> Self
Shows a key cap after the label, in the label’s color, such as "F8". It only
shows the key: BuildCx::shortcut makes the key work.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Button
impl !Send for Button
impl !Sync for Button
impl !UnwindSafe for Button
impl Freeze for Button
impl Unpin for Button
impl UnsafeUnpin for Button
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<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<V> ViewExt for Vwhere
V: View,
impl<V> ViewExt for Vwhere
V: View,
Source§fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
Source§fn background(self, fill: impl Into<Fill>) -> Styled<Self>
fn background(self, fill: impl Into<Fill>) -> Styled<Self>
Source§fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
None keeps the content size.