Skip to content

Commit 3203a85

Browse files
Change window position types from tuple to vec (#5276)
Resolves #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]>
1 parent 2344ada commit 3203a85

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

crates/bevy_window/src/window.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use bevy_math::{DVec2, IVec2, Vec2};
1+
use bevy_math::{DVec2, IVec2, UVec2, Vec2};
22
use bevy_utils::{tracing::warn, Uuid};
33
use raw_window_handle::RawWindowHandle;
44

@@ -202,7 +202,7 @@ pub enum WindowCommand {
202202
/// Set the window's [`WindowMode`].
203203
SetWindowMode {
204204
mode: WindowMode,
205-
resolution: (u32, u32),
205+
resolution: UVec2,
206206
},
207207
/// Set the window's title.
208208
SetTitle {
@@ -214,7 +214,7 @@ pub enum WindowCommand {
214214
},
215215
/// Set the window's resolution.
216216
SetResolution {
217-
logical_resolution: (f32, f32),
217+
logical_resolution: Vec2,
218218
scale_factor: f64,
219219
},
220220
/// Set the window's [`PresentMode`].
@@ -447,7 +447,7 @@ impl Window {
447447
self.requested_width = width;
448448
self.requested_height = height;
449449
self.command_queue.push(WindowCommand::SetResolution {
450-
logical_resolution: (self.requested_width, self.requested_height),
450+
logical_resolution: Vec2::new(self.requested_width, self.requested_height),
451451
scale_factor: self.scale_factor(),
452452
});
453453
}
@@ -464,7 +464,7 @@ impl Window {
464464
scale_factor: self.scale_factor(),
465465
});
466466
self.command_queue.push(WindowCommand::SetResolution {
467-
logical_resolution: (self.requested_width, self.requested_height),
467+
logical_resolution: Vec2::new(self.requested_width, self.requested_height),
468468
scale_factor: self.scale_factor(),
469469
});
470470
}
@@ -668,7 +668,7 @@ impl Window {
668668
self.mode = mode;
669669
self.command_queue.push(WindowCommand::SetWindowMode {
670670
mode,
671-
resolution: (self.physical_width, self.physical_height),
671+
resolution: UVec2::new(self.physical_width, self.physical_height),
672672
});
673673
}
674674
/// Close the operating system window corresponding to this [`Window`].

crates/bevy_winit/src/lib.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use bevy_input::{
1818
mouse::{MouseButtonInput, MouseMotion, MouseScrollUnit, MouseWheel},
1919
touch::TouchInput,
2020
};
21-
use bevy_math::{ivec2, DVec2, Vec2};
21+
use bevy_math::{ivec2, DVec2, UVec2, Vec2};
2222
use bevy_utils::{
2323
tracing::{error, info, trace, warn},
2424
Instant,
@@ -74,7 +74,11 @@ fn change_window(
7474
match command {
7575
bevy_window::WindowCommand::SetWindowMode {
7676
mode,
77-
resolution: (width, height),
77+
resolution:
78+
UVec2 {
79+
x: width,
80+
y: height,
81+
},
7882
} => {
7983
let window = winit_windows.get_window(id).unwrap();
8084
match mode {
@@ -105,7 +109,11 @@ fn change_window(
105109
window_dpi_changed_events.send(WindowScaleFactorChanged { id, scale_factor });
106110
}
107111
bevy_window::WindowCommand::SetResolution {
108-
logical_resolution: (width, height),
112+
logical_resolution:
113+
Vec2 {
114+
x: width,
115+
y: height,
116+
},
109117
scale_factor,
110118
} => {
111119
let window = winit_windows.get_window(id).unwrap();

0 commit comments

Comments
 (0)