Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add separate initial window size #465

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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