Skip to content

Commit

Permalink
Doc: fix and enhancement (#1)
Browse files Browse the repository at this point in the history
* readme: fix link to bevy doc

* workaround to link to bevy type

see rust-lang/docs.rs#1588

* readme: move the link to bevy at the end

* add a link to `CursorInfo` doc
  • Loading branch information
tguichaoua authored Aug 12, 2023
1 parent 4153795 commit 9932986
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
[Build Status]: https://github.com/tguichaoua/bevy_cursor/actions/workflows/ci.yml/badge.svg?branch=main
[actions]: https://github.com/tguichaoua/bevy_cursor/actions/workflows/ci.yml

**Bevy Cursor is a [`bevy`](https://github.com/bevyengine/bevy) plugin to track informations about the cursor.**
**Bevy Cursor is a [`bevy`] plugin to track informations about the cursor.**

---

The following cursor informations are available via the `CursorInfo` resource:
The following cursor informations are available via the [`CursorInfo`] resource:

- The entity id of the window on which the cursor is currently;
- The entity if of the camera on which the cursor is currently;
- The position of the cursor on the window (logical position);
- The 2D world position of the cursor (if the feature `2d` is enabled);
- The [ray](https://docs.rs/bevy/0.11.0/bevy/index.html) emitted by the cursor through the camera (if the feature `3d` is enabled);
- The [ray] emitted by the cursor through the camera (if the feature `3d` is enabled);

## Example

Expand Down Expand Up @@ -54,10 +54,14 @@ fn print_cursor_position(cursor: Res<CursorInfo>) {
## Features

- `2d` opt-in the computation of the world position of the cursor.
- `3d` opt-in the computation of the [ray](https://docs.rs/bevy/0.11.0/bevy/index.html) emitted by the cursor through the camera (disabled by default).
- `3d` opt-in the computation of the [ray] emitted by the cursor through the camera (disabled by default).

## Bevy compatible version

| bevy | bevy_cursor |
| ---- | ----------- |
| 0.11 | 0.1 |

[`bevy`]: https://github.com/bevyengine/bevy
[`CursorInfo`]: https://docs.rs/bevy_cursor/latest/bevy_cursor/struct.CursorInfo.html
[ray]: https://docs.rs/bevy/0.11.0/bevy/math/struct.Ray.html
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 9932986

Please sign in to comment.