Skip to content

Commit 1aff709

Browse files
Set cursor updates (#993)
* update `Window::set_cursor_position` to take a `Vec2` instead of `i32`s this allows fractional coordinates to work correctly
1 parent 1f2e417 commit 1aff709

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

crates/bevy_window/src/window.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ pub enum WindowCommand {
8080
visible: bool,
8181
},
8282
SetCursorPosition {
83-
x: i32,
84-
y: i32,
83+
position: Vec2,
8584
},
8685
}
8786

@@ -237,9 +236,9 @@ impl Window {
237236
self.cursor_position
238237
}
239238

240-
pub fn set_cursor_position(&mut self, x: i32, y: i32) {
239+
pub fn set_cursor_position(&mut self, position: Vec2) {
241240
self.command_queue
242-
.push(WindowCommand::SetCursorPosition { x, y });
241+
.push(WindowCommand::SetCursorPosition { position });
243242
}
244243

245244
#[allow(missing_docs)]

crates/bevy_winit/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,14 @@ fn change_window(_: &mut World, resources: &mut Resources) {
9494
let window = winit_windows.get_window(id).unwrap();
9595
window.set_cursor_visible(visible);
9696
}
97-
bevy_window::WindowCommand::SetCursorPosition { x, y } => {
97+
bevy_window::WindowCommand::SetCursorPosition { position } => {
9898
let window = winit_windows.get_window(id).unwrap();
99+
let inner_size = window.inner_size().to_logical::<f32>(window.scale_factor());
99100
window
100-
.set_cursor_position(winit::dpi::LogicalPosition::new(x, y))
101+
.set_cursor_position(winit::dpi::LogicalPosition::new(
102+
position.x,
103+
inner_size.height - position.y,
104+
))
101105
.unwrap_or_else(|e| error!("Unable to set cursor position: {}", e));
102106
}
103107
}

0 commit comments

Comments
 (0)