Merge branch 'imbris/large-fix-1' into 'master'

Fix offset issue in ui on startup

See merge request veloren/veloren!1504
This commit is contained in:
Imbris 2020-11-12 05:59:01 +00:00
commit 1e0b01d509
2 changed files with 10 additions and 8 deletions

View File

@ -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 {

View File

@ -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<f64>, 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<f64>, 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.