Created
March 9, 2021 08:36
-
-
Save wyhinton/adb18bb8d905e9e94d60df004e80eb70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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