From 3ba406c0feb218fcc4d88dabf3fc891ff3e1c270 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 20 Oct 2021 13:54:08 +0200 Subject: [PATCH] egui-winit: restore window position accurately previous code had mixed up inner and outer coordinates --- egui-winit/src/window_settings.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/egui-winit/src/window_settings.rs b/egui-winit/src/window_settings.rs index 687b4abf..b7db8d02 100644 --- a/egui-winit/src/window_settings.rs +++ b/egui-winit/src/window_settings.rs @@ -1,9 +1,9 @@ -/// Can be used to store window settings (position and size). +/// Can be used to store native window settings (position and size). #[derive(Clone, Copy, Debug)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct WindowSettings { - /// outer position of window in physical pixels - pos: Option, + /// Inner position of window in physical pixels + inner_pos: Option, /// Inner size of window in logical pixels inner_size_points: Option, } @@ -13,8 +13,8 @@ impl WindowSettings { let inner_size_points = window.inner_size().to_logical::(window.scale_factor()); Self { - pos: window - .outer_position() + inner_pos: window + .inner_position() .ok() .map(|p| egui::pos2(p.x as f32, p.y as f32)), @@ -33,9 +33,9 @@ impl WindowSettings { // If the app last ran on two monitors and only one is now connected, then // the given position is invalid. // If this happens on Mac, the window is clamped into valid area. - // If this happens on Windows, the window is hidden and impossible to bring to get at. + // 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.pos { + if let Some(pos) = self.inner_pos { window = window.with_position(winit::dpi::PhysicalPosition { x: pos.x as f64, y: pos.y as f64,