Preview
Loading GPUI
Props
Install
cargo add evilbuttonsUsage
use evilbuttons::ConfettiButton;
use gpui::{div, prelude::*, rgb, Context, IntoElement, Render, Window};
struct ButtonDemo;
impl Render for ButtonDemo {
fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
div().child(
ConfettiButton::new("celebrate")
.label("Celebrate")
.colors([rgb(0xfafafa), rgb(0xa3a3a3), rgb(0x93c5fd)])
.on_celebrate(|_, _| println!("Celebrated!")),
)
}
}Props
ConfettiButton is a GPUI RenderOnce builder; its state is keyed by id. on_click still fires before the burst.
| Method | Type | Default | Description |
|---|---|---|---|
new(id) | impl Into<ElementId> | - | Unique id for the button's state. |
label(s) | impl Into<SharedString> | "Continue" | Button label. |
particle_count(n) | usize | 80 | Confetti particles per burst. |
spread(deg) | f32 | 64.0 | Confetti spread in degrees. |
start_velocity(v) | f32 | 32.0 | Launch velocity of the burst (canvas-confetti units). |
colors(iter) | IntoIterator<Item = impl Into<Hsla>> | muted neutrals + soft accents | Custom confetti colors. |
icon(bool) | bool | true | Show the leading sparkle icon. |
on_click(f) | Fn(&ClickEvent, &mut Window, &mut App) | - | Fired on every click, before the burst. |
on_celebrate(f) | Fn(&mut Window, &mut App) | - | Fired after each confetti burst. |
disabled(bool) | bool | false | Dims the button and ignores input. |
Good to know
- No
canvas-confetti: its particle model (velocity decay, gravity, wobble, tilt and fade) is ported natively and stepped at its 60fps tick. - Confetti is painted on an unclipped overlay above everything else in the window.