1
0
Fork 0
baseview/examples/open_window.rs

77 lines
2.3 KiB
Rust
Raw Normal View History

use std::sync::mpsc;
use baseview::Event;
fn main() {
let window_open_options = baseview::WindowOpenOptions {
title: "baseview",
width: 512,
height: 512,
parent: baseview::Parent::None,
};
let my_program = MyProgram {};
let (_app_message_tx, app_message_rx) = mpsc::channel::<()>();
// Send _app_message_tx to a separate thread, then send messages to the GUI thread.
let _ = baseview::Window::open(window_open_options, my_program, app_message_rx);
}
2020-09-03 07:23:03 +10:00
struct MyProgram {}
2020-09-06 02:19:09 +10:00
impl baseview::AppWindow for MyProgram {
type AppMessage = ();
fn create_context(
&mut self,
_window: raw_window_handle::RawWindowHandle,
_window_info: &baseview::WindowInfo,
) {
}
fn on_event(&mut self, event: Event) {
match event {
Event::RenderExpose => {}
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
}
}
}
fn on_app_message(&mut self, _message: Self::AppMessage) {}
2020-09-03 07:23:03 +10:00
}