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,
};
Window::open::<MyProgram>(window_open_options);
let _handle = Window::open::<MyProgram>(window_open_options);
}
struct MyProgram {}

View file

@ -18,7 +18,7 @@ pub struct Window {
}
impl Window {
pub fn open<H: WindowHandler>(options: WindowOpenOptions) {
pub fn open<H: WindowHandler>(options: WindowOpenOptions) -> WindowHandle {
unsafe {
let _pool = NSAutoreleasePool::new(nil);
@ -52,6 +52,8 @@ impl Window {
let current_app = NSRunningApplication::currentApplication(nil);
current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps);
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 {
pub fn open<H: WindowHandler>(options: WindowOpenOptions) {
pub fn open<H: WindowHandler>(options: WindowOpenOptions) -> WindowHandle {
unsafe {
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 {
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
let parent = match options.parent {
Parent::None => None,
@ -102,6 +102,8 @@ impl Window {
let mut handler = H::build(&mut window);
run_event_loop(&mut window, &mut handler);
WindowHandle
}
}
@ -115,6 +117,8 @@ unsafe impl HasRawWindowHandle for Window {
}
}
pub struct WindowHandle;
// Event loop
fn run_event_loop<H: WindowHandler>(window: &mut Window, handler: &mut H) {
loop {