Skip to content

Commit

Permalink
Change window position types from tuple to vec (bevyengine#5276)
Browse files Browse the repository at this point in the history
Resolves bevyengine#5004. As suggested in the original issue, change tuple types to their corresponding vector type.

## migration guide

Changed the following fields
- `WindowCommand::SetWindowMode.resolution` from `(u32, u32)` to `UVec2`
- `WindowCommand::SetResolution.logical_resolution` from `(f32, f32)` to `Vec2`

Co-authored-by: Daniel Liu <[email protected]>
  • Loading branch information
2 people authored and inodentry committed Aug 8, 2022
1 parent 292388f commit c47f574
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
12 changes: 6 additions & 6 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy_math::{DVec2, IVec2, Vec2};
use bevy_math::{DVec2, IVec2, UVec2, Vec2};
use bevy_utils::{tracing::warn, Uuid};
use raw_window_handle::RawWindowHandle;

Expand Down Expand Up @@ -202,7 +202,7 @@ pub enum WindowCommand {
/// Set the window's [`WindowMode`].
SetWindowMode {
mode: WindowMode,
resolution: (u32, u32),
resolution: UVec2,
},
/// Set the window's title.
SetTitle {
Expand All @@ -214,7 +214,7 @@ pub enum WindowCommand {
},
/// Set the window's resolution.
SetResolution {
logical_resolution: (f32, f32),
logical_resolution: Vec2,
scale_factor: f64,
},
/// Set the window's [`PresentMode`].
Expand Down Expand Up @@ -447,7 +447,7 @@ impl Window {
self.requested_width = width;
self.requested_height = height;
self.command_queue.push(WindowCommand::SetResolution {
logical_resolution: (self.requested_width, self.requested_height),
logical_resolution: Vec2::new(self.requested_width, self.requested_height),
scale_factor: self.scale_factor(),
});
}
Expand All @@ -464,7 +464,7 @@ impl Window {
scale_factor: self.scale_factor(),
});
self.command_queue.push(WindowCommand::SetResolution {
logical_resolution: (self.requested_width, self.requested_height),
logical_resolution: Vec2::new(self.requested_width, self.requested_height),
scale_factor: self.scale_factor(),
});
}
Expand Down Expand Up @@ -668,7 +668,7 @@ impl Window {
self.mode = mode;
self.command_queue.push(WindowCommand::SetWindowMode {
mode,
resolution: (self.physical_width, self.physical_height),
resolution: UVec2::new(self.physical_width, self.physical_height),
});
}
/// Close the operating system window corresponding to this [`Window`].
Expand Down
14 changes: 11 additions & 3 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use bevy_input::{
mouse::{MouseButtonInput, MouseMotion, MouseScrollUnit, MouseWheel},
touch::TouchInput,
};
use bevy_math::{ivec2, DVec2, Vec2};
use bevy_math::{ivec2, DVec2, UVec2, Vec2};
use bevy_utils::{
tracing::{error, info, trace, warn},
Instant,
Expand Down Expand Up @@ -74,7 +74,11 @@ fn change_window(
match command {
bevy_window::WindowCommand::SetWindowMode {
mode,
resolution: (width, height),
resolution:
UVec2 {
x: width,
y: height,
},
} => {
let window = winit_windows.get_window(id).unwrap();
match mode {
Expand Down Expand Up @@ -105,7 +109,11 @@ fn change_window(
window_dpi_changed_events.send(WindowScaleFactorChanged { id, scale_factor });
}
bevy_window::WindowCommand::SetResolution {
logical_resolution: (width, height),
logical_resolution:
Vec2 {
x: width,
y: height,
},
scale_factor,
} => {
let window = winit_windows.get_window(id).unwrap();
Expand Down

0 comments on commit c47f574

Please sign in to comment.