2020-11-29 14:37:59 +01:00
|
|
|
use std::time::Duration;
|
|
|
|
|
2020-12-08 18:37:17 -06:00
|
|
|
use rtrb::{RingBuffer, Consumer};
|
2020-09-02 16:22:49 -05:00
|
|
|
|
2020-12-08 18:37:17 -06:00
|
|
|
use baseview::{Event, Window, WindowHandler, WindowScalePolicy};
|
2020-11-29 14:37:59 +01:00
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
enum Message {
|
|
|
|
Hello
|
|
|
|
}
|
|
|
|
|
2020-12-08 18:37:17 -06:00
|
|
|
struct OpenWindowExample {
|
|
|
|
rx: Consumer<Message>,
|
|
|
|
}
|
2020-11-29 14:37:59 +01:00
|
|
|
|
2020-10-20 21:31:44 +02:00
|
|
|
impl WindowHandler for OpenWindowExample {
|
2020-12-08 18:37:17 -06:00
|
|
|
fn on_frame(&mut self) {
|
|
|
|
while let Ok(message) = self.rx.pop() {
|
|
|
|
println!("Message: {:?}", message);
|
|
|
|
}
|
|
|
|
}
|
2020-09-05 14:41:26 -05:00
|
|
|
|
2020-09-11 18:18:39 +02:00
|
|
|
fn on_event(&mut self, _window: &mut Window, event: Event) {
|
2020-09-03 11:38:22 -05:00
|
|
|
match event {
|
2020-09-11 10:21:05 -05:00
|
|
|
Event::Mouse(e) => println!("Mouse event: {:?}", e),
|
|
|
|
Event::Keyboard(e) => println!("Keyboard event: {:?}", e),
|
2020-09-11 12:38:06 -05:00
|
|
|
Event::Window(e) => println!("Window event: {:?}", e),
|
2020-09-02 16:22:49 -05:00
|
|
|
}
|
|
|
|
}
|
2020-09-02 16:23:03 -05:00
|
|
|
}
|
2020-09-11 18:25:50 +02:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let window_open_options = baseview::WindowOpenOptions {
|
|
|
|
title: "baseview".into(),
|
2020-10-20 19:02:45 -05:00
|
|
|
size: baseview::Size::new(512.0, 512.0),
|
|
|
|
scale: WindowScalePolicy::SystemScaleFactor,
|
2020-09-11 18:25:50 +02:00
|
|
|
parent: baseview::Parent::None,
|
|
|
|
};
|
|
|
|
|
2020-12-08 18:37:17 -06:00
|
|
|
let (mut tx, rx) = RingBuffer::new(128).split();
|
|
|
|
|
|
|
|
let (_handle, opt_app_runner) = Window::open(
|
2020-11-29 16:57:34 +01:00
|
|
|
window_open_options,
|
2020-12-08 18:37:17 -06:00
|
|
|
|_| OpenWindowExample { rx }
|
2020-11-29 16:57:34 +01:00
|
|
|
);
|
2020-11-29 14:37:59 +01:00
|
|
|
|
2020-11-29 16:57:34 +01:00
|
|
|
::std::thread::spawn(move || {
|
|
|
|
loop {
|
|
|
|
::std::thread::sleep(Duration::from_secs(5));
|
2020-11-29 14:37:59 +01:00
|
|
|
|
2020-12-08 18:37:17 -06:00
|
|
|
if let Err(_) = tx.push(Message::Hello) {
|
2020-11-29 16:57:34 +01:00
|
|
|
println!("Failed sending message");
|
2020-11-29 14:37:59 +01:00
|
|
|
}
|
2020-11-29 16:57:34 +01:00
|
|
|
}
|
|
|
|
});
|
2020-11-29 14:37:59 +01:00
|
|
|
|
2020-11-29 16:57:34 +01:00
|
|
|
opt_app_runner.unwrap().app_run_blocking();
|
2020-09-11 18:25:50 +02:00
|
|
|
}
|