TrollButton

A button that dodges the cursor until it runs out of stamina, then gives up and lets you click it.

Preview

Loading GPUI

Props

Install

cargo add evilbuttons

Usage

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.

MethodTypeDefaultDescription
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)Duration3500msHow long it runs before giving up. The timer starts on the first dodge.
flee_radius(px)f3256How close in px the cursor can get to the button's edge before it dodges.
range(px)f32140Maximum distance in px it strays from its resting spot.
reset_after(d)Duration1500msHow 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)boolfalseDims 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.

Search docs

Jump to a button documentation page