mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
5b29402cc8
# Objective This idea came up in the context of a hypothetical "text sections as entities" where text sections are children of a text bundle. ```rust commands .spawn(TextBundle::default()) .with_children(|parent} { parent.spawn(TextSection::from("Hello")); }); ``` This is a bit cumbersome (but powerful and probably the way things are headed). [`bsn!`](https://github.com/bevyengine/bevy/discussions/14437) will eventually make this nicer, but in the mean time, this might improve ergonomics for the common case where there is only one `TextSection`. ## Solution Add a `with_child` method to the `BuildChildren` trait that spawns a single bundle and adds it as a child to the entity. ```rust commands .spawn(TextBundle::default()) .with_child(TextSection::from("Hello")); ``` ## Testing I added some tests, and modified the `button` example to use the new method. If any potential co-authors want to improve the tests, that would be great. ## Alternatives - Some sort of macro. See https://github.com/tigregalis/bevy_spans_ent/blob/main/examples/macro.rs#L20. I don't love this, personally, and it would probably be obsoleted by `bsn!`. - Wait for `bsn!` - Add `with_children_batch` that takes an `Into<Iterator>` of bundles. ```rust with_children_batch(vec![TextSection::from("Hello")]) ``` This is maybe not as useful as it sounds -- it only works with homogeneous bundles, so no marker components or styles. - If this doesn't seem valuable, doing nothing is cool with me. |
||
---|---|---|
.. | ||
src | ||
Cargo.toml | ||
README.md |