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:
parent
b16042a047
commit
3a1e694c2f
40 changed files with 388 additions and 336 deletions
|
|
@ -185,7 +185,7 @@ impl Handler {
|
|||
&self,
|
||||
callback: &mut Box<dyn EventHandler + 'static>,
|
||||
ns_window: IdRef,
|
||||
suggested_size: LogicalSize,
|
||||
suggested_size: LogicalSize<f64>,
|
||||
hidpi_factor: f64,
|
||||
) {
|
||||
let size = suggested_size.to_physical(hidpi_factor);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ pub enum EventWrapper {
|
|||
pub enum EventProxy {
|
||||
HiDpiFactorChangedProxy {
|
||||
ns_window: IdRef,
|
||||
suggested_size: LogicalSize,
|
||||
suggested_size: LogicalSize<f64>,
|
||||
hidpi_factor: f64,
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ impl Clone for NativeDisplayMode {
|
|||
}
|
||||
|
||||
impl VideoMode {
|
||||
pub fn size(&self) -> PhysicalSize {
|
||||
pub fn size(&self) -> PhysicalSize<u32> {
|
||||
self.size.into()
|
||||
}
|
||||
|
||||
|
|
@ -166,8 +166,8 @@ impl fmt::Debug for MonitorHandle {
|
|||
struct MonitorHandle {
|
||||
name: Option<String>,
|
||||
native_identifier: u32,
|
||||
size: PhysicalSize,
|
||||
position: PhysicalPosition,
|
||||
size: PhysicalSize<u32>,
|
||||
position: PhysicalPosition<i32>,
|
||||
hidpi_factor: f64,
|
||||
}
|
||||
|
||||
|
|
@ -199,18 +199,18 @@ impl MonitorHandle {
|
|||
self.0
|
||||
}
|
||||
|
||||
pub fn size(&self) -> PhysicalSize {
|
||||
pub fn size(&self) -> PhysicalSize<u32> {
|
||||
let MonitorHandle(display_id) = *self;
|
||||
let display = CGDisplay::new(display_id);
|
||||
let height = display.pixels_high();
|
||||
let width = display.pixels_wide();
|
||||
PhysicalSize::from_logical((width as f64, height as f64), self.hidpi_factor())
|
||||
PhysicalSize::from_logical::<_, f64>((width as f64, height as f64), self.hidpi_factor())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn position(&self) -> PhysicalPosition {
|
||||
pub fn position(&self) -> PhysicalPosition<i32> {
|
||||
let bounds = unsafe { CGDisplayBounds(self.native_identifier()) };
|
||||
PhysicalPosition::from_logical(
|
||||
PhysicalPosition::from_logical::<_, f64>(
|
||||
(bounds.origin.x as f64, bounds.origin.y as f64),
|
||||
self.hidpi_factor(),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -73,10 +73,10 @@ pub unsafe fn set_style_mask_sync(ns_window: id, ns_view: id, mask: NSWindowStyl
|
|||
|
||||
struct SetContentSizeData {
|
||||
ns_window: id,
|
||||
size: LogicalSize,
|
||||
size: LogicalSize<f64>,
|
||||
}
|
||||
impl SetContentSizeData {
|
||||
fn new_ptr(ns_window: id, size: LogicalSize) -> *mut Self {
|
||||
fn new_ptr(ns_window: id, size: LogicalSize<f64>) -> *mut Self {
|
||||
Box::into_raw(Box::new(SetContentSizeData { ns_window, size }))
|
||||
}
|
||||
}
|
||||
|
|
@ -98,7 +98,7 @@ extern "C" fn set_content_size_callback(context: *mut c_void) {
|
|||
}
|
||||
// `setContentSize:` isn't thread-safe either, though it doesn't log any errors
|
||||
// and just fails silently. Anyway, GCD to the rescue!
|
||||
pub unsafe fn set_content_size_async(ns_window: id, size: LogicalSize) {
|
||||
pub unsafe fn set_content_size_async(ns_window: id, size: LogicalSize<f64>) {
|
||||
let context = SetContentSizeData::new_ptr(ns_window, size);
|
||||
dispatch_async_f(
|
||||
dispatch_get_main_queue(),
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ pub struct PlatformSpecificWindowBuilderAttributes {
|
|||
pub titlebar_hidden: bool,
|
||||
pub titlebar_buttons_hidden: bool,
|
||||
pub fullsize_content_view: bool,
|
||||
pub resize_increments: Option<LogicalSize>,
|
||||
pub resize_increments: Option<LogicalSize<f64>>,
|
||||
pub disallow_hidpi: bool,
|
||||
}
|
||||
|
||||
|
|
@ -299,7 +299,7 @@ pub struct UnownedWindow {
|
|||
pub shared_state: Arc<Mutex<SharedState>>,
|
||||
decorations: AtomicBool,
|
||||
cursor_state: Weak<Mutex<CursorState>>,
|
||||
pub inner_rect: Option<PhysicalSize>,
|
||||
pub inner_rect: Option<PhysicalSize<u32>>,
|
||||
}
|
||||
|
||||
unsafe impl Send for UnownedWindow {}
|
||||
|
|
@ -440,7 +440,7 @@ impl UnownedWindow {
|
|||
AppState::queue_redraw(RootWindowId(self.id()));
|
||||
}
|
||||
|
||||
pub fn outer_position(&self) -> Result<PhysicalPosition, NotSupportedError> {
|
||||
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
|
||||
let frame_rect = unsafe { NSWindow::frame(*self.ns_window) };
|
||||
let position = LogicalPosition::new(
|
||||
frame_rect.origin.x as f64,
|
||||
|
|
@ -450,7 +450,7 @@ impl UnownedWindow {
|
|||
Ok(position.to_physical(dpi_factor))
|
||||
}
|
||||
|
||||
pub fn inner_position(&self) -> Result<PhysicalPosition, NotSupportedError> {
|
||||
pub fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
|
||||
let content_rect = unsafe {
|
||||
NSWindow::contentRectForFrameRect_(*self.ns_window, NSWindow::frame(*self.ns_window))
|
||||
};
|
||||
|
|
@ -480,18 +480,18 @@ impl UnownedWindow {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn inner_size(&self) -> PhysicalSize {
|
||||
pub fn inner_size(&self) -> PhysicalSize<u32> {
|
||||
let view_frame = unsafe { NSView::frame(*self.ns_view) };
|
||||
let logical: LogicalSize =
|
||||
let logical: LogicalSize<f64> =
|
||||
(view_frame.size.width as f64, view_frame.size.height as f64).into();
|
||||
let dpi_factor = self.hidpi_factor();
|
||||
logical.to_physical(dpi_factor)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn outer_size(&self) -> PhysicalSize {
|
||||
pub fn outer_size(&self) -> PhysicalSize<u32> {
|
||||
let view_frame = unsafe { NSWindow::frame(*self.ns_window) };
|
||||
let logical: LogicalSize =
|
||||
let logical: LogicalSize<f64> =
|
||||
(view_frame.size.width as f64, view_frame.size.height as f64).into();
|
||||
let dpi_factor = self.hidpi_factor();
|
||||
logical.to_physical(dpi_factor)
|
||||
|
|
@ -591,11 +591,11 @@ impl UnownedWindow {
|
|||
pub fn set_cursor_position(&self, cursor_position: Position) -> Result<(), ExternalError> {
|
||||
let physical_window_position = self.inner_position().unwrap();
|
||||
let dpi_factor = self.hidpi_factor();
|
||||
let window_position = physical_window_position.to_logical(dpi_factor);
|
||||
let logical_cursor_position = cursor_position.to_logical(dpi_factor);
|
||||
let window_position = physical_window_position.to_logical::<CGFloat>(dpi_factor);
|
||||
let logical_cursor_position = cursor_position.to_logical::<CGFloat>(dpi_factor);
|
||||
let point = appkit::CGPoint {
|
||||
x: (logical_cursor_position.x + window_position.x) as CGFloat,
|
||||
y: (logical_cursor_position.y + window_position.y) as CGFloat,
|
||||
x: logical_cursor_position.x + window_position.x,
|
||||
y: logical_cursor_position.y + window_position.y,
|
||||
};
|
||||
CGDisplay::warp_mouse_cursor_position(point)
|
||||
.map_err(|e| ExternalError::Os(os_error!(OsError::CGError(e))))?;
|
||||
|
|
@ -1095,7 +1095,7 @@ impl Drop for UnownedWindow {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe fn set_min_inner_size<V: NSWindow + Copy>(window: V, mut min_size: LogicalSize) {
|
||||
unsafe fn set_min_inner_size<V: NSWindow + Copy>(window: V, mut min_size: LogicalSize<f64>) {
|
||||
let mut current_rect = NSWindow::frame(window);
|
||||
let content_rect = NSWindow::contentRectForFrameRect_(window, NSWindow::frame(window));
|
||||
// Convert from client area size to window size
|
||||
|
|
@ -1119,7 +1119,7 @@ unsafe fn set_min_inner_size<V: NSWindow + Copy>(window: V, mut min_size: Logica
|
|||
}
|
||||
}
|
||||
|
||||
unsafe fn set_max_inner_size<V: NSWindow + Copy>(window: V, mut max_size: LogicalSize) {
|
||||
unsafe fn set_max_inner_size<V: NSWindow + Copy>(window: V, mut max_size: LogicalSize<f64>) {
|
||||
let mut current_rect = NSWindow::frame(window);
|
||||
let content_rect = NSWindow::contentRectForFrameRect_(window, NSWindow::frame(window));
|
||||
// Convert from client area size to window size
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ impl WindowDelegateState {
|
|||
(unsafe { NSWindow::backingScaleFactor(*self.ns_window) }) as f64
|
||||
}
|
||||
|
||||
fn view_size(&self) -> LogicalSize {
|
||||
fn view_size(&self) -> LogicalSize<f64> {
|
||||
let ns_size = unsafe { NSView::frame(*self.ns_view).size };
|
||||
LogicalSize::new(ns_size.width as f64, ns_size.height as f64)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue