diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2023-12-19 20:52:42 +1300 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2023-12-19 21:17:35 +1300 |
commit | 8e019fb17d49dd1d605e81a59a84febfd4fc41c8 (patch) | |
tree | d217df89986e5378c79d7225585f51d2978611dd /src | |
parent | 6b6bd38e84d1d14a526765bd23926024b2eda3c7 (diff) | |
download | phosphor-8e019fb17d49dd1d605e81a59a84febfd4fc41c8.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/window.rs | 10 |
1 files changed, 9 insertions, 1 deletions
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<dyn WindowController>) -> 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); + } } } |