From 7cc8495603524483ac2ebe9d00cde8b9bb0faf4a Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Tue, 8 Jul 2025 17:07:34 +1200 Subject: Enforce a minimum window size of 8px by 8px This is to prevent a panic that occurs when the maximum size of a window is set to 0px along at least one dimension. --- src/events.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/events.rs') diff --git a/src/events.rs b/src/events.rs index 78ef20a..733f1c5 100644 --- a/src/events.rs +++ b/src/events.rs @@ -4,6 +4,7 @@ use winit::dpi::PhysicalSize; use winit::event::ElementState; use winit::keyboard::KeyCode; +use std::cmp::max; use std::path::PathBuf; @@ -95,12 +96,12 @@ pub struct SizeBounds { impl SizeBounds { pub fn as_min_max_size(&self, scale: u32) -> (PhysicalSize, PhysicalSize) { let min_size = PhysicalSize { - width: std::cmp::max(1, self.min_width.unwrap_or(0)).saturating_mul(scale), - height: std::cmp::max(1, self.min_height.unwrap_or(0)).saturating_mul(scale), + width: max(8, self.min_width.unwrap_or(0)).saturating_mul(scale), + height: max(8, self.min_height.unwrap_or(0)).saturating_mul(scale), }; let max_size = PhysicalSize { - width: self.max_width.unwrap_or(u32::MAX).saturating_mul(scale), - height: self.max_height.unwrap_or(u32::MAX).saturating_mul(scale), + width: max(8, self.max_width.unwrap_or(u16::MAX as u32)).saturating_mul(scale), + height: max(8, self.max_height.unwrap_or(u16::MAX as u32)).saturating_mul(scale), }; return (min_size, max_size); } -- cgit v1.2.3-70-g09d2