bevy/examples/3d
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
..
3d_scene.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
3d_shapes.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
3d_viewport_to_world.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
animated_material.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
anisotropy.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
anti_aliasing.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
atmospheric_fog.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
auto_exposure.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
blend_modes.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
bloom_3d.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
camera_sub_view.rs improve sub view example with dynamic viewports (#15681) 2024-10-08 16:07:31 +00:00
clearcoat.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
color_grading.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
deferred_rendering.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
depth_of_field.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
fog.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
fog_volumes.rs Synchronize removed components with the render world (#15582) 2024-10-08 22:23:17 +00:00
generate_custom_mesh.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
irradiance_volumes.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
lighting.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
lightmaps.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
lines.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
load_gltf.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
load_gltf_extras.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
meshlet.rs Fix meshlet materials (#15755) 2024-10-09 15:39:10 +00:00
motion_blur.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
order_independent_transparency.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
orthographic.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
parallax_mapping.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
parenting.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
pbr.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
pcss.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
post_processing.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
query_gltf_primitives.rs Fix query_gltf_primitives example (#15715) 2024-10-07 23:03:16 +00:00
reflection_probes.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
render_to_texture.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
rotate_environment_map.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
scrolling_fog.rs Fix missing Msaa::Off in scrolling_fog example (#15787) 2024-10-09 14:15:24 +00:00
shadow_biases.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
shadow_caster_receiver.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
skybox.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
spherical_area_lights.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
split_screen.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
spotlight.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
ssao.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
ssr.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
texture.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
tonemapping.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
transmission.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
transparency_3d.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
two_passes.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
update_gltf_scene.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
vertex_colors.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
visibility_range.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
volumetric_fog.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00
wireframe.rs Text rework (#15591) 2024-10-09 18:35:36 +00:00