Preview
Loading GPUI
Props
Install
cargo add evilbuttonsUsage
use evilbuttons::TrollButton;
use std::time::Duration;
TrollButton::new("catch-me")
.label("Click If You Can")
.give_up_after(Duration::from_millis(3000))
.on_click(|_, _, _| println!("Caught it"))Variants
Stubborn
A long chase over a wide area before it gives in.
Loading GPUI
TrollButton::new("never")
.label("Never")
.give_up_after(Duration::from_millis(8000))
.range(220.0)
.flee_radius(90.0)
.surrender_label("Okay, you win")Props
TrollButton is a GPUI RenderOnce builder; its chase state is keyed by id.
| Method | Type | Default | Description |
|---|---|---|---|
new(id) | impl Into<ElementId> | - | Unique id for the chase state. |
label(s) | impl Into<SharedString> | "Click Me" | Label while it is fleeing. |
surrender_label(s) | impl Into<SharedString> | "Fine, click me" | Label shown once the button gives up. |
give_up_after(d) | Duration | 3500ms | How long it runs before giving up. The timer starts on the first dodge. |
flee_radius(px) | f32 | 56 | How close in px the cursor can get to the button's edge before it dodges. |
range(px) | f32 | 140 | Maximum distance in px it strays from its resting spot. |
reset_after(d) | Duration | 1500ms | How long after a successful click before it starts fleeing again. Duration::ZERO keeps it caught. |
on_click(f) | Fn(&ClickEvent, &mut Window, &mut App) | - | Only fires once the button has given up. |
disabled(bool) | bool | false | Dims the button and ignores input. |
Good to know
- On touch, taps make it dodge instead.
- Keyboard clicks always go through.
- It watches the pointer across the whole window, but in the docs preview that window is the preview frame.
- GPUI can't rotate text, so during the quick lean of a dodge only the button's surface tilts.