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.
Where the label and the bars do not fit side by side, as on a narrow screen or in a longer language, the label wraps over the whole width and the bars go on a line of their own under it; the control reports the extra rows.
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>
impl<Msg: Clone + 'static> HoldToConfirm<Msg>
Sourcepub fn on_confirm(self, message: Msg) -> Self
pub fn on_confirm(self, message: Msg) -> Self
The message sent once the hold completes.
Sourcepub fn duration(self, duration: Duration) -> Self
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.
Sourcepub fn key(self, chord: &str) -> Self
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.
Sourcepub fn floating(self, floating: bool) -> Self
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.
Sourcepub fn color(self, paint: impl Into<String>) -> Self
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>
impl<Msg: Clone + 'static> Widget<Msg> for HoldToConfirm<Msg>
Source§fn measure(&self, cx: &mut MeasureCx<'_>, available: Size) -> Size
fn measure(&self, cx: &mut MeasureCx<'_>, available: Size) -> Size
available.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 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 children_mut(&mut self) -> &mut [Node<Msg>]
fn children_mut(&mut self) -> &mut [Node<Msg>]
Auto Trait Implementations§
impl<Msg> Freeze for HoldToConfirm<Msg>
impl<Msg> RefUnwindSafe for HoldToConfirm<Msg>where
Option<Msg>: RefUnwindSafe,
impl<Msg> Send for HoldToConfirm<Msg>
impl<Msg> Sync for HoldToConfirm<Msg>
impl<Msg> Unpin for HoldToConfirm<Msg>
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> 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