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>) -> Button
pub fn new(label: impl Into<String>) -> Button
A primary, medium button with this label. An empty label makes it icon-only.
Sourcepub fn accessible_name(self, name: impl Into<String>) -> Button
pub fn accessible_name(self, name: impl Into<String>) -> Button
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>) -> Button
pub fn accessible_description(self, text: impl Into<String>) -> Button
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) -> Button
pub fn on_click(self, handler: impl Fn() + 'static) -> Button
Runs handler when the button is clicked or activated with Enter or Space.
Sourcepub fn style(self, style: ButtonStyle) -> Button
pub fn style(self, style: ButtonStyle) -> Button
Sets the visual emphasis (Primary by default).
Sourcepub fn size(self, size: ButtonSize) -> Button
pub fn size(self, size: ButtonSize) -> Button
Sets the height and padding (Medium by default).
Sourcepub fn trailing_icon(self, icon: IconName) -> Button
pub fn trailing_icon(self, icon: IconName) -> Button
An icon after the label (e.g. a chevron for menus).
Sourcepub fn disabled(self, disabled: bool) -> Button
pub fn disabled(self, disabled: bool) -> Button
Greys the button out and ignores clicks and focus.
Sourcepub fn full_width(self) -> Button
pub fn full_width(self) -> Button
Stretches across the parent stack.
Sourcepub fn loading(self, loading: bool) -> Button
pub fn loading(self, loading: bool) -> Button
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) -> Button
pub fn selected(self, selected: bool) -> Button
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.
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§
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
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
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
fn to_sample_(self) -> U
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.