Skip to main content

HoldToConfirm

Struct HoldToConfirm 

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

A control that sends its message only after a key or the mouse button is held on it.

While held, three bars fill one after another. Each bar is one block of colour: over its third of the duration the whole bar blends from the track colour to the theme’s target colour (to, the warning tone in the built-in themes). When the third bar reaches the full colour the message is sent, once; nothing more happens until the key or button is let go and pressed again. Letting go empties the bars quickly, over motion.enter. With reduced motion each bar switches to the full colour at the end of its third and letting go empties them at once.

With no options it is a focusable chip: hold Enter or Space while it has focus, or press the mouse button on it. key makes a chord work from anywhere on the screen, e.g. holding ctrl+q to quit; floating draws nothing until the hold starts and then shows the label and bars on a small card in the top left corner of the screen.

Held keys arrive as repeats: with the kitty keyboard protocol as repeat and release events, elsewhere as the same key pressed again every few dozen milliseconds after the keyboard’s repeat delay. The hold therefore counts as released on a release event, or when no repeat arrives within 650 ms of the press or 350 ms of the last repeat. A held mouse button is followed until it is released or leaves the control.

Hovered and focused controls show the pillar in their first cell, like buttons.

The bars fill towards the theme’s to colour unless HoldToConfirm::color names another one, preferably a theme token such as "$danger" so the control follows the theme.

Style keys: hold (bg, fg, bold, padding, track, to, pillar) with states hover, focus, active (held), disabled; hold-card (bg, padding, pillar). Without a card pillar, the card’s pillar blends from muted to to as the hold goes on.

Implementations§

Source§

impl<Msg: Clone + 'static> HoldToConfirm<Msg>

Source

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

A control labelled label, e.g. “Hold to delete”.

Source

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

The message sent once the hold completes.

Source

pub fn duration(self, duration: Duration) -> Self

How long to hold; 1.2 s by default. It does not shorten with reduced motion: the wait protects the action, it is not decoration.

Source

pub fn key(self, chord: &str) -> Self

Holding chord anywhere on the screen confirms too, while the control is in the view.

§Panics

Panics when chord is not a valid chord such as "ctrl+q"; chords are fixed in code.

Source

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

Takes no room and draws nothing until a hold starts, then shows a card in the top left corner of the screen. Meant together with HoldToConfirm::key.

Source

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

Greys the control out; holding does nothing.

Source

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

The colour the bars fill towards, written like a theme colour: a token such as "$danger", "$success" or "$accent", a blend such as "mix($accent, $danger, 50%)", or a fixed "#RRGGBB". Tokens are the intended use: they follow the theme, a fixed colour does not. An expression that is not a single colour of the current theme (a typo, an unknown token, pulse()) falls back to the theme’s to, as if no colour were set; check one with Theme::solid. Default: the theme’s to, the warning tone.

Trait Implementations§

Source§

impl<Msg: Clone + 'static> Widget<Msg> for HoldToConfirm<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 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 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 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 HoldToConfirm<Msg>
where Option<Msg>: Freeze,

§

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

§

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

§

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

§

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

§

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

§

impl<Msg> UnwindSafe for HoldToConfirm<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.