Skip to content

Commit

Permalink
Demo app fix: respect native pixels_per_point on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Feb 5, 2022
1 parent cbc53fb commit 55067f5
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions egui_demo_lib/src/backend_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f32>,

/// maximum size of the web browser canvas
Expand Down Expand Up @@ -195,12 +196,10 @@ impl BackendPanel {
ui: &mut egui::Ui,
info: &epi::IntegrationInfo,
) -> Option<f32> {
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;
Expand Down

0 comments on commit 55067f5

Please sign in to comment.