From aac09353fdbe615bbaeed54ff234197cf4aca040 Mon Sep 17 00:00:00 2001 From: Minghao Liu Date: Sat, 6 Nov 2021 20:34:31 +0000 Subject: [PATCH] add position to WindowDescriptor (#3070) # Objective Set initial position of the window, so I can start it at the left side of the view automatically, used with `cargo watch` ## Solution add window position to WindowDescriptor --- crates/bevy_window/src/window.rs | 2 ++ crates/bevy_winit/src/winit_windows.rs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/crates/bevy_window/src/window.rs b/crates/bevy_window/src/window.rs index f8e2e249da..94b0e1edda 100644 --- a/crates/bevy_window/src/window.rs +++ b/crates/bevy_window/src/window.rs @@ -525,6 +525,7 @@ impl Window { pub struct WindowDescriptor { pub width: f32, pub height: f32, + pub position: Option, pub resize_constraints: WindowResizeConstraints, pub scale_factor_override: Option, pub title: String, @@ -544,6 +545,7 @@ impl Default for WindowDescriptor { title: "bevy".to_string(), width: 1280., height: 720., + position: None, resize_constraints: WindowResizeConstraints::default(), scale_factor_override: None, vsync: true, diff --git a/crates/bevy_winit/src/winit_windows.rs b/crates/bevy_winit/src/winit_windows.rs index b05f812f4d..8194ddb702 100644 --- a/crates/bevy_winit/src/winit_windows.rs +++ b/crates/bevy_winit/src/winit_windows.rs @@ -44,9 +44,28 @@ impl WinitWindows { let WindowDescriptor { width, height, + position, scale_factor_override, .. } = window_descriptor; + + if let Some(position) = position { + if let Some(sf) = scale_factor_override { + winit_window_builder = winit_window_builder.with_position( + winit::dpi::LogicalPosition::new( + position[0] as f64, + position[1] as f64, + ) + .to_physical::(*sf), + ); + } else { + winit_window_builder = + winit_window_builder.with_position(winit::dpi::LogicalPosition::new( + position[0] as f64, + position[1] as f64, + )); + } + } if let Some(sf) = scale_factor_override { winit_window_builder.with_inner_size( winit::dpi::LogicalSize::new(*width, *height).to_physical::(*sf),