bevy/crates
UkoeHB c2c19e5ae4
Text rework (#15591)
**Ready for review. Examples migration progress: 100%.**

# Objective

- Implement https://github.com/bevyengine/bevy/discussions/15014

## Solution

This implements [cart's
proposal](https://github.com/bevyengine/bevy/discussions/15014#discussioncomment-10574459)
faithfully except for one change. I separated `TextSpan` from
`TextSpan2d` because `TextSpan` needs to require the `GhostNode`
component, which is a `bevy_ui` component only usable by UI.

Extra changes:
- Added `EntityCommands::commands_mut` that returns a mutable reference.
This is a blocker for extension methods that return something other than
`self`. Note that `sickle_ui`'s `UiBuilder::commands` returns a mutable
reference for this reason.

## Testing

- [x] Text examples all work.

---

## Showcase

TODO: showcase-worthy

## Migration Guide

TODO: very breaking

### Accessing text spans by index

Text sections are now text sections on different entities in a
hierarchy, Use the new `TextReader` and `TextWriter` system parameters
to access spans by index.

Before:
```rust
fn refresh_text(mut query: Query<&mut Text, With<TimeText>>, time: Res<Time>) {
    let text = query.single_mut();
    text.sections[1].value = format_time(time.elapsed());
}
```

After:
```rust
fn refresh_text(
    query: Query<Entity, With<TimeText>>,
    mut writer: UiTextWriter,
    time: Res<Time>
) {
    let entity = query.single();
    *writer.text(entity, 1) = format_time(time.elapsed());
}
```

### Iterating text spans

Text spans are now entities in a hierarchy, so the new `UiTextReader`
and `UiTextWriter` system parameters provide ways to iterate that
hierarchy. The `UiTextReader::iter` method will give you a normal
iterator over spans, and `UiTextWriter::for_each` lets you visit each of
the spans.

---------

Co-authored-by: ickshonpe <david.curthoys@googlemail.com>
Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2024-10-09 18:35:36 +00:00
..
bevy_a11y Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
bevy_animation Remove thiserror from bevy_animation (#15780) 2024-10-09 14:16:21 +00:00
bevy_app Rename App/World::observe to add_observer, EntityWorldMut::observe_entity to observe. (#15754) 2024-10-09 15:39:29 +00:00
bevy_asset Remove thiserror from bevy_asset (#15778) 2024-10-09 14:30:46 +00:00
bevy_audio Fix audio not playing (#15638) 2024-10-04 01:07:09 +00:00
bevy_color Remove thiserror from bevy_color (#15777) 2024-10-09 14:18:41 +00:00
bevy_core Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
bevy_core_pipeline Remove thiserror from bevy_core_pipeline (#15775) 2024-10-09 14:20:16 +00:00
bevy_derive move ANDROID_APP to bevy_window (#15585) 2024-10-02 03:01:06 +00:00
bevy_dev_tools Text rework (#15591) 2024-10-09 18:35:36 +00:00
bevy_diagnostic Update sysinfo requirement from 0.31.0 to 0.32.0 (#15697) 2024-10-07 07:31:17 +00:00
bevy_dylib Generate links to definition in source code pages on docs.rs and dev-docs.bevyengine.org (#12965) 2024-07-29 23:10:16 +00:00
bevy_ecs Text rework (#15591) 2024-10-09 18:35:36 +00:00
bevy_encase_derive Update `glam to 0.29, encase` to 0.10. (#15249) 2024-09-23 19:44:02 +00:00
bevy_gilrs Remove thiserror from bevy_gilrs (#15773) 2024-10-09 14:21:25 +00:00
bevy_gizmos Fix failing cargo check with only the bevy_dev_tools feature (#15743) 2024-10-08 22:41:04 +00:00
bevy_gltf Remove thiserror from bevy_gltf (#15772) 2024-10-09 14:22:00 +00:00
bevy_hierarchy Add more tools for traversing hierarchies (#15627) 2024-10-07 15:24:57 +00:00
bevy_image Remove thiserror from bevy_image (#15771) 2024-10-09 14:23:53 +00:00
bevy_input Remove thiserror from bevy_input (#15770) 2024-10-09 14:23:01 +00:00
bevy_internal Feature-gate all image formats (#15586) 2024-10-07 16:37:45 +00:00
bevy_log Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
bevy_macro_utils Modify derive_label to support no_std environments (#15465) 2024-09-27 20:23:26 +00:00
bevy_math Put curve-related stuff behind a feature (#15790) 2024-10-09 16:38:23 +00:00
bevy_mesh Remove thiserror from bevy_mesh (#15768) 2024-10-09 14:24:54 +00:00
bevy_mikktspace Add no_std support to bevy_mikktspace (#15528) 2024-09-30 18:17:03 +00:00
bevy_pbr Remove Handle<T> trait implementations that are dependent on Component (#15749) 2024-10-09 17:12:27 +00:00
bevy_picking Rename App/World::observe to add_observer, EntityWorldMut::observe_entity to observe. (#15754) 2024-10-09 15:39:29 +00:00
bevy_ptr Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
bevy_reflect bevy_reflect: Add crate level functions feature docs (#15086) 2024-10-09 18:06:56 +00:00
bevy_remote Watching versions of bevy/get and bevy/list with HTTP SSE (#15608) 2024-10-08 16:21:46 +00:00
bevy_render Remove Handle<T> trait implementations that are dependent on Component (#15749) 2024-10-09 17:12:27 +00:00
bevy_scene Rename App/World::observe to add_observer, EntityWorldMut::observe_entity to observe. (#15754) 2024-10-09 15:39:29 +00:00
bevy_sprite Migrate bevy_sprite to required components (#15489) 2024-10-09 16:17:26 +00:00
bevy_state Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
bevy_tasks bump async-channel to 2.3.0 (#15497) 2024-09-28 19:21:59 +00:00
bevy_text Text rework (#15591) 2024-10-09 18:35:36 +00:00
bevy_time Remove thiserror from bevy_time (#15759) 2024-10-09 14:13:28 +00:00
bevy_transform Remove thiserror from bevy_transform (#15761) 2024-10-09 14:27:30 +00:00
bevy_ui Text rework (#15591) 2024-10-09 18:35:36 +00:00
bevy_utils Minor fixes for bevy_utils in no_std (#15463) 2024-10-04 19:25:49 +00:00
bevy_window Add the functions start_drag_move and start_drag_resize to Window (#15674) 2024-10-08 16:32:07 +00:00
bevy_winit Rename App/World::observe to add_observer, EntityWorldMut::observe_entity to observe. (#15754) 2024-10-09 15:39:29 +00:00