Preview
Loading GPUI
Props
Variants
Longer leash
Tune cooldown and supply your own taunts.
Loading GPUI
CooldownButton::new("refresh")
.label("Refresh")
.cooldown(Duration::from_millis(5000))
.taunts(["Nope.", "Still waiting.", "Touch grass."])Install
cargo add evilbuttonsUsage
use evilbuttons::CooldownButton;
use std::time::Duration;
CooldownButton::new("send")
.cooldown(Duration::from_millis(3000))
.on_click(|_, _, _| send_request())Props
CooldownButton is a GPUI RenderOnce builder; its cooldown state is keyed by id.
| Method | Type | Default | Description |
|---|---|---|---|
new(id) | impl Into<ElementId> | - | Unique id for the cooldown state. |
label(s) | impl Into<SharedString> | "Send it" | Idle label. |
cooldown(d) | Duration | 3000ms | Lockout after each click. Duration::ZERO disables the cooldown. |
taunts(list) | IntoIterator<Item = impl Into<SharedString>> | 5 defaults | Pool of messages; one is picked at random per cooldown. |
show_countdown(bool) | bool | true | Append the remaining whole seconds to the taunt while locked. |
on_click(f) | Fn(&ClickEvent, &mut Window, &mut App) | - | Fires immediately on a valid click, before the cooldown begins. |
disabled(bool) | bool | false | Dims the button and ignores input. |
Good to know
- Ignores clicks for the whole cooldown, so no double submits.