From 6369ad6b8d163e78b1311ea3e09caabbba3d6ff9 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Mon, 25 Jul 2022 14:45:55 +0200 Subject: [PATCH 1/4] Windows: respect min/max sizes when creating the window --- src/dpi.rs | 23 +++++++++++++++++++++++ src/platform_impl/windows/window.rs | 11 +++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/dpi.rs b/src/dpi.rs index 3c3829359f..c967c084f1 100644 --- a/src/dpi.rs +++ b/src/dpi.rs @@ -511,6 +511,29 @@ impl Size { Size::Logical(size) => size.to_physical(scale_factor), } } + + pub fn clamp>(s1: S, s2: S, s3: S, scale_factor: f64) -> Size { + let (s1, s2, s3) = ( + s1.into().to_physical::(scale_factor), + s2.into().to_physical::(scale_factor), + s3.into().to_physical::(scale_factor), + ); + + let clamp = |input: f64, min: f64, max: f64| { + if input < min { + min + } else if input > max { + max + } else { + input + } + }; + + let width = clamp(s1.width, s2.width, s3.width); + let height = clamp(s1.height, s2.height, s3.height); + + PhysicalSize::new(width, height).into() + } } impl From> for Size { diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 73680cdad9..bf85a42874 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -879,10 +879,17 @@ impl<'a, T: 'static> InitData<'a, T> { win.set_fullscreen(attributes.fullscreen); force_window_active(win.window.0); } else { - let dimensions = attributes + let size = attributes .inner_size .unwrap_or_else(|| PhysicalSize::new(800, 600).into()); - win.set_inner_size(dimensions); + let max_size = attributes + .max_inner_size + .unwrap_or_else(|| PhysicalSize::new(f64::MAX, f64::MAX).into()); + let min_size = attributes + .max_inner_size + .unwrap_or_else(|| PhysicalSize::new(0, 0).into()); + let clamped_size = Size::clamp(size, min_size, max_size, win.scale_factor()); + win.set_inner_size(clamped_size); if attributes.maximized { // Need to set MAXIMIZED after setting `inner_size` as From 2213a62653b235886fd1ff8ad38441ed5d2e80d9 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Mon, 25 Jul 2022 14:46:28 +0200 Subject: [PATCH 2/4] changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99d1d70d03..85b7d84d30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre # Unreleased +- On Windows, respect min/max inner sizes when creating the window. - On Windows, fix hiding a maximized window. - On Android, `ndk-glue`'s `NativeWindow` lock is now held between `Event::Resumed` and `Event::Suspended`. - On Web, added `EventLoopExtWebSys` with a `spawn` method to start the event loop without throwing an exception. From 80ddf68976d7994a4ebf5ff906ec4e9740e4fcd2 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Mon, 25 Jul 2022 14:49:57 +0200 Subject: [PATCH 3/4] better variable names --- src/dpi.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/dpi.rs b/src/dpi.rs index c967c084f1..7d372d8899 100644 --- a/src/dpi.rs +++ b/src/dpi.rs @@ -512,11 +512,11 @@ impl Size { } } - pub fn clamp>(s1: S, s2: S, s3: S, scale_factor: f64) -> Size { - let (s1, s2, s3) = ( - s1.into().to_physical::(scale_factor), - s2.into().to_physical::(scale_factor), - s3.into().to_physical::(scale_factor), + pub fn clamp>(input: S, min: S, max: S, scale_factor: f64) -> Size { + let (input, min, max) = ( + input.into().to_physical::(scale_factor), + min.into().to_physical::(scale_factor), + max.into().to_physical::(scale_factor), ); let clamp = |input: f64, min: f64, max: f64| { @@ -529,8 +529,8 @@ impl Size { } }; - let width = clamp(s1.width, s2.width, s3.width); - let height = clamp(s1.height, s2.height, s3.height); + let width = clamp(input.width, min.width, max.width); + let height = clamp(input.height, min.height, max.height); PhysicalSize::new(width, height).into() } From b6944b4ad3f7757b82955f18f5440d2f6232f974 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Mon, 25 Jul 2022 14:51:22 +0200 Subject: [PATCH 4/4] use correct min size --- src/platform_impl/windows/window.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index bf85a42874..e63075a833 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -886,7 +886,7 @@ impl<'a, T: 'static> InitData<'a, T> { .max_inner_size .unwrap_or_else(|| PhysicalSize::new(f64::MAX, f64::MAX).into()); let min_size = attributes - .max_inner_size + .min_inner_size .unwrap_or_else(|| PhysicalSize::new(0, 0).into()); let clamped_size = Size::clamp(size, min_size, max_size, win.scale_factor()); win.set_inner_size(clamped_size);