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