1
0
Fork 0

api change: AppWindow methods receive an &mut Window, which implements HasRawWindowHandle

This commit is contained in:
Micah Johnston 2020-09-07 02:37:16 -05:00 committed by micah
parent 17c673957c
commit 58ed00eb11
2 changed files with 11 additions and 23 deletions

View file

@ -1,6 +1,6 @@
use std::sync::mpsc;
use baseview::Event;
use baseview::{Event, Window};
fn main() {
let window_open_options = baseview::WindowOpenOptions {
@ -14,21 +14,21 @@ fn main() {
// Send _app_message_tx to a separate thread, then send messages to the GUI thread.
let _ = baseview::Window::<MyProgram>::open(window_open_options, app_message_rx);
let _ = Window::open::<MyProgram>(window_open_options, app_message_rx);
}
struct MyProgram {}
impl baseview::AppWindow for MyProgram {
type AppMessage = ();
fn build(_window_handle: baseview::RawWindow, window_info: &baseview::WindowInfo) -> Self {
println!("Window info: {:?}", window_info);
fn build(window: &mut Window) -> Self {
Self {}
}
fn draw(&mut self) {}
fn draw(&mut self, window: &mut Window) {}
fn on_event(&mut self, event: Event) {
fn on_event(&mut self, window: &mut Window, event: Event) {
match event {
Event::CursorMotion(x, y) => {
println!("Cursor moved, x: {}, y: {}", x, y);
@ -69,5 +69,5 @@ impl baseview::AppWindow for MyProgram {
}
}
fn on_app_message(&mut self, _message: Self::AppMessage) {}
fn on_app_message(&mut self, window: &mut Window, _message: Self::AppMessage) {}
}

View file

@ -36,21 +36,9 @@ pub struct WindowOpenOptions<'a> {
pub trait AppWindow {
type AppMessage;
fn build(window_handle: RawWindow, window_info: &WindowInfo) -> Self;
fn build(window: &mut Window) -> Self;
fn draw(&mut self);
fn on_event(&mut self, event: Event);
fn on_app_message(&mut self, message: Self::AppMessage);
}
/// A wrapper for a `RawWindowHandle`. Some context creators expect an `&impl HasRawWindowHandle`.
#[derive(Debug, Copy, Clone)]
pub struct RawWindow {
pub raw_window_handle: raw_window_handle::RawWindowHandle,
}
unsafe impl raw_window_handle::HasRawWindowHandle for RawWindow {
fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle {
self.raw_window_handle
}
fn draw(&mut self, window: &mut Window);
fn on_event(&mut self, window: &mut Window, event: Event);
fn on_app_message(&mut self, window: &mut Window, message: Self::AppMessage);
}