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

@ -60,7 +60,7 @@ impl Window {
let dpi = get_dpi_factor(&surface) as f64;
let (width, height) = attributes
.inner_size
.map(|size| size.to_logical(dpi).into())
.map(|size| size.to_logical::<f64>(dpi).into())
.unwrap_or((800, 600));
// Create the window
@ -147,12 +147,12 @@ impl Window {
frame.set_min_size(
attributes
.min_inner_size
.map(|size| size.to_logical(dpi).into()),
.map(|size| size.to_logical::<f64>(dpi).into()),
);
frame.set_max_size(
attributes
.max_inner_size
.map(|size| size.to_logical(dpi).into()),
.map(|size| size.to_logical::<f64>(dpi).into()),
);
let kill_switch = Arc::new(Mutex::new(false));
@ -206,12 +206,12 @@ impl Window {
}
#[inline]
pub fn outer_position(&self) -> Result<PhysicalPosition, NotSupportedError> {
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
Err(NotSupportedError::new())
}
#[inline]
pub fn inner_position(&self) -> Result<PhysicalPosition, NotSupportedError> {
pub fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
Err(NotSupportedError::new())
}
@ -220,9 +220,9 @@ impl Window {
// Not possible with wayland
}
pub fn inner_size(&self) -> PhysicalSize {
pub fn inner_size(&self) -> PhysicalSize<u32> {
let dpi = self.hidpi_factor() as f64;
let size = LogicalSize::from(*self.size.lock().unwrap());
let size = LogicalSize::<f64>::from(*self.size.lock().unwrap());
size.to_physical(dpi)
}
@ -231,11 +231,11 @@ impl Window {
}
#[inline]
pub fn outer_size(&self) -> PhysicalSize {
pub fn outer_size(&self) -> PhysicalSize<u32> {
let dpi = self.hidpi_factor() as f64;
let (w, h) = self.size.lock().unwrap().clone();
// let (w, h) = super::wayland_window::add_borders(w as i32, h as i32);
let size = LogicalSize::from((w, h));
let size = LogicalSize::<f64>::from((w, h));
size.to_physical(dpi)
}
@ -243,7 +243,7 @@ impl Window {
// NOTE: This will only resize the borders, the contents must be updated by the user
pub fn set_inner_size(&self, size: Size) {
let dpi = self.hidpi_factor() as f64;
let (w, h) = size.to_logical(dpi).into();
let (w, h) = size.to_logical::<u32>(dpi).into();
self.frame.lock().unwrap().resize(w, h);
*(self.size.lock().unwrap()) = (w, h);
}
@ -254,7 +254,7 @@ impl Window {
self.frame
.lock()
.unwrap()
.set_min_size(dimensions.map(|dim| dim.to_logical(dpi).into()));
.set_min_size(dimensions.map(|dim| dim.to_logical::<f64>(dpi).into()));
}
#[inline]
@ -263,7 +263,7 @@ impl Window {
self.frame
.lock()
.unwrap()
.set_max_size(dimensions.map(|dim| dim.to_logical(dpi).into()));
.set_max_size(dimensions.map(|dim| dim.to_logical::<f64>(dpi).into()));
}
#[inline]