CooldownButton

A button that locks itself behind a draining radial timer after each click to stop spam and double-submits, taunting you while you wait.

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 evilbuttons

Usage

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.

MethodTypeDefaultDescription
new(id)impl Into<ElementId>-Unique id for the cooldown state.
label(s)impl Into<SharedString>"Send it"Idle label.
cooldown(d)Duration3000msLockout after each click. Duration::ZERO disables the cooldown.
taunts(list)IntoIterator<Item = impl Into<SharedString>>5 defaultsPool of messages; one is picked at random per cooldown.
show_countdown(bool)booltrueAppend 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)boolfalseDims the button and ignores input.

Good to know

  • Ignores clicks for the whole cooldown, so no double submits.

Search docs

Jump to a button documentation page