Skip to content

Commit

Permalink
workaround to link to bevy type
Browse files Browse the repository at this point in the history
  • Loading branch information
tguichaoua committed Aug 12, 2023
1 parent 7dcd317 commit c7cee10
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ impl Plugin for CursorInfoPlugin {
/// /* ... */
/// }
/// ```
///
/// [`SystemSet`]: https://docs.rs/bevy/0.11.0/bevy/ecs/schedule/trait.SystemSet.html
#[derive(SystemSet, Hash, Debug, PartialEq, Eq, Clone, Copy)]
pub struct UpdateCursorInfo;

Expand Down Expand Up @@ -80,18 +82,29 @@ pub struct CursorInfo(Option<CursorData>);
#[derive(Debug, Clone, PartialEq)]
pub struct CursorData {
/// The position of the cursor in the world.
///
/// See [`Camera::viewport_to_world_2d`].
///
/// [`Camera::viewport_to_world_2d`]: https://docs.rs/bevy/0.11.0/bevy/render/camera/struct.Camera.html#method.viewport_to_world_2d
#[cfg(feature = "2d")]
pub position: Vec2,
/// The [`Ray`] emitted by the cursor from the camera.
///
/// See [`Camera::viewport_to_world`].
///
/// [`Ray`]: https://docs.rs/bevy/0.11.0/bevy/math/struct.Ray.html
/// [`Camera::viewport_to_world`]: https://docs.rs/bevy/0.11.0/bevy/render/camera/struct.Camera.html#method.viewport_to_world
#[cfg(feature = "3d")]
pub ray: Ray,
/// The cursor position in the window in logical pixels.
///
/// See [`cursor_position`](Window::cursor_position()).
/// See [`Window::cursor_position`].
///
/// [`Window::cursor_position`]: https://docs.rs/bevy/0.11.0/bevy/window/struct.Window.html#method.cursor_position
pub window_position: Vec2,
/// The [`Entity`] of the window that contains the cursor.
/// The entity id of the window that contains the cursor.
pub window: Entity,
/// The [`Entity`] of the camera used to compute the world position of the cursor.
/// The entity id of the camera used to compute the world position of the cursor.
pub camera: Entity,
}

Expand All @@ -106,9 +119,11 @@ impl CursorInfo {

/// The position of the cursor in the world.
///
/// See [`Camera::viewport_to_world_2d`](Camera::viewport_to_world_2d).
/// See [`Camera::viewport_to_world_2d`].
///
/// The value is `None` if the cursor is not in any window.
///
/// [`Camera::viewport_to_world_2d`]: https://docs.rs/bevy/0.11.0/bevy/render/camera/struct.Camera.html#method.viewport_to_world_2d
#[cfg(feature = "2d")]
#[inline]
pub fn position(&self) -> Option<Vec2> {
Expand All @@ -117,9 +132,12 @@ impl CursorInfo {

/// The [`Ray`] emitted by the cursor from the camera.
///
/// See [`Camera::viewport_to_world`](Camera::viewport_to_world).
/// See [`Camera::viewport_to_world`].
///
/// The value is `None` if the cursor is not in any window.
///
/// [`Ray`]: https://docs.rs/bevy/0.11.0/bevy/math/struct.Ray.html
/// [`Camera::viewport_to_world`]: https://docs.rs/bevy/0.11.0/bevy/render/camera/struct.Camera.html#method.viewport_to_world
#[cfg(feature = "3d")]
#[inline]
pub fn ray(&self) -> Option<Ray> {
Expand All @@ -128,23 +146,25 @@ impl CursorInfo {

/// The cursor position in the window in logical pixels.
///
/// See [`cursor_position`](Window::cursor_position()).
/// See [`Window::cursor_position`].
///
/// The value is `None` if the cursor is not in any window.
///
/// [`Window::cursor_position`]: https://docs.rs/bevy/0.11.0/bevy/window/struct.Window.html#method.cursor_position
#[inline]
pub fn window_position(&self) -> Option<Vec2> {
self.get().map(|data| data.window_position)
}

/// The [`Entity`] of the window that contains the cursor.
/// The entity id of the window that contains the cursor.
///
/// The value is `None` if the cursor is not in any window.
#[inline]
pub fn window(&self) -> Option<Entity> {
self.get().map(|data| data.window)
}

/// The [`Entity`] of the camera used to compute the world position of the cursor.
/// The entity id of the camera used to compute the world position of the cursor.
///
/// The value is `None` if the cursor is not in any window.
#[inline]
Expand Down

0 comments on commit c7cee10

Please sign in to comment.