Started to add set_position

This commit is contained in:
Daniel Collin 2016-01-09 20:06:07 +01:00
parent 1cd69660d8
commit b576ab3139
5 changed files with 35 additions and 0 deletions

View file

@ -20,6 +20,8 @@ fn main() {
} }
}; };
window.set_position(10, 10);
while window.is_open() && !window.is_key_down(Key::Escape) { while window.is_open() && !window.is_key_down(Key::Escape) {
for i in buffer.iter_mut() { for i in buffer.iter_mut() {
noise = seed; noise = seed;

View file

@ -249,6 +249,23 @@ impl Window {
self.0.is_open() 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. /// Get the current keys that are down.
/// ///

View file

@ -201,6 +201,10 @@ impl Window {
} }
} }
#[inline]
pub fn set_position(&mut self, _: isize, _: isize) {
}
#[inline] #[inline]
pub fn get_keys(&self) -> Option<Vec<Key>> { pub fn get_keys(&self) -> Option<Vec<Key>> {
self.key_handler.get_keys() self.key_handler.get_keys()

View file

@ -175,6 +175,10 @@ impl Window {
} }
} }
#[inline]
pub fn set_position(&mut self, _: isize, _: isize) {
}
#[inline] #[inline]
pub fn get_keys(&self) -> Option<Vec<Key>> { pub fn get_keys(&self) -> Option<Vec<Key>> {
self.key_handler.get_keys() self.key_handler.get_keys()

View file

@ -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] #[inline]
pub fn get_keys(&self) -> Option<Vec<Key>> { pub fn get_keys(&self) -> Option<Vec<Key>> {
self.key_handler.get_keys() self.key_handler.get_keys()