Skip to content

Commit

Permalink
Merge pull request #61 from bytestring-net/dev
Browse files Browse the repository at this point in the history
Docs and example improvements
  • Loading branch information
IDEDARY authored Jul 20, 2024
2 parents 2b810af + 5b44690 commit 636e7c3
Show file tree
Hide file tree
Showing 31 changed files with 282 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{
"type": "cargo",
"command": "run",
"args": ["--bin", "minimal"],
"args": ["--bin", "worldspace"],
"problemMatcher": [
"$rustc"
],
Expand Down
3 changes: 0 additions & 3 deletions crates/bevy_lunex/src/logic/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,12 @@ pub struct CursorBundle {
pub cursor: Cursor2d,
/// The virtual pointer that the cursor controls
pub pointer: PointerBundle,
/// Required for Cursor to exist
pub spatial: SpatialBundle,
}
impl Default for CursorBundle {
fn default() -> Self {
Self {
cursor: default(),
pointer: PointerBundle::new(PointerId::Custom(pointer::Uuid::new_v4())),
spatial: default(),
}
}
}
Expand Down
38 changes: 19 additions & 19 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
# Summary

[Introduction](1_overview.md)
[Introduction](overview.md)

---

# Getting started

- [Installation](2_installation.md)
- [Quick start](3_quick_start.md)
- [Debug](4_debug.md)
- [Installation](installation.md)
- [Quick start](quick_start.md)
- [Debug](debug.md)

---

# Advanced
- [Linking](advanced/0_linking.md)
- [Layouts](advanced/1_layouts.md)
- [Units](advanced/2_units.md)
- [Cursor](advanced/3_cursor.md)
- [Text](advanced/4_text.md)
- [Abstraction](advanced/5_abstraction.md)
- [Components](advanced/abstraction/1_components.md)
- [Routes](advanced/abstraction/2_routes.md)
- [Interactivity](advanced/6_interactivity.md)
- [Animation](advanced/7_animation.md)
- [2D & 3D](advanced/8_2d_and_3d.md)
- [Worldspace UI](advanced/9_worldspace_ui.md)
- [Custom rendering](advanced/10_rendering.md)
- [Linking](advanced/linking.md)
- [Layouts](advanced/layouts.md)
- [Units](advanced/units.md)
- [Cursor](advanced/cursor.md)
- [Text](advanced/text.md)
- [Abstraction](advanced/abstraction.md)
- [Components](advanced/abstraction/components.md)
- [Routes](advanced/abstraction/routes.md)
- [Interactivity](advanced/interactivity.md)
- [Animation](advanced/animation.md)
- [2D & 3D](advanced/2d_and_3d.md)
- [Worldspace UI](advanced/worldspace_ui.md)
- [Custom rendering](advanced/rendering.md)

-----------

[Contributors](5_contributors.md)
[Help](6_help.md)
[Contributors](contributors.md)
[Help](help.md)
File renamed without changes.
108 changes: 0 additions & 108 deletions docs/src/advanced/3_cursor.md

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
83 changes: 83 additions & 0 deletions docs/src/advanced/cursor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Cursor

Lunex provides a custom abstraction for a cursor related features within your Bevy application.
This is achieved by moving all logic to a an entity that is spawned into the world.
It is required that you spawn this entity, otherwise picking won't work.

### Requirements

You need to spawn this bundle for native cursor to work

```rust
commands.spawn( CursorBundle::default() )
```

### Styled cursors

You can also attach custom image to your cursor entity. First, you will also need to have all the cursor icons in a image strip like this:

![Cursor](../images/cursor.png)

Then you can use `StyledCursorBundle` instead of `CursorBundle`.

```rust
commands.spawn(StyledCursorBundle {
// Put texture atlas and sprite bundle here
..default()
})
```

Make sure you spawn `StyledCursorBundle` as a child of 2D `Camera`, otherwise the sprite would not follow the view.

### Gamepad support

To bind a cursor to a gamepad, you have to add this component:

```rust
GamepadCursor::new(0),
```

If you want the cursor to accept both Mouse and Gamepad inputs, you have to create an additional
system that listens to recent input events and based on them "removes" or "adds" this component.

Currently, there is only 1 mode supported and that is `Free` which means you just use your stick to move
the cursor around. There is no "jumping" yet.

However, it is planned to add `Snap` mode, which makes the cursor "jump" and snap to the next node in input direction.

## Example

Here's an example of how to set up a custom cursor with gamepad control:

```rust
// Spawn cursor
camera.spawn ((
StyledCursorBundle {
// Here we can map different native cursor icons to texture atlas indexes and sprite offsets
cursor: Cursor2d::new()
.set_index(CursorIcon::Default, 0, (14.0, 14.0))
.set_index(CursorIcon::Pointer, 1, (10.0, 12.0))
.set_index(CursorIcon::Grab, 2, (40.0, 40.0)),
// Add texture atlas to the cursor
atlas: TextureAtlas {
layout: atlas_layout.add(TextureAtlasLayout::from_grid(UVec2::splat(80), 3, 1, None, None)),
index: 0,
},
// Add sprite strip to the cursor
sprite: SpriteBundle {
texture: assets.load("cursor.png"),
transform: Transform { scale: Vec3::new(0.45, 0.45, 1.0), ..default() },
sprite: Sprite {
color: Color::YELLOW.with_alpha(2.0),
anchor: Anchor::TopLeft,
..default()
},
..default()
},
..default()
},

// Here we specify that the cursor should be controlled by gamepad 0
GamepadCursor::new(0),
));
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions docs/src/6_help.md → docs/src/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ For issues related to the library, please create a ticket on [`GitHub`](https://
You can also reach out to me on the [`Bevy Discord`](https://discord.gg/bevy), where you can use the [`#Ecosystem-crates: Bevy Lunex`](https://discord.com/channels/691052431525675048/1034543904478998539) thread.

For specific questions, feel free to send me a direct message on Discord: `@idedary`.
_Just make sure you are in the Bevy discord or otherwise I will ignore you_.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 1 addition & 7 deletions examples/mesh2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
publish = false

[dependencies]
bevy = { version = "0.14.0-rc.2", default_features = false, features = [
bevy = { version = "^0.14.0", default_features = false, features = [
"bevy_asset",
"bevy_gilrs",
"bevy_winit",
Expand All @@ -17,12 +17,6 @@
"bevy_text",
"multi_threaded",
"png",
"hdr",
"x11",
"bevy_gizmos",
"tonemapping_luts",
"default_font",

"dynamic_linking",
] }
bevy_lunex = { workspace = true, features=["debug"] }
8 changes: 1 addition & 7 deletions examples/minimal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
publish = false

[dependencies]
bevy = { version = "0.14.0-rc.2", default_features = false, features = [
bevy = { version = "^0.14.0", default_features = false, features = [
"bevy_asset",
"bevy_gilrs",
"bevy_winit",
Expand All @@ -17,12 +17,6 @@
"bevy_text",
"multi_threaded",
"png",
"hdr",
"x11",
"bevy_gizmos",
"tonemapping_luts",
"default_font",

"dynamic_linking",
] }
bevy_lunex = { workspace = true, features=["debug"] }
24 changes: 24 additions & 0 deletions examples/worldspace/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "worldspace"
authors.workspace = true
version.workspace = true
edition.workspace = true
publish = false

[dependencies]
bevy = { version = "^0.14.0", default_features = false, features = [
"bevy_asset",
"bevy_winit",
"bevy_core_pipeline",
"bevy_pbr",
"bevy_render",
"bevy_sprite",
"bevy_text",
"multi_threaded",
"png",
"hdr",
"vorbis",
"x11",
"tonemapping_luts",
] }
bevy_lunex = { workspace = true, features=["debug"] }
Binary file added examples/worldspace/assets/panel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 636e7c3

Please sign in to comment.