Skip to content

Commit

Permalink
Rename some Location (formerly CursorData) fields and `CursorLoca…
Browse files Browse the repository at this point in the history
…tion` (formerly `CursorInfo`) methods (#21)

* rename `position` field to `world_position`

* rename `window_position` to `position`
  • Loading branch information
tguichaoua committed Feb 20, 2024
1 parent d6a9903 commit 3a363f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/multiple_windows.rs
Expand Up @@ -340,8 +340,8 @@ fn print_cursor_location(
cursor.camera,
name_q.get(cursor.camera).unwrap().0
),
cursor.window_position.to_string(),
cursor.position.to_string(),
cursor.world_position.to_string(),
);
} else {
set_texts(
Expand Down
18 changes: 9 additions & 9 deletions src/lib.rs
Expand Up @@ -110,7 +110,7 @@ pub struct Location {
/// See [`Window::cursor_position`].
///
/// [`Window::cursor_position`]: https://docs.rs/bevy/0.13.0/bevy/window/struct.Window.html#method.cursor_position
pub window_position: Vec2,
pub position: Vec2,

/// The entity id of the window that contains the cursor.
pub window: Entity,
Expand All @@ -124,7 +124,7 @@ pub struct Location {
///
/// [`Camera::viewport_to_world_2d`]: https://docs.rs/bevy/0.13.0/bevy/render/camera/struct.Camera.html#method.viewport_to_world_2d
#[cfg(feature = "2d")]
pub position: Vec2,
pub world_position: Vec2,

/// The [`Ray3d`] emitted by the cursor from the camera.
///
Expand Down Expand Up @@ -153,8 +153,8 @@ impl CursorLocation {
///
/// [`Window::cursor_position`]: https://docs.rs/bevy/0.13.0/bevy/window/struct.Window.html#method.cursor_position
#[inline]
pub fn window_position(&self) -> Option<Vec2> {
self.get().map(|data| data.window_position)
pub fn position(&self) -> Option<Vec2> {
self.get().map(|data| data.position)
}

/// The entity id of the window that contains the cursor.
Expand Down Expand Up @@ -182,8 +182,8 @@ impl CursorLocation {
/// [`Camera::viewport_to_world_2d`]: https://docs.rs/bevy/0.13.0/bevy/render/camera/struct.Camera.html#method.viewport_to_world_2d
#[cfg(feature = "2d")]
#[inline]
pub fn position(&self) -> Option<Vec2> {
self.get().map(|data| data.position)
pub fn world_position(&self) -> Option<Vec2> {
self.get().map(|data| data.world_position)
}

/// The [`Ray3d`] emitted by the cursor from the camera.
Expand Down Expand Up @@ -255,7 +255,7 @@ fn update_cursor_location_res(
}

#[cfg(feature = "2d")]
let Some(position) = camera.viewport_to_world_2d(cam_t, cursor_position) else {
let Some(world_position) = camera.viewport_to_world_2d(cam_t, cursor_position) else {
continue;
};

Expand All @@ -265,12 +265,12 @@ fn update_cursor_location_res(
};

cursor.set_if_neq(Some(Location {
window_position: cursor_position,
position: cursor_position,
window: win_ref,
camera: camera_ref,

#[cfg(feature = "2d")]
position,
world_position,

#[cfg(feature = "3d")]
ray,
Expand Down

0 comments on commit 3a363f6

Please sign in to comment.