diff --git a/src/android/mod.rs b/src/android/mod.rs index db3dd193..71985533 100644 --- a/src/android/mod.rs +++ b/src/android/mod.rs @@ -125,6 +125,12 @@ impl Window { pub fn set_title(&self, _: &str) { } + pub fn show(&self) { + } + + pub fn hide(&self) { + } + pub fn get_position(&self) -> Option<(int, int)> { None } diff --git a/src/lib.rs b/src/lib.rs index 096bae4f..d8c546a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -74,6 +74,7 @@ pub struct WindowBuilder { monitor: Option, gl_version: Option<(uint, uint)>, vsync: bool, + visible: bool, } #[cfg(feature = "window")] @@ -86,6 +87,7 @@ impl WindowBuilder { monitor: None, gl_version: None, vsync: false, + visible: true, } } @@ -127,6 +129,12 @@ impl WindowBuilder { self } + /// Sets whether the window will be initially hidden or visible. + pub fn with_visibility(mut self, visible: bool) -> WindowBuilder { + self.visible = visible; + self + } + /// Builds the window. /// /// Error should be very rare and only occur in case of permission denied, incompatible system, @@ -252,6 +260,28 @@ impl Window { self.window.set_title(title) } + /// Shows the window if it was hidden. + /// + /// ## Platform-specific + /// + /// - Has no effect on Android + /// + #[inline] + pub fn show(&self) { + self.window.show() + } + + /// Hides the window if it was visible. + /// + /// ## Platform-specific + /// + /// - Has no effect on Android + /// + #[inline] + pub fn hide(&self) { + self.window.hide() + } + /// Returns the position of the top-left hand corner of the window relative to the /// top-left hand corner of the desktop. /// diff --git a/src/osx/mod.rs b/src/osx/mod.rs index 287dcb4c..3e0d668a 100644 --- a/src/osx/mod.rs +++ b/src/osx/mod.rs @@ -198,6 +198,12 @@ impl Window { unimplemented!() } + pub fn show(&self) { + } + + pub fn hide(&self) { + } + pub fn get_position(&self) -> Option<(int, int)> { unimplemented!() } diff --git a/src/win32/init.rs b/src/win32/init.rs index 5168cc6f..bf849730 100644 --- a/src/win32/init.rs +++ b/src/win32/init.rs @@ -17,7 +17,7 @@ local_data_key!(WINDOW: (ffi::HWND, Sender)) pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: String, builder_monitor: Option, builder_gl_version: Option<(uint, uint)>, builder_vsync: bool, - builder_headless: bool) -> Result + builder_hidden: bool) -> Result { use std::mem; use std::os; @@ -237,7 +237,7 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin (None, None) }; - let style = if builder_headless { + let style = if builder_hidden { style } else { style | ffi::WS_VISIBLE diff --git a/src/win32/mod.rs b/src/win32/mod.rs index 35e71697..facfb6dd 100644 --- a/src/win32/mod.rs +++ b/src/win32/mod.rs @@ -68,8 +68,8 @@ pub struct Window { impl Window { /// See the docs in the crate root file. pub fn new(builder: WindowBuilder) -> Result { - let WindowBuilder { dimensions, title, monitor, gl_version, vsync } = builder; - init::new_window(dimensions, title, monitor, gl_version, vsync, false) + let WindowBuilder { dimensions, title, monitor, gl_version, vsync, visible } = builder; + init::new_window(dimensions, title, monitor, gl_version, vsync, !visible) } } @@ -91,6 +91,18 @@ impl Window { } } + pub fn show(&self) { + unsafe { + ffi::ShowWindow(self.window, ffi::SW_SHOW); + } + } + + pub fn hide(&self) { + unsafe { + ffi::ShowWindow(self.window, ffi::SW_HIDE); + } + } + /// See the docs in the crate root file. pub fn get_position(&self) -> Option<(int, int)> { use std::mem; diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs index 26d5497f..2d26cbd2 100644 --- a/src/x11/window/mod.rs +++ b/src/x11/window/mod.rs @@ -295,6 +295,12 @@ impl Window { } } + pub fn show(&self) { + } + + pub fn hide(&self) { + } + fn get_geometry(&self) -> Option<(int, int, uint, uint)> { unsafe { use std::mem;