Skip to content

Instantly share code, notes, and snippets.

@pa-0
Forked from MoAlyousef/expand_button.rs
Created August 25, 2025 20:59
Show Gist options
  • Save pa-0/202f6929da2523d3f35f0dc928257872 to your computer and use it in GitHub Desktop.
Save pa-0/202f6929da2523d3f35f0dc928257872 to your computer and use it in GitHub Desktop.
Expandable button animation using fltk-rs
use fltk::{prelude::*, *};
fn main() {
let app = app::App::default();
app::set_visible_focus(false);
let mut win = window::Window::default().with_size(400, 300);
win.set_color(enums::Color::White);
let mut but = button::Button::default()
.with_size(80, 40)
.with_label("Expand!")
.center_of_parent();
but.set_color(enums::Color::Cyan);
but.set_frame(enums::FrameType::RFlatBox);
win.end();
win.show();
but.set_callback(|b| {
if b.y() == 0 {
return;
}
let mut b = b.clone();
std::thread::spawn(move || loop {
if b.y() == 0 {
break;
}
b.resize(b.x() - 1, b.y() - 1, b.w() + 2, b.h());
app::sleep(0.005);
b.parent().unwrap().redraw();
});
});
app.run().unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment