From 8e019fb17d49dd1d605e81a59a84febfd4fc41c8 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Tue, 19 Dec 2023 20:52:42 +1300 Subject: Use pixel scale as window resize increment When resizing a window, the window width and height will be made to be a multiple of the current pixel scale. This is to prevent thin black strips from rendering along the bottom edge and the right edge of the window when the dimensions of the window exceed the dimensions of the scaled screen content. --- src/window.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/window.rs') diff --git a/src/window.rs b/src/window.rs index 697c0bb..327cbea 100644 --- a/src/window.rs +++ b/src/window.rs @@ -19,8 +19,11 @@ pub struct Window { impl Window { pub fn new(event_loop: &EventLoopWindowTarget<()>, controller: Box) -> Self { - let mut builder = winit::window::WindowBuilder::new().with_title(controller.title()); let pixel_scale = controller.pixel_scale().get(); + let increment = PhysicalSize { width: pixel_scale, height: pixel_scale }; + let mut builder = winit::window::WindowBuilder::new() + .with_title(controller.title()) + .with_resize_increments(increment); if let Some(exact_dimensions) = controller.exact_size() { let exact_size = dim_to_size(exact_dimensions * pixel_scale); builder = builder @@ -92,6 +95,11 @@ impl Window { self.window.set_min_inner_size(size); let size = self.controller.maximum_size().map(|d| dim_to_size(d * pixel_scale)); self.window.set_max_inner_size(size); + if pixel_scale != self.pixel_scale { + let increment = PhysicalSize { width: pixel_scale, height: pixel_scale }; + self.window.set_resize_increments(Some(increment)); + self.resize_buffer_and_surface(self.surface_dimensions); + } } } -- cgit v1.2.3-70-g09d2