1
0
Fork 0
baseview/examples/open_window.rs
William Light 072918cb3f rename WindowHandler.draw() to WindowHandler.on_frame()
also remove the `Window` ref argument because `on_frame()` shouldn't be
doing any window system ops (this is my opinion and i am happy to
backpedal if it turns out to be wrong).
2020-09-11 16:54:13 +02:00

67 lines
2 KiB
Rust

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);
}
struct MyProgram {}
impl WindowHandler for MyProgram {
type Message = ();
fn build(_window: &mut Window) -> Self {
Self {}
}
fn on_frame(&mut self) {}
fn on_event(&mut self, _window: &mut Window, event: Event) {
match event {
Event::CursorMotion(x, y) => {
println!("Cursor moved, x: {}, y: {}", x, y);
}
Event::MouseDown(button_id) => {
println!("Mouse down, button id: {:?}", button_id);
}
Event::MouseUp(button_id) => {
println!("Mouse up, button id: {:?}", button_id);
}
Event::MouseScroll(mouse_scroll) => {
println!("Mouse scroll, {:?}", mouse_scroll);
}
Event::MouseClick(mouse_click) => {
println!("Mouse click, {:?}", mouse_click);
}
Event::KeyDown(keycode) => {
println!("Key down, keycode: {}", keycode);
}
Event::KeyUp(keycode) => {
println!("Key up, keycode: {}", keycode);
}
Event::CharacterInput(char_code) => {
println!("Character input, char_code: {}", char_code);
}
Event::WindowResized(window_info) => {
println!("Window resized, {:?}", window_info);
}
Event::WindowFocus => {
println!("Window focused");
}
Event::WindowUnfocus => {
println!("Window unfocused");
}
Event::WillClose => {
println!("Window will close");
}
}
}
fn on_message(&mut self, _window: &mut Window, _message: Self::Message) {}
}