mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 13:31:29 +11:00
Window getters now return an Option in case where the Window has been closed
This commit is contained in:
parent
66f6b003d0
commit
838cc2b325
|
@ -51,8 +51,11 @@ impl Window {
|
||||||
self.window.set_title(title)
|
self.window.set_title(title)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the position of the window relative to the top-left hand corner of the screen.
|
||||||
|
///
|
||||||
|
/// Returns `None` if the window no longer exists.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_position(&self) -> (int, int) {
|
pub fn get_position(&self) -> Option<(int, int)> {
|
||||||
self.window.get_position()
|
self.window.get_position()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,12 +65,12 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_inner_size(&self) -> (uint, uint) {
|
pub fn get_inner_size(&self) -> Option<(uint, uint)> {
|
||||||
self.window.get_inner_size()
|
self.window.get_inner_size()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_outer_size(&self) -> (uint, uint) {
|
pub fn get_outer_size(&self) -> Option<(uint, uint)> {
|
||||||
self.window.get_outer_size()
|
self.window.get_outer_size()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,8 +94,6 @@ impl Window {
|
||||||
|
|
||||||
// creating the window
|
// creating the window
|
||||||
let handle = unsafe {
|
let handle = unsafe {
|
||||||
use libc;
|
|
||||||
|
|
||||||
let handle = ffi::CreateWindowExW(ex_style, class_name.as_ptr(),
|
let handle = ffi::CreateWindowExW(ex_style, class_name.as_ptr(),
|
||||||
title.utf16_units().collect::<Vec<u16>>().append_one(0).as_ptr() as ffi::LPCWSTR,
|
title.utf16_units().collect::<Vec<u16>>().append_one(0).as_ptr() as ffi::LPCWSTR,
|
||||||
style | ffi::WS_VISIBLE | ffi::WS_CLIPSIBLINGS | ffi::WS_CLIPCHILDREN,
|
style | ffi::WS_VISIBLE | ffi::WS_CLIPSIBLINGS | ffi::WS_CLIPCHILDREN,
|
||||||
|
@ -207,18 +205,18 @@ impl Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_position(&self) -> (int, int) {
|
pub fn get_position(&self) -> Option<(int, int)> {
|
||||||
use std::{mem, os};
|
use std::mem;
|
||||||
|
|
||||||
let mut placement: ffi::WINDOWPLACEMENT = unsafe { mem::zeroed() };
|
let mut placement: ffi::WINDOWPLACEMENT = unsafe { mem::zeroed() };
|
||||||
placement.length = mem::size_of::<ffi::WINDOWPLACEMENT>() as ffi::UINT;
|
placement.length = mem::size_of::<ffi::WINDOWPLACEMENT>() as ffi::UINT;
|
||||||
|
|
||||||
if unsafe { ffi::GetWindowPlacement(self.window, &mut placement) } == 0 {
|
if unsafe { ffi::GetWindowPlacement(self.window, &mut placement) } == 0 {
|
||||||
fail!("GetWindowPlacement failed: {}", os::error_string(os::errno() as uint));
|
return None
|
||||||
}
|
}
|
||||||
|
|
||||||
let ref rect = placement.rcNormalPosition;
|
let ref rect = placement.rcNormalPosition;
|
||||||
(rect.left as int, rect.top as int)
|
Some((rect.left as int, rect.top as int))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_position(&self, x: uint, y: uint) {
|
pub fn set_position(&self, x: uint, y: uint) {
|
||||||
|
@ -231,32 +229,32 @@ impl Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_inner_size(&self) -> (uint, uint) {
|
pub fn get_inner_size(&self) -> Option<(uint, uint)> {
|
||||||
use std::{mem, os};
|
use std::mem;
|
||||||
let mut rect: ffi::RECT = unsafe { mem::uninitialized() };
|
let mut rect: ffi::RECT = unsafe { mem::uninitialized() };
|
||||||
|
|
||||||
if unsafe { ffi::GetClientRect(self.window, &mut rect) } == 0 {
|
if unsafe { ffi::GetClientRect(self.window, &mut rect) } == 0 {
|
||||||
fail!("GetClientRect failed: {}", os::error_string(os::errno() as uint));
|
return None
|
||||||
}
|
}
|
||||||
|
|
||||||
(
|
Some((
|
||||||
(rect.right - rect.left) as uint,
|
(rect.right - rect.left) as uint,
|
||||||
(rect.bottom - rect.top) as uint
|
(rect.bottom - rect.top) as uint
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_outer_size(&self) -> (uint, uint) {
|
pub fn get_outer_size(&self) -> Option<(uint, uint)> {
|
||||||
use std::{mem, os};
|
use std::mem;
|
||||||
let mut rect: ffi::RECT = unsafe { mem::uninitialized() };
|
let mut rect: ffi::RECT = unsafe { mem::uninitialized() };
|
||||||
|
|
||||||
if unsafe { ffi::GetWindowRect(self.window, &mut rect) } == 0 {
|
if unsafe { ffi::GetWindowRect(self.window, &mut rect) } == 0 {
|
||||||
fail!("GetWindowRect failed: {}", os::error_string(os::errno() as uint));
|
return None
|
||||||
}
|
}
|
||||||
|
|
||||||
(
|
Some((
|
||||||
(rect.right - rect.left) as uint,
|
(rect.right - rect.left) as uint,
|
||||||
(rect.bottom - rect.top) as uint
|
(rect.bottom - rect.top) as uint
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_inner_size(&self, x: uint, y: uint) {
|
pub fn set_inner_size(&self, x: uint, y: uint) {
|
||||||
|
|
|
@ -120,7 +120,7 @@ impl Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_position(&self) -> (int, int) {
|
pub fn get_position(&self) -> Option<(int, int)> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,11 +128,11 @@ impl Window {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_inner_size(&self) -> (uint, uint) {
|
pub fn get_inner_size(&self) -> Option<(uint, uint)> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_outer_size(&self) -> (uint, uint) {
|
pub fn get_outer_size(&self) -> Option<(uint, uint)> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue