From f1b435303910628f9b855b8614512c83dbfd3a1a Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 15 Dec 2020 21:58:14 +0100 Subject: [PATCH] [egui_glium]: Store window size in points instead of physical pixels --- egui_glium/CHANGELOG.md | 4 ++++ egui_glium/src/storage.rs | 26 +++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/egui_glium/CHANGELOG.md b/egui_glium/CHANGELOG.md index 9e83c7fe..0b80d392 100644 --- a/egui_glium/CHANGELOG.md +++ b/egui_glium/CHANGELOG.md @@ -11,6 +11,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). * `egui_glium::run`: the parameter `app` now has signature `Box` (you need to add `Box::new(app)` to your code). +### Fixed 🐛 + +* Serialize window size in logical points instead of physical pixels + ## 0.5.0 - 2020-12-13 diff --git a/egui_glium/src/storage.rs b/egui_glium/src/storage.rs index 77d86f98..fa2b43cf 100644 --- a/egui_glium/src/storage.rs +++ b/egui_glium/src/storage.rs @@ -91,11 +91,12 @@ pub fn write_memory( use glium::glutin; #[derive(Default, serde::Deserialize, serde::Serialize)] +#[serde(default)] pub struct WindowSettings { /// outer position of window in physical pixels pos: Option, - /// inner size of window in physical pixels - size: Option, + /// Inner size of window in logical pixels + inner_size_points: Option, } impl WindowSettings { @@ -106,6 +107,13 @@ impl WindowSettings { } pub fn from_display(display: &glium::Display) -> Self { + let scale_factor = display.gl_window().window().scale_factor(); + let inner_size_points = display + .gl_window() + .window() + .inner_size() + .to_logical::(scale_factor); + Self { pos: display .gl_window() @@ -114,9 +122,9 @@ impl WindowSettings { .ok() .map(|p| egui::pos2(p.x as f32, p.y as f32)), - size: Some(egui::vec2( - display.gl_window().window().inner_size().width as f32, - display.gl_window().window().inner_size().height as f32, + inner_size_points: Some(egui::vec2( + inner_size_points.width as f32, + inner_size_points.height as f32, )), } } @@ -125,10 +133,10 @@ impl WindowSettings { &self, window: glutin::window::WindowBuilder, ) -> glutin::window::WindowBuilder { - if let Some(size) = self.size { - window.with_inner_size(glutin::dpi::PhysicalSize { - width: size.x as f64, - height: size.y as f64, + if let Some(inner_size_points) = self.inner_size_points { + window.with_inner_size(glutin::dpi::LogicalSize { + width: inner_size_points.x as f64, + height: inner_size_points.y as f64, }) } else { window