From eec18290a4712f96f0420c1747e8908420dbf9ca Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 7 Nov 2022 12:36:17 +0100 Subject: [PATCH] eframe: make sure to update native_pixels_per_point when dpi changes (#2256) * eframe: make sure to update native_pixels_per_point when dpi changes * Update changelog --- crates/eframe/CHANGELOG.md | 3 ++- crates/eframe/src/native/epi_integration.rs | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/eframe/CHANGELOG.md b/crates/eframe/CHANGELOG.md index 6c4932985..31f81715d 100644 --- a/crates/eframe/CHANGELOG.md +++ b/crates/eframe/CHANGELOG.md @@ -15,7 +15,8 @@ NOTE: [`egui-winit`](../egui-winit/CHANGELOG.md), [`egui_glium`](../egui_glium/C * Web: you can access your application from JS using `AppRunner::app_mut`. See `crates/egui_demo_app/src/lib.rs`. * Web: You can now use WebGL on top of `wgpu` by enabling the `wgpu` feature (and disabling `glow` via disabling default features) ([#2107](https://github.com/emilk/egui/pull/2107)). * Web: Add `WebInfo::user_agent` ([#2202](https://github.com/emilk/egui/pull/2202)). -* * Wgpu device/adapter/surface creation has now various configuration options exposed via `NativeOptions/WebOptions::wgpu_options` ([#2207](https://github.com/emilk/egui/pull/2207)). +* Wgpu device/adapter/surface creation has now various configuration options exposed via `NativeOptions/WebOptions::wgpu_options` ([#2207](https://github.com/emilk/egui/pull/2207)). +* Fix: Make sure that `native_pixels_per_point` is updated ([#2256](https://github.com/emilk/egui/pull/2256)). ## 0.19.0 - 2022-08-20 diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index 66c9ab4f6..9d9d51e03 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -231,11 +231,13 @@ impl EpiIntegration { *egui_ctx.memory() = load_egui_memory(storage.as_deref()).unwrap_or_default(); + let native_pixels_per_point = window.scale_factor() as f32; + let frame = epi::Frame { info: epi::IntegrationInfo { system_theme, cpu_usage: None, - native_pixels_per_point: Some(native_pixels_per_point(window)), + native_pixels_per_point: Some(native_pixels_per_point), window_info: read_window_info(window, egui_ctx.pixels_per_point()), }, output: Default::default(), @@ -248,8 +250,7 @@ impl EpiIntegration { let mut egui_winit = egui_winit::State::new(event_loop); egui_winit.set_max_texture_side(max_texture_side); - let pixels_per_point = window.scale_factor() as f32; - egui_winit.set_pixels_per_point(pixels_per_point); + egui_winit.set_pixels_per_point(native_pixels_per_point); Self { frame, @@ -292,6 +293,9 @@ impl EpiIntegration { state: ElementState::Pressed, .. } => self.can_drag_window = true, + WindowEvent::ScaleFactorChanged { scale_factor, .. } => { + self.frame.info.native_pixels_per_point = Some(*scale_factor as _); + } _ => {} }