Preview
Loading GPUI
Props
Variants
Fast hold
A snappier 800ms hold for low-stakes confirmations.
Loading GPUI
HoldButton::new("dismiss")
.duration(Duration::from_millis(800))
.label("Hold to dismiss")
.success_label("Dismissed")Slow hold
A longer 2.5s hold for high-stakes, irreversible actions.
Loading GPUI
HoldButton::new("wipe")
.duration(Duration::from_millis(2500))
.label("Hold to wipe account")
.success_label("Wiped")Install
cargo add evilbuttonsUsage
use evilbuttons::HoldButton;
use std::time::Duration;
HoldButton::new("delete")
.duration(Duration::from_millis(1500))
.label("Hold to delete")
.success_label("Deleted")
.on_confirm(|_, _| delete_account())
.on_abort(|progress, _, _| println!("aborted at {progress}"))Props
HoldButton is a GPUI RenderOnce builder; its hold state is keyed by id.
| Method | Type | Default | Description |
|---|---|---|---|
new(id) | impl Into<ElementId> | - | Unique id for the hold state. |
duration(d) | Duration | 1500ms | How long the user must hold before on_confirm fires. |
label(s) | impl Into<SharedString> | "Hold to delete" | Label shown in the idle state. |
holding_label(s) | impl Into<SharedString> | "Keep holding…" | Label shown while the button is being held. |
success_label(s) | impl Into<SharedString> | "Deleted" | Label shown after the hold completes. |
reset_after(d) | Duration | 1400ms | How long to stay in the success state before resetting. Duration::ZERO stays. |
on_confirm(f) | Fn(&mut Window, &mut App) | - | Fired once the fill reaches 100%. |
on_abort(f) | Fn(f32, &mut Window, &mut App) | - | Fired when released early, with the progress (0-1) reached. |
disabled(bool) | bool | false | Dims the button and ignores input. |
Good to know
- Release outside the button and it still aborts.
- Hold Space or Enter to confirm from the keyboard.