Skip to content

Commit

Permalink
Add separate initial window size
Browse files Browse the repository at this point in the history
  • Loading branch information
thatcomputerguy0101 committed Jul 5, 2024
1 parent 21638a2 commit 24b4b0b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
25 changes: 17 additions & 8 deletions src/window/winit_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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
Expand All @@ -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(),
)
}

Expand Down
14 changes: 9 additions & 5 deletions src/window/winit_window/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down

0 comments on commit 24b4b0b

Please sign in to comment.