Preview
Loading GPUI
Props
Install
cargo add evilbuttonsUsage
use evilbuttons::ClickPowerUp;
use gpui::{div, prelude::*, Context, IntoElement, Render, Window};
struct ButtonDemo;
impl Render for ButtonDemo {
fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
div().child(ClickPowerUp::new("launch", "Launch").on_click(|_, _, _| println!("Powered up")))
}
}Variants
Custom accent
Swap the flash color and hold it a little longer.
Loading GPUI
ClickPowerUp::new("overdrive", "Overdrive")
.accent_color(rgb(0xf59e0b))
.tap_duration(Duration::from_millis(900))Props
ClickPowerUp is a GPUI RenderOnce builder; its animation state is keyed by id.
| Method | Type | Default | Description |
|---|---|---|---|
new(id, label) | impl Into<ElementId>, impl Into<SharedString> | - | Unique id and the button label (shown uppercase). |
tap_duration(d) | Duration | 500ms | How long the powered-up flash lasts after a click. |
accent_color(c) | impl Into<Hsla> | #2CD4BD | Color of the powered-up flash. |
background(c) | impl Into<Hsla> | theme background | Face color. Defaults to shadcn's --background for the window's light or dark appearance. |
foreground(c) | impl Into<Hsla> | theme foreground | Ink for the label, brackets, hatching and armed panel. |
on_click(f) | Fn(&ClickEvent, &mut Window, &mut App) | - | Fired on every click, and on Space/Enter while focused. |
disabled(bool) | bool | false | Dims the button and ignores input. |
Good to know
- Works in light and dark themes: pass your theme's
backgroundandforeground, or let it follow the window appearance. - Pressing always wins, so every click, even mid power-up, snaps in then bursts out. Space/Enter press it too.