From 55067f54ce343be6f1550f029bf4c0e6f2a819b5 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 5 Feb 2022 23:54:44 +0100 Subject: [PATCH] Demo app fix: respect native pixels_per_point on startup --- egui_demo_lib/src/backend_panel.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/egui_demo_lib/src/backend_panel.rs b/egui_demo_lib/src/backend_panel.rs index acc0461e0..81903af17 100644 --- a/egui_demo_lib/src/backend_panel.rs +++ b/egui_demo_lib/src/backend_panel.rs @@ -51,6 +51,7 @@ pub struct BackendPanel { run_mode: RunMode, /// current slider value for current gui scale + #[cfg_attr(feature = "serde", serde(skip))] pixels_per_point: Option, /// maximum size of the web browser canvas @@ -195,12 +196,10 @@ impl BackendPanel { ui: &mut egui::Ui, info: &epi::IntegrationInfo, ) -> Option { - self.pixels_per_point = self - .pixels_per_point - .or(info.native_pixels_per_point) - .or_else(|| Some(ui.ctx().pixels_per_point())); - - let pixels_per_point = self.pixels_per_point.as_mut()?; + let pixels_per_point = self.pixels_per_point.get_or_insert_with(|| { + info.native_pixels_per_point + .unwrap_or_else(|| ui.ctx().pixels_per_point()) + }); ui.horizontal(|ui| { ui.spacing_mut().slider_width = 90.0;