Skip to content

Rewrite Text migration guide for 0.15 #1814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions release-content/0.15/migration-guides/15591_Text_rework.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
TODO: very breaking
The `Text` API in Bevy has been overhauled in several ways as part of Bevy 0.15.
There are several major changes to consider:

__Accessing text spans by index__
- `ab_glyph` has been replaced with `cosmic-text`. These changes are mostly internal and the majority of users will not interact with either text backend directly.
- each text section is now stored as a distinct entity within the standard hierarchy, rather than as a `Vec<TextSection>` on the `Text` component. Children of `Text`/`Text2d` entities with `TextSpan` components will act as additional text sections.
- like other aspects of Bevy's API, required components have replaced bundles

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.
## `TextBundle` and text styling

`TextBundle` has been removed.
Add the `Text` component to set the string displayed.

`TextLayout`, `TextFont` and `TextColor` are required components for `Text`,
and are automatically added whenever `Text` is.
Set those values to change the text section's style.

Like elsewhere in Bevy, there is no style inheritance. Consider [writing your own abstraction for this](https://github.com/viridia/thorium_ui/blob/main/crates/thorium_ui_controls/src/text_styles.rs) if this is something you'd like to use.

To control the layout of a `Text` section, modify the properties of its `Node`.

## Accessing text spans by index

Previously, text sections were elements of a vector stored within `Text`.
Now, they are stored as distinct entities under the same `Parent`.
You can use the new `TextUiReader` and `TextUiWriter` system parameters to conveniently access text spans by index.

Before:

Expand All @@ -26,6 +46,9 @@ fn refresh_text(
}
```

__Iterating text spans__
2D equivalents (`Text2dReader` and `Text2dWriter`) also exist.

## Internal layout information

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.
`TextBundle` additional fields have been moved into the `TextNodeFlags` component,
while `Text2dBundle`'s additional fields turned into the `TextBounds` and `Anchor` components.
2 changes: 1 addition & 1 deletion release-content/0.15/migration-guides/_guides.toml
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ file_name = "15579_Migrate_scenes_to_required_components.md"

[[guides]]
title = "Text rework"
prs = [15591]
prs = [15591, 15887]
areas = ["Text"]
file_name = "15591_Text_rework.md"

Expand Down