2020-09-04 02:38:22 +10:00
|
|
|
use std::sync::mpsc;
|
|
|
|
|
|
|
|
use baseview::Event;
|
2020-09-03 07:22:49 +10:00
|
|
|
|
2020-05-26 08:44:15 +10:00
|
|
|
fn main() {
|
|
|
|
let window_open_options = baseview::WindowOpenOptions {
|
|
|
|
title: "baseview",
|
|
|
|
width: 512,
|
|
|
|
height: 512,
|
|
|
|
parent: baseview::Parent::None,
|
|
|
|
};
|
|
|
|
|
2020-09-04 02:38:22 +10:00
|
|
|
let (_app_message_tx, app_message_rx) = mpsc::channel::<()>();
|
|
|
|
|
|
|
|
// Send _app_message_tx to a separate thread, then send messages to the GUI thread.
|
|
|
|
|
2020-09-06 08:29:36 +10:00
|
|
|
let _ = baseview::Window::<MyProgram>::open(window_open_options, app_message_rx);
|
2020-09-04 01:17:54 +10:00
|
|
|
}
|
2020-09-03 07:23:03 +10:00
|
|
|
struct MyProgram {}
|
2020-09-03 07:22:49 +10:00
|
|
|
|
2020-09-06 02:19:09 +10:00
|
|
|
impl baseview::AppWindow for MyProgram {
|
2020-09-04 02:38:22 +10:00
|
|
|
type AppMessage = ();
|
|
|
|
|
2020-09-06 08:29:36 +10:00
|
|
|
fn build(_window_handle: baseview::RawWindow, window_info: &baseview::WindowInfo) -> Self {
|
|
|
|
println!("Window info: {:?}", window_info);
|
|
|
|
Self {}
|
2020-09-04 01:54:23 +10:00
|
|
|
}
|
|
|
|
|
2020-09-06 05:41:26 +10:00
|
|
|
fn draw(&mut self) {}
|
|
|
|
|
2020-09-04 02:38:22 +10:00
|
|
|
fn on_event(&mut self, event: Event) {
|
|
|
|
match event {
|
|
|
|
Event::CursorMotion(x, y) => {
|
2020-09-03 07:22:49 +10:00
|
|
|
println!("Cursor moved, x: {}, y: {}", x, y);
|
2020-09-03 07:23:03 +10:00
|
|
|
}
|
2020-09-04 02:38:22 +10:00
|
|
|
Event::MouseDown(button_id) => {
|
2020-09-03 07:22:49 +10:00
|
|
|
println!("Mouse down, button id: {:?}", button_id);
|
2020-09-03 07:23:03 +10:00
|
|
|
}
|
2020-09-04 02:38:22 +10:00
|
|
|
Event::MouseUp(button_id) => {
|
2020-09-03 07:22:49 +10:00
|
|
|
println!("Mouse up, button id: {:?}", button_id);
|
2020-09-03 07:23:03 +10:00
|
|
|
}
|
2020-09-04 02:38:22 +10:00
|
|
|
Event::MouseScroll(mouse_scroll) => {
|
2020-09-03 07:22:49 +10:00
|
|
|
println!("Mouse scroll, {:?}", mouse_scroll);
|
2020-09-03 07:23:03 +10:00
|
|
|
}
|
2020-09-04 02:38:22 +10:00
|
|
|
Event::MouseClick(mouse_click) => {
|
2020-09-03 07:22:49 +10:00
|
|
|
println!("Mouse click, {:?}", mouse_click);
|
|
|
|
}
|
2020-09-04 02:38:22 +10:00
|
|
|
Event::KeyDown(keycode) => {
|
2020-09-03 07:22:49 +10:00
|
|
|
println!("Key down, keycode: {}", keycode);
|
2020-09-03 07:23:03 +10:00
|
|
|
}
|
2020-09-04 02:38:22 +10:00
|
|
|
Event::KeyUp(keycode) => {
|
2020-09-03 07:22:49 +10:00
|
|
|
println!("Key up, keycode: {}", keycode);
|
2020-09-03 07:23:03 +10:00
|
|
|
}
|
2020-09-04 02:38:22 +10:00
|
|
|
Event::CharacterInput(char_code) => {
|
2020-09-03 07:22:49 +10:00
|
|
|
println!("Character input, char_code: {}", char_code);
|
2020-09-03 07:23:03 +10:00
|
|
|
}
|
2020-09-04 02:38:22 +10:00
|
|
|
Event::WindowResized(window_info) => {
|
2020-09-03 07:22:49 +10:00
|
|
|
println!("Window resized, {:?}", window_info);
|
2020-09-03 07:23:03 +10:00
|
|
|
}
|
2020-09-04 02:38:22 +10:00
|
|
|
Event::WindowFocus => {
|
2020-09-03 07:22:49 +10:00
|
|
|
println!("Window focused");
|
2020-09-03 07:23:03 +10:00
|
|
|
}
|
2020-09-04 02:38:22 +10:00
|
|
|
Event::WindowUnfocus => {
|
2020-09-03 07:22:49 +10:00
|
|
|
println!("Window unfocused");
|
2020-09-03 07:23:03 +10:00
|
|
|
}
|
2020-09-04 02:38:22 +10:00
|
|
|
Event::WillClose => {
|
2020-09-03 07:22:49 +10:00
|
|
|
println!("Window will close");
|
2020-09-03 07:23:03 +10:00
|
|
|
}
|
2020-09-03 07:22:49 +10:00
|
|
|
}
|
|
|
|
}
|
2020-09-04 02:38:22 +10:00
|
|
|
|
|
|
|
fn on_app_message(&mut self, _message: Self::AppMessage) {}
|
2020-09-03 07:23:03 +10:00
|
|
|
}
|