From 0ad9c3d453076adc5d94008d7e155d7ee5536225 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Tue, 16 Dec 2014 15:49:22 +1000 Subject: Add callback function to allow resize messages to be sent on mac. --- src/x11/window/mod.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/x11/window') diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs index a0e7078..0a3ba01 100644 --- a/src/x11/window/mod.rs +++ b/src/x11/window/mod.rs @@ -598,4 +598,7 @@ impl Window { pub fn get_api(&self) -> ::Api { ::Api::OpenGl } + + pub fn set_window_resize_callback(&mut self, _: fn(uint, uint)) { + } } -- cgit v1.2.3 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. --- examples/window.rs | 9 +++++++-- src/android/mod.rs | 2 +- src/lib.rs | 4 ++-- src/osx/mod.rs | 25 ++++++++++++------------- src/win32/mod.rs | 4 ++-- src/x11/headless.rs | 2 +- src/x11/window/mod.rs | 2 +- 7 files changed, 26 insertions(+), 22 deletions(-) (limited to 'src/x11/window') diff --git a/examples/window.rs b/examples/window.rs index e947234..dce8f3a 100644 --- a/examples/window.rs +++ b/examples/window.rs @@ -14,11 +14,16 @@ android_start!(main) #[cfg(not(feature = "window"))] fn main() { println!("This example requires glutin to be compiled with the `window` feature"); } +#[cfg(feature = "window")] +fn resize_callback(width: uint, height: uint) { + println!("Window resized to {}x{}", width, height); +} + #[cfg(feature = "window")] fn main() { - let window = glutin::Window::new().unwrap(); + let mut window = glutin::Window::new().unwrap(); window.set_title("A fantastic window!"); - + window.set_window_resize_callback(Some(resize_callback)); unsafe { window.make_current() }; let context = support::load(&window); diff --git a/src/android/mod.rs b/src/android/mod.rs index ad9d00a..3a86779 100644 --- a/src/android/mod.rs +++ b/src/android/mod.rs @@ -274,7 +274,7 @@ impl Window { ::Api::OpenGlEs } - pub fn set_window_resize_callback(&mut self, _: fn(uint, uint)) { + pub fn set_window_resize_callback(&mut self, _: Option) { } } diff --git a/src/lib.rs b/src/lib.rs index 48fcc85..eee166b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -486,7 +486,7 @@ impl Window { /// Sets a resize callback that is called by Mac (and potentially other /// operating systems) during resize operations. This can be used to repaint /// during window resizing. - pub fn set_window_resize_callback(&mut self, callback: fn(uint, uint)) { + pub fn set_window_resize_callback(&mut self, callback: Option) { self.window.set_window_resize_callback(callback); } } @@ -550,7 +550,7 @@ impl HeadlessContext { self.context.get_api() } - pub fn set_window_resize_callback(&mut self, _: fn(uint, uint)) { + pub fn set_window_resize_callback(&mut self, _: Option) { } } 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; } } diff --git a/src/win32/mod.rs b/src/win32/mod.rs index 2e0dcae..f900c1f 100644 --- a/src/win32/mod.rs +++ b/src/win32/mod.rs @@ -47,7 +47,7 @@ impl HeadlessContext { ::Api::OpenGl } - pub fn set_window_resize_callback(&mut self, _: fn(uint, uint)) { + pub fn set_window_resize_callback(&mut self, _: Option) { } } @@ -280,7 +280,7 @@ impl Window { ::Api::OpenGl } - pub fn set_window_resize_callback(&mut self, _: fn(uint, uint)) { + pub fn set_window_resize_callback(&mut self, _: Option) { } } diff --git a/src/x11/headless.rs b/src/x11/headless.rs index 3bcea29..95f5233 100644 --- a/src/x11/headless.rs +++ b/src/x11/headless.rs @@ -53,7 +53,7 @@ impl HeadlessContext { ::Api::OpenGl } - pub fn set_window_resize_callback(&mut self, _: fn(uint, uint)) { + pub fn set_window_resize_callback(&mut self, _: Option) { } } diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs index 0a3ba01..422b5b6 100644 --- a/src/x11/window/mod.rs +++ b/src/x11/window/mod.rs @@ -599,6 +599,6 @@ impl Window { ::Api::OpenGl } - pub fn set_window_resize_callback(&mut self, _: fn(uint, uint)) { + pub fn set_window_resize_callback(&mut self, _: Option) { } } -- cgit v1.2.3