From e7d404140f9fbdd1fddd38c2cdad4d3e743ecdcf Mon Sep 17 00:00:00 2001 From: Okko Hakola Date: Sat, 4 Jan 2025 13:26:14 +0200 Subject: [PATCH] Fix centered positioning --- src/window.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/window.rs b/src/window.rs index 74cdc4c..790a4b8 100644 --- a/src/window.rs +++ b/src/window.rs @@ -5,7 +5,7 @@ use wgpu::{ TextureFormat, }; use winit::{ - dpi::{LogicalSize, PhysicalPosition, PhysicalSize}, + dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize}, monitor::MonitorHandle, window::{Fullscreen, Window}, }; @@ -227,12 +227,11 @@ pub fn get_centered_window_position( monitor: &MonitorHandle, window_width: u32, window_height: u32, -) -> PhysicalPosition { - let size = monitor.size(); - let window_size = PhysicalSize::new(window_width, window_height); - let lt_x = size.width as i32 / 2 - window_size.width as i32 / 2; - let lt_y = size.height as i32 / 2 - window_size.height as i32 / 2; - PhysicalPosition::new(lt_x, lt_y) +) -> LogicalPosition { + let size: LogicalSize = monitor.size().to_logical(monitor.scale_factor()); + let lt_x = size.width / 2 - window_width as i32 / 2; + let lt_y = size.height / 2 - window_height as i32 / 2; + LogicalPosition::new(lt_x, lt_y) } pub fn get_fitting_videomode(