From fa5cb66cff2e13a5ee75c4f99abe5f93bede7dd1 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Wed, 17 Dec 2014 09:41:27 +1000 Subject: Add resize example, fix warnings, make callback an option so it can be removed. --- src/osx/mod.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src/osx') diff --git a/src/osx/mod.rs b/src/osx/mod.rs index 2634491..110113b 100644 --- a/src/osx/mod.rs +++ b/src/osx/mod.rs @@ -48,8 +48,7 @@ struct DelegateState<'a> { is_closed: bool, context: id, view: id, - window: &'a Window, - handler: fn(uint, uint), + handler: Option, } pub struct Window { @@ -57,7 +56,7 @@ pub struct Window { window: id, context: id, delegate: id, - resize: fn(uint, uint), + resize: Option, is_closed: Cell, } @@ -118,15 +117,20 @@ extern fn window_did_resize(this: id, _: id) -> id { let _: id = msg_send()(state.context, selector("update")); - let rect = NSView::frame(state.view); - (state.handler)(rect.size.width as uint, rect.size.height as uint); + match state.handler { + Some(handler) => { + let rect = NSView::frame(state.view); + (handler)(rect.size.width as uint, rect.size.height as uint); + } + None => {} + } } 0 } impl Window { fn new_impl(dimensions: Option<(uint, uint)>, title: &str, monitor: Option, - vsync: bool, visible: bool) -> Result { + vsync: bool, _visible: bool) -> Result { let app = match Window::create_app() { Some(app) => app, None => { return Err(OsError(format!("Couldn't create NSApplication"))); }, @@ -173,7 +177,7 @@ impl Window { window: window, context: context, delegate: delegate, - resize: Window::resize, + resize: None, is_closed: Cell::new(false), }; @@ -181,10 +185,6 @@ impl Window { Ok(window) } - fn resize(_: uint, _: uint) { - - } - fn create_app() -> Option { unsafe { let app = NSApp(); @@ -349,7 +349,6 @@ impl Window { is_closed: self.is_closed.get(), context: self.context, view: self.view, - window: self, handler: self.resize, }; object_setInstanceVariable(self.delegate, @@ -476,7 +475,7 @@ impl Window { ::Api::OpenGl } - pub fn set_window_resize_callback(&mut self, callback: fn(uint, uint)) { + pub fn set_window_resize_callback(&mut self, callback: Option) { self.resize = callback; } } -- cgit v1.2.3