2020-09-08 12:36:54 +10:00
|
|
|
use baseview::{Event, Window, WindowHandler};
|
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-08 12:45:08 +10:00
|
|
|
let _handle = Window::open::<MyProgram>(window_open_options);
|
2020-09-04 01:17:54 +10:00
|
|
|
}
|
2020-09-07 17:37:16 +10:00
|
|
|
|
2020-09-03 07:23:03 +10:00
|
|
|
struct MyProgram {}
|
2020-09-03 07:22:49 +10:00
|
|
|
|
2020-09-08 12:36:54 +10:00
|
|
|
impl WindowHandler for MyProgram {
|
|
|
|
type Message = ();
|
2020-09-04 02:38:22 +10:00
|
|
|
|
2020-09-07 17:37:16 +10:00
|
|
|
fn build(window: &mut Window) -> Self {
|
2020-09-06 08:29:36 +10:00
|
|
|
Self {}
|
2020-09-04 01:54:23 +10:00
|
|
|
}
|
|
|
|
|
2020-09-12 00:32:21 +10:00
|
|
|
fn draw(&mut self, _window: &mut Window) {}
|
2020-09-06 05:41:26 +10:00
|
|
|
|
2020-09-07 17:37:16 +10:00
|
|
|
fn on_event(&mut self, window: &mut Window, event: Event) {
|
2020-09-04 02:38:22 +10:00
|
|
|
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
|
|
|
|
2020-09-08 12:36:54 +10:00
|
|
|
fn on_message(&mut self, window: &mut Window, _message: Self::Message) {}
|
2020-09-03 07:23:03 +10:00
|
|
|
}
|