From 58ed00eb11fc44508f3278f98661f0d3d547f8e8 Mon Sep 17 00:00:00 2001 From: Micah Johnston Date: Mon, 7 Sep 2020 02:37:16 -0500 Subject: [PATCH] api change: AppWindow methods receive an &mut Window, which implements HasRawWindowHandle --- examples/open_window.rs | 14 +++++++------- src/lib.rs | 20 ++++---------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/examples/open_window.rs b/examples/open_window.rs index 8b344b5..49cff6f 100644 --- a/examples/open_window.rs +++ b/examples/open_window.rs @@ -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::::open(window_open_options, app_message_rx); + let _ = Window::open::(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) {} } diff --git a/src/lib.rs b/src/lib.rs index 406bb91..a962ba4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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); }