Skip to content

Commit 7dada6d

Browse files
committed
Fix mouse tracking, consistently use logical position/size
CursorMoved changed in winit 0.21 to return PhysicalPosition, so we need to convert it to LogicalPosition. Change the width/height passed to be LogicalSize instead of a PhysicalPosition, matching the LogicalPosition.
1 parent 72e377b commit 7dada6d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/main.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,9 @@ fn handle_window_event<T>(
507507

508508
WindowEvent::MouseInput { state, button, .. } => match (state, button) {
509509
(ElementState::Released, MouseButton::Left) => {
510-
let (width, height) = window.window().inner_size().into();
510+
let physical_size = window.window().inner_size();
511+
let (width, height) =
512+
physical_size.to_logical::<f64>(game.dpi_factor).into();
511513

512514
if game.server.is_connected()
513515
&& !game.focused
@@ -536,12 +538,14 @@ fn handle_window_event<T>(
536538
(_, _) => (),
537539
},
538540
WindowEvent::CursorMoved { position, .. } => {
539-
let (x, y) = position.into();
541+
let (x, y) = position.to_logical::<f64>(game.dpi_factor).into();
540542
game.last_mouse_x = x;
541543
game.last_mouse_y = y;
542544

543545
if !game.focused {
544-
let (width, height) = window.window().inner_size().into();
546+
let physical_size = window.window().inner_size();
547+
let (width, height) =
548+
physical_size.to_logical::<f64>(game.dpi_factor).into();
545549
ui_container.hover_at(game, x, y, width, height);
546550
}
547551
}

0 commit comments

Comments
 (0)