From 19d23f0d2e04b52db1e388fe1e8eb919e9e1b4c8 Mon Sep 17 00:00:00 2001 From: Barugon Date: Thu, 16 Jun 2022 12:24:07 -0700 Subject: [PATCH 1/3] Fix window position --- egui-winit/src/window_settings.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/egui-winit/src/window_settings.rs b/egui-winit/src/window_settings.rs index b7db8d02683..f970130d344 100644 --- a/egui-winit/src/window_settings.rs +++ b/egui-winit/src/window_settings.rs @@ -2,8 +2,9 @@ #[derive(Clone, Copy, Debug)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct WindowSettings { - /// Inner position of window in physical pixels - inner_pos: Option, + /// Position of window in physical pixels. This is either + /// the inner or outer position depending on the platform. + position: Option, /// Inner size of window in logical pixels inner_size_points: Option, } @@ -11,13 +12,22 @@ pub struct WindowSettings { impl WindowSettings { pub fn from_display(window: &winit::window::Window) -> Self { let inner_size_points = window.inner_size().to_logical::(window.scale_factor()); - - Self { - inner_pos: window + let position = if cfg!(macos) { + // Use the inner position for MacOS + window .inner_position() .ok() - .map(|p| egui::pos2(p.x as f32, p.y as f32)), + .map(|p| egui::pos2(p.x as f32, p.y as f32)) + } else { + // Other platforms use the outer position. + window + .outer_position() + .ok() + .map(|p| egui::pos2(p.x as f32, p.y as f32)) + }; + Self { + position, inner_size_points: Some(egui::vec2( inner_size_points.width as f32, inner_size_points.height as f32, @@ -35,7 +45,7 @@ impl WindowSettings { // If this happens on Mac, the window is clamped into valid area. // If this happens on Windows, the window is hidden and very difficult to find. // So we don't restore window positions on Windows. - if let Some(pos) = self.inner_pos { + if let Some(pos) = self.position { window = window.with_position(winit::dpi::PhysicalPosition { x: pos.x as f64, y: pos.y as f64, From c8a97521b921ea7244a807fa56e319b83e341393 Mon Sep 17 00:00:00 2001 From: Barugon Date: Thu, 16 Jun 2022 12:53:26 -0700 Subject: [PATCH 2/3] Better comment --- egui-winit/src/window_settings.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/egui-winit/src/window_settings.rs b/egui-winit/src/window_settings.rs index f970130d344..1f0e05db6b6 100644 --- a/egui-winit/src/window_settings.rs +++ b/egui-winit/src/window_settings.rs @@ -13,7 +13,7 @@ impl WindowSettings { pub fn from_display(window: &winit::window::Window) -> Self { let inner_size_points = window.inner_size().to_logical::(window.scale_factor()); let position = if cfg!(macos) { - // Use the inner position for MacOS + // MacOS uses inner position when positioning windows. window .inner_position() .ok() From 0ffc20472c43607c4078449140fd8a1f18bc5528 Mon Sep 17 00:00:00 2001 From: Barugon Date: Thu, 16 Jun 2022 12:59:59 -0700 Subject: [PATCH 3/3] Add doc link --- egui-winit/src/window_settings.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/egui-winit/src/window_settings.rs b/egui-winit/src/window_settings.rs index 1f0e05db6b6..fd8afb94718 100644 --- a/egui-winit/src/window_settings.rs +++ b/egui-winit/src/window_settings.rs @@ -4,6 +4,7 @@ pub struct WindowSettings { /// Position of window in physical pixels. This is either /// the inner or outer position depending on the platform. + /// See [`winit::window::WindowAttributes`] for details. position: Option, /// Inner size of window in logical pixels inner_size_points: Option,