Skip to content

Commit 056f122

Browse files
committed
Update MouseMotion and CursorMoved docs (#5090)
# Objective - Fixes #5083 ## Solution I looked at the implementation of those events. I noticed that they both are adaptations of `winit`'s `DeviceEvent`/`WindowEvent` enum variants. Therefore I based the description of the items on the documentation provided by the upstream crate. I also added a link to `CursorMoved`, just like `MouseMotion` already has. ## Observations - Looking at the implementation of `MouseMotion`, I noticed the `DeviceId` field of the `winit` event is discarded by `bevy_input`. This means that in the case a machine has multiple pointing devices, it is impossible to distinguish to which one the event is referring to. **EDIT:** just tested, `MouseMotion` events are emitted for movement of both mice.
1 parent 1bd33ca commit 056f122

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

crates/bevy_input/src/mouse.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,18 @@ pub enum MouseButton {
4141
Other(u16),
4242
}
4343

44-
/// A mouse motion event.
44+
/// An event reporting the change in physical position of a pointing device.
4545
///
46-
/// This event is the translated version of the `DeviceEvent::MouseMotion` from the `winit` crate.
46+
/// This represents raw, unfiltered physical motion.
47+
/// It is the translated version of [`DeviceEvent::MouseMotion`] from the `winit` crate.
48+
///
49+
/// All pointing devices connected to a single machine at the same time can emit the event independently.
50+
/// However, the event data does not make it possible to distinguish which device it is referring to.
51+
///
52+
/// [`DeviceEvent::MouseMotion`]: https://docs.rs/winit/latest/winit/event/enum.DeviceEvent.html#variant.MouseMotion
4753
#[derive(Debug, Clone)]
4854
pub struct MouseMotion {
49-
/// The delta of the previous and current mouse positions.
55+
/// The change in the position of the pointing device since the last event was sent.
5056
pub delta: Vec2,
5157
}
5258

crates/bevy_window/src/event.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,21 @@ pub struct WindowCloseRequested {
5858
pub struct WindowClosed {
5959
pub id: WindowId,
6060
}
61-
/// An event that is sent whenenver the user's cursor moves.
61+
/// An event reporting that the mouse cursor has moved on a window.
62+
///
63+
/// The event is sent only if the cursor is over one of the application's windows.
64+
/// It is the translated version of [`WindowEvent::CursorMoved`] from the `winit` crate.
65+
///
66+
/// Not to be confused with the [`MouseMotion`] event from `bevy_input`.
67+
///
68+
/// [`WindowEvent::CursorMoved`]: https://docs.rs/winit/latest/winit/event/enum.WindowEvent.html#variant.CursorMoved
69+
/// [`MouseMotion`]: bevy_input::mouse::MouseMotion
6270
#[derive(Debug, Clone)]
6371
pub struct CursorMoved {
72+
/// The identifier of the window the cursor has moved on.
6473
pub id: WindowId,
74+
75+
/// The position of the cursor, in window coordinates.
6576
pub position: Vec2,
6677
}
6778
/// An event that is sent whenever the user's cursor enters a window.

0 commit comments

Comments
 (0)