Make size/position types generic over pixel type (#1277)

* Begin implementing DPI generics

* Fix multithreaded example

* Format

* Fix serde test

* hopefully fix most of the errors

* Fix dpi module errors

* More error fixings

* Format

* fix macos errors

* Another error pass

* Replace bad type signatures

* more fixins
This commit is contained in:
Osspial 2020-01-04 01:33:07 -05:00
parent b16042a047
commit 3a1e694c2f
40 changed files with 388 additions and 336 deletions

View file

@ -707,7 +707,7 @@ unsafe extern "system" fn public_window_callback<T: 'static>(
let windowpos = lparam as *const winuser::WINDOWPOS;
if (*windowpos).flags & winuser::SWP_NOMOVE != winuser::SWP_NOMOVE {
let physical_position =
PhysicalPosition::new((*windowpos).x as f64, (*windowpos).y as f64);
PhysicalPosition::new((*windowpos).x as u32, (*windowpos).y as u32);
subclass_input.send_event(Event::WindowEvent {
window_id: RootWindowId(WindowId(window)),
event: Moved(physical_position),
@ -829,8 +829,8 @@ unsafe extern "system" fn public_window_callback<T: 'static>(
});
}
let x = windowsx::GET_X_LPARAM(lparam) as f64;
let y = windowsx::GET_Y_LPARAM(lparam) as f64;
let x = windowsx::GET_X_LPARAM(lparam) as i32;
let y = windowsx::GET_Y_LPARAM(lparam) as i32;
let position = PhysicalPosition::new(x, y);
subclass_input.send_event(Event::WindowEvent {
@ -1489,8 +1489,8 @@ unsafe extern "system" fn public_window_callback<T: 'static>(
// We calculate our own size because the default suggested rect doesn't do a great job
// of preserving the window's logical size.
let suggested_physical_inner_size = old_physical_inner_size
.to_logical(old_dpi_factor)
.to_physical(new_dpi_factor);
.to_logical::<f64>(old_dpi_factor)
.to_physical::<u32>(new_dpi_factor);
// `allow_resize` prevents us from re-applying DPI adjustment to the restored size after
// exiting fullscreen (the restored size is already DPI adjusted).

View file

@ -62,7 +62,7 @@ impl std::fmt::Debug for VideoMode {
}
impl VideoMode {
pub fn size(&self) -> PhysicalSize {
pub fn size(&self) -> PhysicalSize<u32> {
self.size.into()
}
@ -185,7 +185,7 @@ impl MonitorHandle {
}
#[inline]
pub fn size(&self) -> PhysicalSize {
pub fn size(&self) -> PhysicalSize<u32> {
let monitor_info = get_monitor_info(self.0).unwrap();
PhysicalSize {
width: (monitor_info.rcMonitor.right - monitor_info.rcMonitor.left) as u32,
@ -194,11 +194,11 @@ impl MonitorHandle {
}
#[inline]
pub fn position(&self) -> PhysicalPosition {
pub fn position(&self) -> PhysicalPosition<i32> {
let monitor_info = get_monitor_info(self.0).unwrap();
PhysicalPosition {
x: monitor_info.rcMonitor.left as f64,
y: monitor_info.rcMonitor.top as f64,
x: monitor_info.rcMonitor.left,
y: monitor_info.rcMonitor.top,
}
}

View file

@ -76,7 +76,7 @@ pub fn get_client_rect(hwnd: HWND) -> Result<RECT, io::Error> {
}
}
pub fn adjust_size(hwnd: HWND, size: PhysicalSize) -> PhysicalSize {
pub fn adjust_size(hwnd: HWND, size: PhysicalSize<u32>) -> PhysicalSize<u32> {
let (width, height): (u32, u32) = size.into();
let rect = RECT {
left: 0,

View file

@ -147,24 +147,24 @@ impl Window {
}
#[inline]
pub fn outer_position(&self) -> Result<PhysicalPosition, NotSupportedError> {
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
util::get_window_rect(self.window.0)
.map(|rect| Ok(PhysicalPosition::new(rect.left as f64, rect.top as f64)))
.map(|rect| Ok(PhysicalPosition::new(rect.left as i32, rect.top as i32)))
.expect("Unexpected GetWindowRect failure; please report this error to https://github.com/rust-windowing/winit")
}
#[inline]
pub fn inner_position(&self) -> Result<PhysicalPosition, NotSupportedError> {
pub fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
let mut position: POINT = unsafe { mem::zeroed() };
if unsafe { winuser::ClientToScreen(self.window.0, &mut position) } == 0 {
panic!("Unexpected ClientToScreen failure: please report this error to https://github.com/rust-windowing/winit")
}
Ok(PhysicalPosition::new(position.x as f64, position.y as f64))
Ok(PhysicalPosition::new(position.x as i32, position.y as i32))
}
#[inline]
pub fn set_outer_position(&self, position: Position) {
let (x, y): (i32, i32) = position.to_physical(self.hidpi_factor()).into();
let (x, y): (i32, i32) = position.to_physical::<i32>(self.hidpi_factor()).into();
let window_state = Arc::clone(&self.window_state);
let window = self.window.clone();
@ -192,7 +192,7 @@ impl Window {
}
#[inline]
pub fn inner_size(&self) -> PhysicalSize {
pub fn inner_size(&self) -> PhysicalSize<u32> {
let mut rect: RECT = unsafe { mem::zeroed() };
if unsafe { winuser::GetClientRect(self.window.0, &mut rect) } == 0 {
panic!("Unexpected GetClientRect failure: please report this error to https://github.com/rust-windowing/winit")
@ -204,7 +204,7 @@ impl Window {
}
#[inline]
pub fn outer_size(&self) -> PhysicalSize {
pub fn outer_size(&self) -> PhysicalSize<u32> {
util::get_window_rect(self.window.0)
.map(|rect| {
PhysicalSize::new(
@ -250,7 +250,7 @@ impl Window {
#[inline]
pub fn set_inner_size(&self, size: Size) {
let dpi_factor = self.hidpi_factor();
let (width, height) = size.to_physical(dpi_factor).into();
let (width, height) = size.to_physical::<u32>(dpi_factor).into();
let window_state = Arc::clone(&self.window_state);
let window = self.window.clone();
@ -363,7 +363,7 @@ impl Window {
#[inline]
pub fn set_cursor_position(&self, position: Position) -> Result<(), ExternalError> {
let dpi_factor = self.hidpi_factor();
let (x, y) = position.to_physical(dpi_factor).into();
let (x, y) = position.to_physical::<i32>(dpi_factor).into();
let mut point = POINT { x, y };
unsafe {