1
0
Fork 0
baseview/examples/open_window.rs

68 lines
2 KiB
Rust
Raw Normal View History

2020-09-08 12:36:54 +10:00
use baseview::{Event, Window, WindowHandler};
fn main() {
let window_open_options = baseview::WindowOpenOptions {
title: "baseview",
width: 512,
height: 512,
parent: baseview::Parent::None,
};
let _handle = Window::open::<MyProgram>(window_open_options);
}
2020-09-03 07:23:03 +10:00
struct MyProgram {}
2020-09-08 12:36:54 +10:00
impl WindowHandler for MyProgram {
type Message = ();
fn build(window: &mut Window) -> Self {
Self {}
}
fn draw(&mut self, window: &mut Window) {}
fn on_event(&mut self, window: &mut Window, event: Event) {
match event {
Event::CursorMotion(x, y) => {
println!("Cursor moved, x: {}, y: {}", x, y);
2020-09-03 07:23:03 +10:00
}
Event::MouseDown(button_id) => {
println!("Mouse down, button id: {:?}", button_id);
2020-09-03 07:23:03 +10:00
}
Event::MouseUp(button_id) => {
println!("Mouse up, button id: {:?}", button_id);
2020-09-03 07:23:03 +10:00
}
Event::MouseScroll(mouse_scroll) => {
println!("Mouse scroll, {:?}", mouse_scroll);
2020-09-03 07:23:03 +10:00
}
Event::MouseClick(mouse_click) => {
println!("Mouse click, {:?}", mouse_click);
}
Event::KeyDown(keycode) => {
println!("Key down, keycode: {}", keycode);
2020-09-03 07:23:03 +10:00
}
Event::KeyUp(keycode) => {
println!("Key up, keycode: {}", keycode);
2020-09-03 07:23:03 +10:00
}
Event::CharacterInput(char_code) => {
println!("Character input, char_code: {}", char_code);
2020-09-03 07:23:03 +10:00
}
Event::WindowResized(window_info) => {
println!("Window resized, {:?}", window_info);
2020-09-03 07:23:03 +10:00
}
Event::WindowFocus => {
println!("Window focused");
2020-09-03 07:23:03 +10:00
}
Event::WindowUnfocus => {
println!("Window unfocused");
2020-09-03 07:23:03 +10:00
}
Event::WillClose => {
println!("Window will close");
2020-09-03 07:23:03 +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
}