1
0
Fork 0

Window::open() returns WindowHandle struct

This commit is contained in:
Micah Johnston 2020-09-07 21:45:08 -05:00
parent 601a5d62a4
commit 5ecce5d28d
4 changed files with 16 additions and 4 deletions

View file

@ -8,7 +8,7 @@ fn main() {
parent: baseview::Parent::None, parent: baseview::Parent::None,
}; };
Window::open::<MyProgram>(window_open_options); let _handle = Window::open::<MyProgram>(window_open_options);
} }
struct MyProgram {} struct MyProgram {}

View file

@ -18,7 +18,7 @@ pub struct Window {
} }
impl Window { impl Window {
pub fn open<H: WindowHandler>(options: WindowOpenOptions) { pub fn open<H: WindowHandler>(options: WindowOpenOptions) -> WindowHandle {
unsafe { unsafe {
let _pool = NSAutoreleasePool::new(nil); let _pool = NSAutoreleasePool::new(nil);
@ -52,6 +52,8 @@ impl Window {
let current_app = NSRunningApplication::currentApplication(nil); let current_app = NSRunningApplication::currentApplication(nil);
current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps); current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps);
app.run(); app.run();
WindowHandle
} }
} }
} }
@ -65,3 +67,5 @@ unsafe impl HasRawWindowHandle for Window {
}) })
} }
} }
pub struct WindowHandle;

View file

@ -136,7 +136,7 @@ pub struct Window {
} }
impl Window { impl Window {
pub fn open<H: WindowHandler>(options: WindowOpenOptions) { pub fn open<H: WindowHandler>(options: WindowOpenOptions) -> WindowHandle {
unsafe { unsafe {
let title = (options.title.to_owned() + "\0").as_ptr() as *const i8; let title = (options.title.to_owned() + "\0").as_ptr() as *const i8;
@ -213,6 +213,8 @@ impl Window {
} }
} }
} }
WindowHandle
} }
} }
@ -224,3 +226,5 @@ unsafe impl HasRawWindowHandle for Window {
}) })
} }
} }
pub struct WindowHandle;

View file

@ -13,7 +13,7 @@ pub struct Window {
} }
impl Window { impl Window {
pub fn open<H: WindowHandler>(options: WindowOpenOptions) { pub fn open<H: WindowHandler>(options: WindowOpenOptions) -> WindowHandle {
// Convert the parent to a X11 window ID if we're given one // Convert the parent to a X11 window ID if we're given one
let parent = match options.parent { let parent = match options.parent {
Parent::None => None, Parent::None => None,
@ -102,6 +102,8 @@ impl Window {
let mut handler = H::build(&mut window); let mut handler = H::build(&mut window);
run_event_loop(&mut window, &mut handler); run_event_loop(&mut window, &mut handler);
WindowHandle
} }
} }
@ -115,6 +117,8 @@ unsafe impl HasRawWindowHandle for Window {
} }
} }
pub struct WindowHandle;
// Event loop // Event loop
fn run_event_loop<H: WindowHandler>(window: &mut Window, handler: &mut H) { fn run_event_loop<H: WindowHandler>(window: &mut Window, handler: &mut H) {
loop { loop {