From 3a14f5e8e241473baa09823a1434476d20034df2 Mon Sep 17 00:00:00 2001 From: Jay Oster Date: Mon, 28 Jun 2021 01:27:32 -0700 Subject: [PATCH] Fix a bug on Windows where minimizing adjusts all of the egui window positions. (#522) - Closes #518 - This bug is caused by an issue in winit where minimized windows will be given 0 width and height on Windows. - See: https://github.com/rust-windowing/winit/issues/208 - See also: https://github.com/hasenbanck/egui_winit_platform/pull/19 --- egui_glium/CHANGELOG.md | 3 +++ egui_glium/src/lib.rs | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/egui_glium/CHANGELOG.md b/egui_glium/CHANGELOG.md index 4746529c..be34348d 100644 --- a/egui_glium/CHANGELOG.md +++ b/egui_glium/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to the `egui_glium` integration will be noted in this file. ## Unreleased +### Fixed 🐛 +* [Fix minimize on Windows](https://github.com/emilk/egui/issues/518) + ## 0.13.1 - 2021-06-24 diff --git a/egui_glium/src/lib.rs b/egui_glium/src/lib.rs index 324e8f4d..49ea1229 100644 --- a/egui_glium/src/lib.rs +++ b/egui_glium/src/lib.rs @@ -523,10 +523,19 @@ impl EguiGlium { .unwrap_or_else(|| self.egui_ctx.pixels_per_point()); self.input_state.raw.time = Some(self.start_time.elapsed().as_nanos() as f64 * 1e-9); - self.input_state.raw.screen_rect = Some(Rect::from_min_size( - Default::default(), - screen_size_in_pixels(display) / pixels_per_point, - )); + + // On Windows, a minimized window will have 0 width and height. + // See: https://github.com/rust-windowing/winit/issues/208 + // This solves an issue where egui window positions would be changed when minimizing on Windows. + let screen_size = screen_size_in_pixels(display); + self.input_state.raw.screen_rect = if screen_size.x > 0.0 && screen_size.y > 0.0 { + Some(Rect::from_min_size( + Default::default(), + screen_size / pixels_per_point, + )) + } else { + None + }; self.egui_ctx.begin_frame(self.input_state.raw.take()); }