https://github.com/ickshonpe/marked-commands
A macro for Bevy that generates extension traits that add marker components to entities when spawned.
https://github.com/ickshonpe/marked-commands
Last synced: about 1 month ago
JSON representation
A macro for Bevy that generates extension traits that add marker components to entities when spawned.
- Host: GitHub
- URL: https://github.com/ickshonpe/marked-commands
- Owner: ickshonpe
- License: mit
- Created: 2022-02-07T13:24:08.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-07T13:57:19.000Z (over 4 years ago)
- Last Synced: 2025-06-23T10:51:02.550Z (12 months ago)
- Language: Rust
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Marked Commands
Generates an extension trait that implements the methods
`marked` and `marked_bundle` (and some other ones) equivalent to
`spawn` and `spawn_bundle` except the new entities will also contain
the marker components passed to the macro.
The marker components must implement `Default`.
## usage example
```rust
marked_commands!((UIElementMarker,));
pub fn spawn_text_box(
mut commands: Commands,
asset_server: Res,
) {
commands.marked_bundle(NodeBundle {
style: Style {
position_type: PositionType::Absolute,
position: Rect { left: Val::Px(100.0), bottom: Val::Px(100.0), ..Default::default() },
padding: Rect::all(Val::Px(2.0)),
..Default::default()
},
..Default::default()
})
.with_children(|builder| {
builder.marked_bundle(NodeBundle {
color: UiColor (Color::DARK_GRAY),
style: Style {
padding: Rect::all(Val::Px(4.0)),
..Default::default()
},
..Default::default()
}
)
.with_children(|builder| {
builder.marked_bundle(TextBundle {
text: Text::with_section(
"Hello, world!",
TextStyle {
font: asset_server.load("FiraMono-Regular.ttf"),
font_size: 16.0,
color: Color::ANTIQUE_WHITE,
},
TextAlignment::default()
),
..Default::default()
});
});
});
}
pub fn despawn_text_box(
mut commands: Commands,
query: Query>
) {
query.for_each(|entity|
commands.entity(entity).despawn();
);
}
```
## Info
* Takes a bundle, so you can add as many marker components as you like! 100, why not.
* I wouldn't use this (because it's a macro).
* The example is bad. You only need to mark the root `NodeBundle` and then call `despawn_recursive`.
But then do you really need the macro if you are only marking the root.