From b576ab31391ea633f22bd4850ca9f945dc402054 Mon Sep 17 00:00:00 2001 From: Daniel Collin Date: Sat, 9 Jan 2016 20:06:07 +0100 Subject: [PATCH] Started to add set_position --- examples/noise.rs | 2 ++ src/lib.rs | 17 +++++++++++++++++ src/os/macos/mod.rs | 4 ++++ src/os/unix/mod.rs | 4 ++++ src/os/windows/mod.rs | 8 ++++++++ 5 files changed, 35 insertions(+) diff --git a/examples/noise.rs b/examples/noise.rs index edde38a..38479f1 100644 --- a/examples/noise.rs +++ b/examples/noise.rs @@ -20,6 +20,8 @@ fn main() { } }; + window.set_position(10, 10); + while window.is_open() && !window.is_key_down(Key::Escape) { for i in buffer.iter_mut() { noise = seed; diff --git a/src/lib.rs b/src/lib.rs index 51b013b..bbc2b73 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -249,6 +249,23 @@ impl Window { self.0.is_open() } + /// + /// Sets the position of the window. This is useful if you have + /// more than one window and want to align them up on the screen + /// + /// # Examples + /// + /// ```ignore + /// // Moves the window to pixel postion 20, 20 on the screen + /// window.set_position(20, 20); + /// } + /// ``` + /// + #[inline] + pub fn set_position(&mut self, x: isize, y: isize) { + self.0.set_position(x, y) + } + /// /// Get the current keys that are down. /// diff --git a/src/os/macos/mod.rs b/src/os/macos/mod.rs index afa6de7..b72165c 100644 --- a/src/os/macos/mod.rs +++ b/src/os/macos/mod.rs @@ -201,6 +201,10 @@ impl Window { } } + #[inline] + pub fn set_position(&mut self, _: isize, _: isize) { + } + #[inline] pub fn get_keys(&self) -> Option> { self.key_handler.get_keys() diff --git a/src/os/unix/mod.rs b/src/os/unix/mod.rs index 50000ea..089e06e 100644 --- a/src/os/unix/mod.rs +++ b/src/os/unix/mod.rs @@ -175,6 +175,10 @@ impl Window { } } + #[inline] + pub fn set_position(&mut self, _: isize, _: isize) { + } + #[inline] pub fn get_keys(&self) -> Option> { self.key_handler.get_keys() diff --git a/src/os/windows/mod.rs b/src/os/windows/mod.rs index abb47a5..e9a5e8f 100644 --- a/src/os/windows/mod.rs +++ b/src/os/windows/mod.rs @@ -342,6 +342,14 @@ impl Window { } } + #[inline] + pub fn set_position(&mut self, x: isize, y: isize) { + unsafe { + user32::SetWindowPos(self.window.unwrap(), ptr::null_mut(), x as i32, y as i32, + 0, 0, winapi::SWP_SHOWWINDOW | winapi::SWP_NOSIZE); + } + } + #[inline] pub fn get_keys(&self) -> Option> { self.key_handler.get_keys()