diff --git a/examples/open_window.rs b/examples/open_window.rs index d40f66d..8b344b5 100644 --- a/examples/open_window.rs +++ b/examples/open_window.rs @@ -10,24 +10,20 @@ fn main() { 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); + let _ = baseview::Window::::open(window_open_options, app_message_rx); } struct MyProgram {} impl baseview::AppWindow for MyProgram { type AppMessage = (); - fn create_context( - &mut self, - _window: baseview::RawWindow, - _window_info: &baseview::WindowInfo, - ) { + fn build(_window_handle: baseview::RawWindow, window_info: &baseview::WindowInfo) -> Self { + println!("Window info: {:?}", window_info); + Self {} } fn draw(&mut self) {} diff --git a/src/lib.rs b/src/lib.rs index 0fe21e0..406bb91 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,7 +36,8 @@ pub struct WindowOpenOptions<'a> { pub trait AppWindow { type AppMessage; - fn create_context(&mut self, window: RawWindow, window_info: &WindowInfo); + fn build(window_handle: RawWindow, window_info: &WindowInfo) -> Self; + fn draw(&mut self); fn on_event(&mut self, event: Event); fn on_app_message(&mut self, message: Self::AppMessage); diff --git a/src/x11/window.rs b/src/x11/window.rs index b30d922..fe6f789 100644 --- a/src/x11/window.rs +++ b/src/x11/window.rs @@ -17,11 +17,7 @@ pub struct Window { } impl Window { - pub fn open( - options: WindowOpenOptions, - app_window: A, - app_message_rx: mpsc::Receiver, - ) -> Self { + pub fn open(options: WindowOpenOptions, app_message_rx: mpsc::Receiver) -> Self { // Convert the parent to a X11 window ID if we're given one let parent = match options.parent { Parent::None => None, @@ -112,6 +108,14 @@ impl Window { .or(Some(1.0)) .unwrap(); + let window_info = WindowInfo { + width: options.width as u32, + height: options.height as u32, + scale: scaling, + }; + + let app_window = A::build(raw_window, &window_info); + let mut x11_window = Self { scaling, xcb_connection, @@ -119,16 +123,6 @@ impl Window { app_message_rx, }; - let window_info = WindowInfo { - width: options.width as u32, - height: options.height as u32, - scale: x11_window.scaling, - }; - - x11_window - .app_window - .create_context(raw_window, &window_info); - x11_window.run_event_loop(); x11_window