Skip to content

Instantly share code, notes, and snippets.

@wyhinton
Created March 9, 2021 08:36
Show Gist options
  • Save wyhinton/adb18bb8d905e9e94d60df004e80eb70 to your computer and use it in GitHub Desktop.
Save wyhinton/adb18bb8d905e9e94d60df004e80eb70 to your computer and use it in GitHub Desktop.
use fltk::*;
fn main() {
let app = app::App::default();
let mut win = window::Window::new(100, 100, 400, 300, "");
let mut scroll = group::Group::default().size_of(&win);
let mut pack = group::Pack::default()
.with_size(200, 100)
.center_of(&scroll);
let mut frame = frame::Frame::default().with_size(0, 160);
let mut but = button::Button::default()
.with_size(0, 40)
.with_label("Click");
pack.end();
scroll.end();
win.end();
win.show();
but.set_callback(move || frame.set_label("Clicked!"));
scroll.handle2({let mut win = win.clone(); move |s, ev| match ev {
Event::MouseWheel => {
let dy = app::event_dy();
if dy > 0 {
pack.set_pos(pack.x(), pack.y() - 10);
s.set_damage_type(Damage::Scroll);
win.set_damage_type(Damage::Scroll);
} else {
pack.set_pos(pack.x(), pack.y() + 10);
s.set_damage_type(Damage::Scroll);
win.set_damage_type(Damage::Scroll);
}
true
}
_ => false,
}});
win.handle2(|w, _| {
let mut damage = w.damage_type();
damage &= Damage::Scroll;
if damage == Damage::Scroll {
println!("Window received a Scroll damage and was redrawn");
}
true
});
app.run().unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment