From 896d87c80420b8acbc65888fa0e351ac5e8070ab Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 20 May 2020 21:19:42 +0200 Subject: [PATCH] make pixels_per_point optional in RawInput (default 1) --- emigui/src/input.rs | 6 +++--- example_glium/src/main.rs | 2 +- example_wasm/src/lib.rs | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/emigui/src/input.rs b/emigui/src/input.rs index 6c7c16dc7..648fa1c2b 100644 --- a/emigui/src/input.rs +++ b/emigui/src/input.rs @@ -21,7 +21,7 @@ pub struct RawInput { pub screen_size: Vec2, /// Also known as device pixel ratio, > 1 for HDPI screens. - pub pixels_per_point: f32, + pub pixels_per_point: Option, /// Time in seconds. Relative to whatever. Used for animation. pub time: f64, @@ -165,7 +165,7 @@ impl GuiInput { mouse_velocity, scroll_delta: new.scroll_delta, screen_size: new.screen_size, - pixels_per_point: new.pixels_per_point, + pixels_per_point: new.pixels_per_point.unwrap_or(1.0), time: new.time, dt, seconds_since_midnight: new.seconds_since_midnight, @@ -186,7 +186,7 @@ impl RawInput { ui.add(label!("mouse_pos: {:.1?}", self.mouse_pos)); ui.add(label!("scroll_delta: {:?}", self.scroll_delta)); ui.add(label!("screen_size: {:?}", self.screen_size)); - ui.add(label!("pixels_per_point: {}", self.pixels_per_point)); + ui.add(label!("pixels_per_point: {:?}", self.pixels_per_point)); ui.add(label!("time: {:.3} s", self.time)); ui.add(label!("events: {:?}", self.events)); ui.add(label!("dropped_files: {:?}", self.dropped_files)); diff --git a/example_glium/src/main.rs b/example_glium/src/main.rs index 2b7978f38..e8b5d189d 100644 --- a/example_glium/src/main.rs +++ b/example_glium/src/main.rs @@ -72,7 +72,7 @@ fn main() { let (width, height) = display.get_framebuffer_dimensions(); vec2(width as f32, height as f32) / pixels_per_point }, - pixels_per_point, + pixels_per_point: Some(pixels_per_point), ..Default::default() }; diff --git a/example_wasm/src/lib.rs b/example_wasm/src/lib.rs index 2437bea7b..dc086358b 100644 --- a/example_wasm/src/lib.rs +++ b/example_wasm/src/lib.rs @@ -37,7 +37,6 @@ impl State { fn run(&mut self, raw_input: RawInput) -> Result { let everything_start = now_sec(); - let pixels_per_point = raw_input.pixels_per_point; self.ctx.begin_frame(raw_input); let mut ui = self.ctx.fullscreen_ui(); @@ -87,7 +86,7 @@ impl State { bg_color, batches, self.ctx.texture(), - pixels_per_point, + self.ctx.pixels_per_point(), )?; emigui_wasm::save_memory(&self.ctx); // TODO: don't save every frame