mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-26 03:36:32 +11:00
Windows: respect min/max sizes when creating the window (#2393)
This commit is contained in:
parent
c53a574bff
commit
6b7ceedc91
3 changed files with 34 additions and 2 deletions
|
@ -8,6 +8,8 @@ And please only add new entries to the top of this list, right below the `# Unre
|
||||||
|
|
||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
|
- On Windows, respect min/max inner sizes when creating the window.
|
||||||
|
|
||||||
# 0.27.1 (2022-07-30)
|
# 0.27.1 (2022-07-30)
|
||||||
|
|
||||||
- The minimum supported Rust version was lowered to `1.57.0` and now explicitly tested.
|
- The minimum supported Rust version was lowered to `1.57.0` and now explicitly tested.
|
||||||
|
|
23
src/dpi.rs
23
src/dpi.rs
|
@ -511,6 +511,29 @@ impl Size {
|
||||||
Size::Logical(size) => size.to_physical(scale_factor),
|
Size::Logical(size) => size.to_physical(scale_factor),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn clamp<S: Into<Size>>(input: S, min: S, max: S, scale_factor: f64) -> Size {
|
||||||
|
let (input, min, max) = (
|
||||||
|
input.into().to_physical::<f64>(scale_factor),
|
||||||
|
min.into().to_physical::<f64>(scale_factor),
|
||||||
|
max.into().to_physical::<f64>(scale_factor),
|
||||||
|
);
|
||||||
|
|
||||||
|
let clamp = |input: f64, min: f64, max: f64| {
|
||||||
|
if input < min {
|
||||||
|
min
|
||||||
|
} else if input > max {
|
||||||
|
max
|
||||||
|
} else {
|
||||||
|
input
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let width = clamp(input.width, min.width, max.width);
|
||||||
|
let height = clamp(input.height, min.height, max.height);
|
||||||
|
|
||||||
|
PhysicalSize::new(width, height).into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: Pixel> From<PhysicalSize<P>> for Size {
|
impl<P: Pixel> From<PhysicalSize<P>> for Size {
|
||||||
|
|
|
@ -879,10 +879,17 @@ impl<'a, T: 'static> InitData<'a, T> {
|
||||||
win.set_fullscreen(attributes.fullscreen);
|
win.set_fullscreen(attributes.fullscreen);
|
||||||
force_window_active(win.window.0);
|
force_window_active(win.window.0);
|
||||||
} else {
|
} else {
|
||||||
let dimensions = attributes
|
let size = attributes
|
||||||
.inner_size
|
.inner_size
|
||||||
.unwrap_or_else(|| PhysicalSize::new(800, 600).into());
|
.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
|
||||||
|
.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);
|
||||||
|
|
||||||
if attributes.maximized {
|
if attributes.maximized {
|
||||||
// Need to set MAXIMIZED after setting `inner_size` as
|
// Need to set MAXIMIZED after setting `inner_size` as
|
||||||
|
|
Loading…
Add table
Reference in a new issue