Skip to content

Commit 220afac

Browse files
committed
wip stuff
1 parent 72c3afd commit 220afac

2 files changed

Lines changed: 10 additions & 107 deletions

File tree

‎src/dpi.rs‎

Lines changed: 8 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -4,106 +4,13 @@ pub use dpi::*;
44
/// A size represented in the platform's native pixels.
55
///
66
/// This size is represented in physical pixels on Windows and Linux, and in logical pixels on macOS.
7+
///
8+
/// # Platform compatibility notes
9+
///
10+
/// On Windows, this *always* represents *actual* pixels, *NOT* the "physical pixels" window
11+
/// implementations think they are using when using the Win32 APIs. TODO: finish sentence
712
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
8-
pub struct NativeSize<P> {
9-
pub width: P,
10-
pub height: P,
11-
}
12-
13-
#[cfg(target_os = "macos")]
14-
const NATIVE_IS_LOGICAL: bool = true;
15-
#[cfg(not(target_os = "macos"))]
16-
const NATIVE_IS_LOGICAL: bool = false;
17-
18-
impl<P> NativeSize<P> {
19-
#[inline]
20-
pub const fn new(width: P, height: P) -> Self {
21-
NativeSize { width, height }
22-
}
23-
24-
/// This is `true` if the platform's native size is represented in logical pixels, and `false` otherwise.
25-
///
26-
/// This is `true` on macOS, and `false` on Windows and Linux.
27-
pub const IS_LOGICAL: bool = NATIVE_IS_LOGICAL;
28-
}
29-
30-
impl<P: Pixel> NativeSize<P> {
31-
#[inline]
32-
pub fn from_size(size: Size, scale_factor: f64) -> Self {
33-
#[cfg(target_os = "macos")]
34-
{
35-
let size = size.to_logical(scale_factor);
36-
Self { width: size.width, height: size.height }
37-
}
38-
39-
#[cfg(not(target_os = "macos"))]
40-
{
41-
let size = size.to_physical(scale_factor);
42-
Self { width: size.width, height: size.height }
43-
}
44-
}
45-
46-
#[inline]
47-
pub fn cast<X: Pixel>(&self) -> NativeSize<X> {
48-
NativeSize { width: self.width.cast(), height: self.height.cast() }
49-
}
50-
51-
#[inline]
52-
pub fn to_physical(self, scale_factor: f64) -> PhysicalSize<P> {
53-
#[cfg(target_os = "macos")]
54-
{
55-
let size = LogicalSize { width: self.width, height: self.height };
56-
size.to_physical(scale_factor)
57-
}
58-
#[cfg(not(target_os = "macos"))]
59-
{
60-
let _ = scale_factor;
61-
PhysicalSize { width: self.width, height: self.height }
62-
}
63-
}
64-
65-
#[inline]
66-
pub fn to_logical(self, scale_factor: f64) -> LogicalSize<P> {
67-
#[cfg(target_os = "macos")]
68-
{
69-
let _ = scale_factor;
70-
LogicalSize { width: self.width, height: self.height }
71-
}
72-
#[cfg(not(target_os = "macos"))]
73-
{
74-
let size = PhysicalSize { width: self.width, height: self.height };
75-
size.to_logical(scale_factor)
76-
}
77-
}
78-
}
79-
80-
impl<P: Pixel> From<WindowSize> for NativeSize<P> {
81-
#[inline]
82-
fn from(size: WindowSize) -> Self {
83-
#[cfg(target_os = "macos")]
84-
{
85-
let size = size.logical.cast();
86-
Self { width: size.width, height: size.height }
87-
}
88-
89-
#[cfg(not(target_os = "macos"))]
90-
{
91-
let size = size.physical.cast();
92-
Self { width: size.width, height: size.height }
93-
}
94-
}
95-
}
96-
97-
impl<P: Pixel> From<NativeSize<P>> for Size {
98-
#[inline]
99-
fn from(size: NativeSize<P>) -> Self {
100-
#[cfg(target_os = "macos")]
101-
{
102-
Size::Logical(LogicalSize::new(size.width, size.height).cast())
103-
}
104-
#[cfg(not(target_os = "macos"))]
105-
{
106-
Size::Physical(PhysicalSize::new(size.width, size.height).cast())
107-
}
108-
}
13+
pub struct HostSize {
14+
pub width: u32,
15+
pub height: u32,
10916
}

‎src/window.rs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,6 @@ impl WindowSize {
281281
pub fn from_logical(logical: LogicalSize<f64>, scale_factor: f64) -> Self {
282282
Self { physical: logical.to_physical(scale_factor), logical, scale_factor }
283283
}
284-
285-
#[inline]
286-
pub fn to_native_size<P: Pixel>(&self) -> NativeSize<P> {
287-
(*self).into()
288-
}
289284
}
290285

291286
impl<P: Pixel> From<WindowSize> for PhysicalSize<P> {
@@ -304,7 +299,8 @@ impl<P: Pixel> From<WindowSize> for LogicalSize<P> {
304299

305300
impl From<WindowSize> for Size {
306301
#[inline]
302+
#[cfg(not(target_os = "macos"))]
307303
fn from(value: WindowSize) -> Self {
308-
value.to_native_size::<f64>().into()
304+
Size::Physical(value.physical)
309305
}
310306
}

0 commit comments

Comments
 (0)