mirror of
https://github.com/bevyengine/bevy
synced 2024-11-30 00:20:20 +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. |
||
---|---|---|
.. | ||
borders.rs | ||
button.rs | ||
display_and_visibility.rs | ||
flex_layout.rs | ||
font_atlas_debug.rs | ||
grid.rs | ||
overflow.rs | ||
overflow_debug.rs | ||
relative_cursor_position.rs | ||
render_ui_to_texture.rs | ||
size_constraints.rs | ||
text.rs | ||
text_debug.rs | ||
text_wrap_debug.rs | ||
transparency_ui.rs | ||
ui.rs | ||
ui_material.rs | ||
ui_scaling.rs | ||
ui_texture_atlas.rs | ||
ui_texture_atlas_slice.rs | ||
ui_texture_slice.rs | ||
viewport_debug.rs | ||
window_fallthrough.rs | ||
z_index.rs |