summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2025-07-08 17:07:34 +1200
committerBen Bridle <ben@derelict.engineering>2025-07-08 17:07:34 +1200
commit7cc8495603524483ac2ebe9d00cde8b9bb0faf4a (patch)
tree06c49897f25771326c0052d1c48dc7bed41a7733
parent92a62768fe6be9f72716c14f427767cce5c03b2f (diff)
downloadphosphor-7cc8495603524483ac2ebe9d00cde8b9bb0faf4a.zip
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.
-rw-r--r--src/events.rs9
1 files changed, 5 insertions, 4 deletions
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<u32>, PhysicalSize<u32>) {
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);
}