1
0
Fork 0

win/mac: closure for building WindowHandler

This commit is contained in:
William Light 2020-10-20 21:33:31 +02:00
parent 43cdc39335
commit cf96f3cc85
2 changed files with 12 additions and 4 deletions

View file

@ -33,7 +33,11 @@ impl WindowHandle {
}
impl Window {
pub fn open<H: WindowHandler>(options: WindowOpenOptions) -> WindowHandle {
pub fn open<H, B>(options: WindowOpenOptions, build: B) -> WindowHandle
where H: WindowHandler,
B: FnOnce(&mut Window) -> H,
B: Send + 'static
{
unsafe {
let _pool = NSAutoreleasePool::new(nil);
@ -59,7 +63,7 @@ impl Window {
let mut window = Window { ns_window, ns_view };
let handler = H::build(&mut window);
let handler = build(&mut window);
// FIXME: only do this in the unparented case
let current_app = NSRunningApplication::currentApplication(nil);

View file

@ -166,7 +166,11 @@ impl WindowHandle {
}
impl Window {
pub fn open<H: WindowHandler>(options: WindowOpenOptions) -> WindowHandle {
pub fn open<H, B>(options: WindowOpenOptions, build: B) -> WindowHandle
where H: WindowHandler,
B: FnOnce(&mut Window) -> H,
B: Send + 'static
{
unsafe {
let title = (options.title.to_owned() + "\0").as_ptr() as *const i8;
@ -222,7 +226,7 @@ impl Window {
let mut window = Window { hwnd };
let handler = H::build(&mut window);
let handler = build(&mut window);
let window_state = Rc::new(RefCell::new(WindowState {
window_class,