bevy/crates/bevy_ui/src/render
ickshonpe 5e2ecf4178
Text background colors (#18892)
# 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 <lukowskiolle@gmail.com>
Co-authored-by: Gilles Henaux <ghx_github_priv@fastmail.com>
2025-05-04 08:18:46 +00:00
..
box_shadow.rs Remove the entity index from the UI phase's sort key (#18273) 2025-03-12 17:11:02 +00:00
box_shadow.wgsl Remove the Globals binding from the box shadow shader (#16177) 2024-10-30 20:06:15 +00:00
debug_overlay.rs Store UI render target info locally per node (#17579) 2025-02-10 07:27:58 +00:00
mod.rs Text background colors (#18892) 2025-05-04 08:18:46 +00:00
pipeline.rs Only use physical coords internally in bevy_ui (#16375) 2024-11-22 00:45:07 +00:00
render_pass.rs Remove the entity index from the UI phase's sort key (#18273) 2025-03-12 17:11:02 +00:00
ui_material_pipeline.rs Remove the entity index from the UI phase's sort key (#18273) 2025-03-12 17:11:02 +00:00
ui_material.wgsl UI material border radius (#15171) 2025-01-28 04:54:48 +00:00
ui_texture_slice_pipeline.rs Rename bevy_platform_support to bevy_platform (#18813) 2025-04-11 23:13:28 +00:00
ui_texture_slice.wgsl Fix some duplicate words in docs/comments (#15980) 2024-10-20 01:03:27 +00:00
ui_vertex_output.wgsl UI material border radius (#15171) 2025-01-28 04:54:48 +00:00
ui.wgsl Revert #17631 (#17660) 2025-02-03 19:01:15 +00:00