Mention in the docs for pointer events that these are in screen-space. (#19518)

# Objective

- Fixes #18109.

## Solution

- All these docs now mention screen-space vs world-space.
- `start_pos` and `latest_pos` both link to `viewport_to_world` and
`viewport_to_world_2d`.
- The remaining cases are all deltas. Unfortunately `Camera` doesn't
have an appropriate method for these cases, and implementing one would
be non-trivial (e.g., the delta could have a different world-space size
based on the depth). For these cases, I just link to `Camera` and
suggest using some of its methods. Not a great solution, but at least it
gets users on the correct track.
This commit is contained in:
andriyDev 2025-06-06 15:20:14 -07:00 committed by GitHub
parent e1230fdc54
commit de79d3f363
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -208,6 +208,11 @@ pub struct Move {
/// Information about the picking intersection.
pub hit: HitData,
/// The change in position since the last move event.
///
/// This is stored in screen pixels, not world coordinates. Screen pixels go from top-left to
/// bottom-right, whereas (in 2D) world coordinates go from bottom-left to top-right. Consider
/// using methods on [`Camera`](bevy_render::camera::Camera) to convert from screen-space to
/// world-space.
pub delta: Vec2,
}
@ -228,8 +233,18 @@ pub struct Drag {
/// Pointer button pressed and moved to trigger this event.
pub button: PointerButton,
/// The total distance vector of a drag, measured from drag start to the current position.
///
/// This is stored in screen pixels, not world coordinates. Screen pixels go from top-left to
/// bottom-right, whereas (in 2D) world coordinates go from bottom-left to top-right. Consider
/// using methods on [`Camera`](bevy_render::camera::Camera) to convert from screen-space to
/// world-space.
pub distance: Vec2,
/// The change in position since the last drag event.
///
/// This is stored in screen pixels, not world coordinates. Screen pixels go from top-left to
/// bottom-right, whereas (in 2D) world coordinates go from bottom-left to top-right. Consider
/// using methods on [`Camera`](bevy_render::camera::Camera) to convert from screen-space to
/// world-space.
pub delta: Vec2,
}
@ -240,6 +255,11 @@ pub struct DragEnd {
/// Pointer button pressed, moved, and released to trigger this event.
pub button: PointerButton,
/// The vector of drag movement measured from start to final pointer position.
///
/// This is stored in screen pixels, not world coordinates. Screen pixels go from top-left to
/// bottom-right, whereas (in 2D) world coordinates go from bottom-left to top-right. Consider
/// using methods on [`Camera`](bevy_render::camera::Camera) to convert from screen-space to
/// world-space.
pub distance: Vec2,
}
@ -296,8 +316,20 @@ pub struct DragDrop {
#[reflect(Clone, PartialEq)]
pub struct DragEntry {
/// The position of the pointer at drag start.
///
/// This is stored in screen pixels, not world coordinates. Screen pixels go from top-left to
/// bottom-right, whereas (in 2D) world coordinates go from bottom-left to top-right. Consider
/// using [`Camera::viewport_to_world`](bevy_render::camera::Camera::viewport_to_world) or
/// [`Camera::viewport_to_world_2d`](bevy_render::camera::Camera::viewport_to_world_2d) to
/// convert from screen-space to world-space.
pub start_pos: Vec2,
/// The latest position of the pointer during this drag, used to compute deltas.
///
/// This is stored in screen pixels, not world coordinates. Screen pixels go from top-left to
/// bottom-right, whereas (in 2D) world coordinates go from bottom-left to top-right. Consider
/// using [`Camera::viewport_to_world`](bevy_render::camera::Camera::viewport_to_world) or
/// [`Camera::viewport_to_world_2d`](bevy_render::camera::Camera::viewport_to_world_2d) to
/// convert from screen-space to world-space.
pub latest_pos: Vec2,
}