Remove `TextSpan`s
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## What problem does this solve or what need does it fill?
We have three primary text components, `Text`, `Text2d`, and `TextSpan`. This isn't very ergonomic, and has always felt confusing and overcomplicated to me. I think we could simplify both the user facing API and the text internals by removing the `TextSpan` component. Instead the root and descendant text entities would be differentiated by their positions in the tree.
Concretely, from the `text2d` example:
```rust
(
Text2d::new(" Anchor".to_string()),
slightly_smaller_text_font.clone(),
text_anchor,
TextBackgroundColor(Color::WHITE.darker(0.8)),
Transform::from_translation(-1. * Vec3::Z),
children![
(
TextSpan("::".to_string()),
slightly_smaller_text_font.clone(),
TextColor(LIGHT_GREY.into()),
TextBackgroundColor(DARK_BLUE.into()),
),
(
TextSpan(format!("{text_anchor:?} ")),
slightly_smaller_text_font.clone(),
TextColor(color),
TextBackgroundColor(color.darker(0.3)),
)
],
)
```
This would become:
```rust
(
Text2d::new(" Anchor".to_string()),
slightly_smaller_text_font.clone(),
text_anchor,
TextBackgroundColor(Color::WHITE.darker(0.8)),
Transform::from_translation(-1. * Vec3::Z),
children![
(
Text2d("::".to_string()),
slightly_smaller_text_font.clone(),
TextColor(LIGHT_GREY.into()),
TextBackgroundColor(DARK_BLUE.into()),
),
(
Text2d(format!("{text_anchor:?} ")),
slightly_smaller_text_font.clone(),
TextColor(color),
TextBackgroundColor(color.darker(0.3)),
)
],
)
```
I think it would also make it easier to add custom text implementations. The current API supports custom top level text components but the descendants still all have to be `TextSpan`s. This isn't very flexible, for example, you aren't able to require additional components on the descendant text entities. You also might want to change the `TextSpan` component itself so it's not just a wrapper for a `String`.
## What solution would you like?
Remove `TextSpan`, root text entities would be identified implicitly by their parent not being a text entity.
There would have to be changes in how and where text layouts are stored.
## What alternative(s) have you considered?
Have each text implementation implement its own text span component. `TextSpan` would be specific for UI text, we'd add a `TextSpan2d` component for `Text2d`, and so on.
Contributor guide
Assessment
This issue has not been assessed yet.