Skip to content

TextBackgroundColors #18889

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

Closed
ickshonpe opened this issue Apr 21, 2025 · 0 comments · Fixed by #18892
Closed

TextBackgroundColors #18889

ickshonpe opened this issue Apr 21, 2025 · 0 comments · Fixed by #18892
Labels
A-Accessibility A problem that prevents users with disabilities from using Bevy A-Rendering Drawing game state to the screen A-Text Rendering and layout for characters A-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible

Comments

@ickshonpe
Copy link
Contributor

What problem does this solve or what need does it fill?

Add background colors to text spans.

Extra graphics options for UI and allows better contrast for improved color blindness accessibility.

What solution would you like?

A TextBackgroundColor component you can optionally add to text sections.

@ickshonpe ickshonpe added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled A-UI Graphical user interfaces, styles, layouts, and widgets A-Rendering Drawing game state to the screen A-Accessibility A problem that prevents users with disabilities from using Bevy A-Text Rendering and layout for characters and removed S-Needs-Triage This issue needs to be labelled labels Apr 21, 2025
github-merge-queue bot pushed a commit that referenced this issue May 4, 2025
# Objective

Add background colors for text.

Fixes #18889

## Solution

New component `TextBackgroundColor`, add it to any UI `Text` or
`TextSpan` entity to add a background color to its text.
New field on `TextLayoutInfo` `section_rects` holds the list of bounding
rects for each text section.

The bounding rects are generated in `TextPipeline::queue_text` during
text layout, `extract_text_background_colors` extracts the colored
background rects for rendering.

Didn't include `Text2d` support because of z-order issues.

The section rects can also be used to implement interactions targeting
individual text sections.

## Testing
Includes a basic example that can be used for testing:
```
cargo run --example text_background_colors
```
---

## Showcase


![tbcm](https://github.com/user-attachments/assets/e584e197-1a8c-4248-82ab-2461d904a85b)

Using a proportional font with kerning the results aren't so tidy (since
the bounds of adjacent glyphs can overlap) but it still works fine:


![tbc](https://github.com/user-attachments/assets/788bb052-4216-4019-a594-7c1b41164dd5)

---------

Co-authored-by: Olle Lukowski <[email protected]>
Co-authored-by: Gilles Henaux <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Accessibility A problem that prevents users with disabilities from using Bevy A-Rendering Drawing game state to the screen A-Text Rendering and layout for characters A-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant