diff --git a/src/window/winit_window.rs b/src/window/winit_window.rs index 9decb601b..2056f5d10 100644 --- a/src/window/winit_window.rs +++ b/src/window/winit_window.rs @@ -105,12 +105,20 @@ impl Window { )) .with_decorations(!window_settings.borderless); - if let Some((width, height)) = window_settings.max_size { - window_builder - .with_inner_size(dpi::LogicalSize::new(width as f64, height as f64)) - .with_max_inner_size(dpi::LogicalSize::new(width as f64, height as f64)) - } else { - window_builder.with_maximized(true) + match (window_settings.initial_size, window_settings.max_size) { + (Some((width, height)), Some((max_width, max_height))) => + window_builder + .with_inner_size(dpi::LogicalSize::new(width as f64, height as f64)) + .with_max_inner_size(dpi::LogicalSize::new(max_width as f64, max_height as f64)), + (Some((width, height)), None) => + window_builder + .with_inner_size(dpi::LogicalSize::new(width as f64, height as f64)), + (None, Some((width, height))) => + window_builder + .with_inner_size(dpi::LogicalSize::new(width as f64, height as f64)) + .with_max_inner_size(dpi::LogicalSize::new(width as f64, height as f64)), + (None, None) => + window_builder.with_maximized(true) } }; #[cfg(target_arch = "wasm32")] @@ -135,7 +143,8 @@ impl Window { }; let inner_size = window_settings - .max_size + .initial_size + .or(window_settings.max_size) .map(|(width, height)| LogicalSize::new(width as f64, height as f64)) .unwrap_or_else(|| { let browser_window = canvas @@ -162,7 +171,7 @@ impl Window { winit_window, event_loop, window_settings.surface_settings, - window_settings.max_size.is_none(), + window_settings.max_size.is_none() && window_settings.initial_size.is_none(), ) } diff --git a/src/window/winit_window/settings.rs b/src/window/winit_window/settings.rs index 3e72dc8c3..e7891f767 100644 --- a/src/window/winit_window/settings.rs +++ b/src/window/winit_window/settings.rs @@ -67,13 +67,16 @@ pub struct WindowSettings { /// /// On web this has no effect. pub min_size: (u32, u32), - /// The maximum and initial size of the window `(width, height)`, in logical pixels. - /// If `None` is specified, the window is maximized. + /// The maximum size of the window `(width, height)`, in logical pixels. + /// If `None` is specified, the window can be maximized. + pub max_size: Option<(u32, u32)>, + /// The initial size of the window `(width, height)`, in logical pixels. + /// If `None` is specified, defaults to max_size. /// /// On web, the size will be applied to the [canvas][WindowSettings::canvas], in logical pixels. - /// If `None` is specified, the canvas will be resized to the same size as - /// the owner `Window`'s inner width and height. - pub max_size: Option<(u32, u32)>, + /// If `None` is specified on both this and max_size, the canvas will be + /// resized to the same size as the owner `Window`'s inner width and height. + pub initial_size: Option<(u32, u32)>, /// Borderless mode. /// /// On web this has no effect. @@ -92,6 +95,7 @@ impl Default for WindowSettings { title: "".to_string(), min_size: (2, 2), max_size: None, + initial_size: None, borderless: false, #[cfg(target_arch = "wasm32")] canvas: None,