72b6a4a2d1
* Add mutable event status argument to WindowHandler::on_event * macOS: simplify method declaration for simple mouse event handlers * macOS: add macro for adding simple keyboard class methods * macOS: reorder code in mouse_moved * Take EventStatus as return value in WindowHandler::on_event * Add doc comments for EventStatus * Improve EventStatus documentation * x11: ignore return value of on_event for now * EventStatus: improve docs * Improve EventsStatus docs * Improve EventStatus docs further * macOS: ignore EventStatus::Ignored for mouse events * macOS: minor formatting improvement * improve EventStatus docs again
58 lines
1.4 KiB
Rust
58 lines
1.4 KiB
Rust
use std::time::Duration;
|
|
|
|
use rtrb::{RingBuffer, Consumer};
|
|
|
|
use baseview::{Event, EventStatus, Window, WindowHandler, WindowScalePolicy};
|
|
|
|
#[derive(Debug, Clone)]
|
|
enum Message {
|
|
Hello
|
|
}
|
|
|
|
struct OpenWindowExample {
|
|
rx: Consumer<Message>,
|
|
}
|
|
|
|
impl WindowHandler for OpenWindowExample {
|
|
fn on_frame(&mut self, _window: &mut Window) {
|
|
while let Ok(message) = self.rx.pop() {
|
|
println!("Message: {:?}", message);
|
|
}
|
|
}
|
|
|
|
fn on_event(&mut self, _window: &mut Window, event: Event) -> EventStatus {
|
|
match event {
|
|
Event::Mouse(e) => println!("Mouse event: {:?}", e),
|
|
Event::Keyboard(e) => println!("Keyboard event: {:?}", e),
|
|
Event::Window(e) => println!("Window event: {:?}", e),
|
|
}
|
|
|
|
EventStatus::Captured
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let window_open_options = baseview::WindowOpenOptions {
|
|
title: "baseview".into(),
|
|
size: baseview::Size::new(512.0, 512.0),
|
|
scale: WindowScalePolicy::SystemScaleFactor,
|
|
};
|
|
|
|
let (mut tx, rx) = RingBuffer::new(128).split();
|
|
|
|
::std::thread::spawn(move || {
|
|
loop {
|
|
::std::thread::sleep(Duration::from_secs(5));
|
|
|
|
if let Err(_) = tx.push(Message::Hello) {
|
|
println!("Failed sending message");
|
|
}
|
|
}
|
|
});
|
|
|
|
Window::open_blocking(
|
|
window_open_options,
|
|
|_| OpenWindowExample { rx }
|
|
);
|
|
}
|