Skip to main content

Button

Struct Button 

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

A button: the shape is its surface colour, never brackets.

Sends its message on Enter or Space while focused, or on a click released over it, and flashes one tone brighter to confirm. Hovered and focused buttons show the pillar in their very first cell, before the shortcut segment and the icon (▌ ⏎ Save); the cell is reserved at rest, so nothing moves when the pillar appears. Like every widget that is not a list, buttons never slide. A middle click sends a second message when the button has one (on_middle_press). A theme padding of zero columns leaves no room for the pillar and draws none. Style keys (pillar sets the pillar colour): button, button.<variant>, states hover, focus, pressed, disabled; the shortcut segment uses button-key and button-key.<variant>.

Implementations§

Source§

impl<Msg> Button<Msg>

Source

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

A button labelled label.

Source

pub fn on_press(self, message: Msg) -> Self

The message sent when the button is pressed.

Source

pub fn on_middle_press(self, message: Msg) -> Self

The message sent when the middle mouse button is pressed and released over the button, such as closing a tab or opening a link in a new one. The middle press flashes the button like any press. It takes effect on a button that can be pressed at all, so give it on_press too; without this option the middle button passes the button by, as the right button does.

Source

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

Theme variant, e.g. "primary" or "danger".

Source

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

Icon key drawn before the label.

Source

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

Key label drawn in a darker segment on the left, e.g. "⏎" or "ctrl s". The segment starts with the button’s pillar cell, so the pillar stays the leftmost mark.

Source

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

Greys the button out; it cannot be focused or pressed.

Source

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

Shows a spinner in the default spinner style instead of the icon and ignores presses.

Source

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

Makes this a choice button, such as one of a few view modes: selected shows it chosen, raised with a steady pillar. Choosing is its own feedback, so a choice button does not flash when pressed.

Source

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

Draws the button a step quieter, for a screen that has gone still, such as a running timer nobody has touched for a while. Only the tone changes: the button still presses, and the pointer over it or the keyboard on it bring its full tone back, so it never hides the fact that it can be used.

Trait Implementations§

Source§

impl<Msg: Clone + 'static> Widget<Msg> for Button<Msg>

Source§

fn measure(&self, cx: &mut MeasureCx<'_>, available: Size) -> Size

The size the widget wants when it may use up to available.
Source§

fn paint(&self, cx: &mut PaintCx<'_>, area: Rect)

Draws the widget into area.
Source§

fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool

Handles input. Returns true when the event was used; unused key and scroll events bubble to the parent widget.
Source§

fn focusable(&self) -> bool

Whether the widget can take keyboard focus.
Source§

fn paint_overlay(&self, _cx: &mut PaintCx<'_>, _anchor: Rect)

Draws the widget’s overlay after the whole view was painted, when it asked for one with PaintCx::request_overlay. anchor is the area the widget was painted in.
Source§

fn children(&self) -> &[Node<Msg>]

Child nodes, for widgets that contain other widgets.
Source§

fn children_mut(&mut self) -> &mut [Node<Msg>]

Mutable child nodes, used to assign ids.

Auto Trait Implementations§

§

impl<Msg> Freeze for Button<Msg>
where Option<Msg>: Freeze,

§

impl<Msg> RefUnwindSafe for Button<Msg>
where Option<Msg>: RefUnwindSafe,

§

impl<Msg> Send for Button<Msg>
where Option<Msg>: Send,

§

impl<Msg> Sync for Button<Msg>
where Option<Msg>: Sync,

§

impl<Msg> Unpin for Button<Msg>
where Option<Msg>: Unpin,

§

impl<Msg> UnsafeUnpin for Button<Msg>
where Option<Msg>: UnsafeUnpin,

§

impl<Msg> UnwindSafe for Button<Msg>
where Option<Msg>: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.