From fffd5d0ef07c7cbd48e0cda5c1a2e9e45e32d023 Mon Sep 17 00:00:00 2001 From: Imbris Date: Wed, 11 Nov 2020 20:00:31 -0500 Subject: [PATCH] Fix offset issue in ui on startup --- voxygen/src/ui/ice/mod.rs | 9 +++------ voxygen/src/ui/scale.rs | 9 +++++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/voxygen/src/ui/ice/mod.rs b/voxygen/src/ui/ice/mod.rs index 7ea39b11ec..caa25ea51f 100644 --- a/voxygen/src/ui/ice/mod.rs +++ b/voxygen/src/ui/ice/mod.rs @@ -135,14 +135,11 @@ impl IcedUi { span!(_guard, "maintain", "IcedUi::maintain"); // Handle window resizing and scale mode changing let scaled_dims = if let Some(new_dims) = self.window_resized.take() { - let old_scaled_dims = self.scale.scaled_window_size(); // TODO maybe use u32 in Scale to be consistent with iced self.scale - .window_resized(new_dims.map(|e| e as f64), renderer); - let scaled_dims = self.scale.scaled_window_size(); - - // Avoid resetting cache if window size didn't change - (scaled_dims != old_scaled_dims).then_some(scaled_dims) + .window_resized(new_dims.map(|e| e as f64), renderer) + // Avoid resetting cache if window size didn't change + .then(|| self.scale.scaled_window_size()) } else if self.scale_mode_changed { Some(self.scale.scaled_window_size()) } else { diff --git a/voxygen/src/ui/scale.rs b/voxygen/src/ui/scale.rs index ae9916e4a2..34bcd5b171 100644 --- a/voxygen/src/ui/scale.rs +++ b/voxygen/src/ui/scale.rs @@ -74,10 +74,15 @@ impl Scale { /// Multiply by scaled coordinates to get the physical coordinates pub fn scale_factor_physical(&self) -> f64 { self.scale_factor_logical() * self.scale_factor } - // Updates internal window size (and/or scale_factor). - pub fn window_resized(&mut self, new_dims: Vec2, renderer: &Renderer) { + /// Updates internal window size (and/or scale_factor). + /// Returns true if either value was changed + #[allow(clippy::float_cmp)] + pub fn window_resized(&mut self, new_dims: Vec2, renderer: &Renderer) -> bool { + let old_scale_factor = self.scale_factor; + let old_window_dims = self.window_dims; self.scale_factor = renderer.get_resolution().x as f64 / new_dims.x; self.window_dims = new_dims; + old_scale_factor != self.scale_factor || old_window_dims != self.window_dims } /// Get scaled window size.