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>
impl<Msg> Button<Msg>
Sourcepub fn on_middle_press(self, message: Msg) -> Self
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.
Sourcepub fn variant(self, variant: impl Into<String>) -> Self
pub fn variant(self, variant: impl Into<String>) -> Self
Theme variant, e.g. "primary" or "danger".
Sourcepub fn shortcut(self, label: impl Into<String>) -> Self
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.
Sourcepub fn disabled(self, disabled: bool) -> Self
pub fn disabled(self, disabled: bool) -> Self
Greys the button out; it cannot be focused or pressed.
Sourcepub fn loading(self, loading: bool) -> Self
pub fn loading(self, loading: bool) -> Self
Shows a spinner in the default spinner style instead of the icon and ignores presses.
Sourcepub fn selected(self, selected: bool) -> Self
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.
Sourcepub fn faint(self, faint: bool) -> Self
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>
impl<Msg: Clone + 'static> Widget<Msg> for Button<Msg>
Source§fn measure(&self, cx: &mut MeasureCx<'_>, available: Size) -> Size
fn measure(&self, cx: &mut MeasureCx<'_>, available: Size) -> Size
available.Source§fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool
fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool
true when the event was used; unused key and scroll events
bubble to the parent widget.Source§fn paint_overlay(&self, _cx: &mut PaintCx<'_>, _anchor: Rect)
fn paint_overlay(&self, _cx: &mut PaintCx<'_>, _anchor: Rect)
PaintCx::request_overlay. anchor is the area the widget was painted in.Source§fn children_mut(&mut self) -> &mut [Node<Msg>]
fn children_mut(&mut self) -> &mut [Node<Msg>]
Auto Trait Implementations§
impl<Msg> Freeze for Button<Msg>
impl<Msg> RefUnwindSafe for Button<Msg>where
Option<Msg>: RefUnwindSafe,
impl<Msg> Send for Button<Msg>
impl<Msg> Sync for Button<Msg>
impl<Msg> Unpin for Button<Msg>
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> 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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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