Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ickshonpe/bevy_ui_pointer_capture_detector
detects when the pointer is over Bevy UI nodes
https://github.com/ickshonpe/bevy_ui_pointer_capture_detector
bevy ui
Last synced: 24 days ago
JSON representation
detects when the pointer is over Bevy UI nodes
- Host: GitHub
- URL: https://github.com/ickshonpe/bevy_ui_pointer_capture_detector
- Owner: ickshonpe
- License: mit
- Created: 2022-06-13T23:56:41.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-06T13:00:28.000Z (almost 2 years ago)
- Last Synced: 2024-11-16T18:26:59.728Z (about 1 month ago)
- Topics: bevy, ui
- Language: Rust
- Homepage:
- Size: 206 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bevy_ui_pointer_capture_detector
A plugin that detects if the mouse pointer is above a Bevy Ui Node.
* supports Bevy 0.9## Usage
In your ```Cargo.toml``` ```[dependencies]``` section, add
```toml
bevy_ui_pointer_capture_detector = "0.3"
```This example draws a square red UI node. Each update it sets the
color of the background depending on if the mouse pointer is over the red node:```rust
use bevy::prelude::*;
use bevy_ui_pointer_capture_detector::*;fn setup(
mut commands: Commands
) {
commands
.spawn(Camera2dBundle::default())
.commands()
.spawn(NodeBundle {
style: Style {
margin: UiRect {
left: Val::Px(100.0),
bottom: Val::Px(100.0),
right: Val::Auto,
top: Val::Auto
},
size: Size {
width: Val::Px(100.0),
height: Val::Px(100.0)
},
..Default::default()
},
background_color: BackgroundColor(Color::RED),
..Default::default()
});
}fn is_pointer_captured(
capture: Res,
mut clear_color: ResMut,
) {
clear_color.0 = if capture.is_captured() {
Color::DARK_GRAY
} else {
Color::WHITE
};
}fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(BevyUiPointerCaptureDetectorPlugin)
.add_startup_system(setup)
.add_system(is_pointer_captured)
.run();
}
```
#
### Examples```
cargo run --example example
cargo run --example minimal
```