1use fltk::{app, frame::Frame, prelude::*, window::Window};
2
3#[derive(Debug, Copy, Clone)]
4pub enum Message {
5 Increment(i32),
6 Decrement(i32),
7}
8
9fn inc_frame(frame: &mut Frame, val: &mut i32, step: i32) {
10 *val += step;
11 frame.set_label(&val.to_string());
12}
13
14fn main() {
15 let app = app::App::default();
16 let mut wind = Window::default().with_size(400, 300);
17 let mut frame = Frame::default().size_of(&wind).with_label("0");
18
19 let mut val = 0;
20
21 wind.show();
22
23 let (s, r) = app::channel::<Message>();
24
25 std::thread::spawn(move || {
26 loop {
27 app::sleep(1.);
28 s.send(Message::Increment(2));
29 }
30 });
31
32 while app.wait() {
33 if let Some(Message::Increment(step)) = r.recv() {
34 inc_frame(&mut frame, &mut val, step)
35 }
36 }
37}