bevy/examples/ui
Alice Cecile 336fddb101
Make default behavior for BackgroundColor and BorderColor more intuitive (#14017)
# Objective

In Bevy 0.13, `BackgroundColor` simply tinted the image of any
`UiImage`. This was confusing: in every other case (e.g. Text), this
added a solid square behind the element. #11165 changed this, but
removed `BackgroundColor` from `ImageBundle` to avoid confusion, since
the semantic meaning had changed.

However, this resulted in a serious UX downgrade / inconsistency, as
this behavior was no longer part of the bundle (unlike for `TextBundle`
or `NodeBundle`), leaving users with a relatively frustrating upgrade
path.

Additionally, adding both `BackgroundColor` and `UiImage` resulted in a
bizarre effect, where the background color was seemingly ignored as it
was covered by a solid white placeholder image.

Fixes #13969.

## Solution

Per @viridia's design:

> - if you don't specify a background color, it's transparent.
> - if you don't specify an image color, it's white (because it's a
multiplier).
> - if you don't specify an image, no image is drawn.
> - if you specify both a background color and an image color, they are
independent.
> - the background color is drawn behind the image (in whatever pixels
are transparent)

As laid out by @benfrankel, this involves:

1. Changing the default `UiImage` to use a transparent texture but a
pure white tint.
2. Adding `UiImage::solid_color` to quickly set placeholder images.
3. Changing the default `BorderColor` and `BackgroundColor` to
transparent.
4. Removing the default overrides for these values in the other assorted
UI bundles.
5. Adding `BackgroundColor` back to `ImageBundle` and `ButtonBundle`.
6. Adding a 1x1 `Image::transparent`, which can be accessed from
`Assets<Image>` via the `TRANSPARENT_IMAGE_HANDLE` constant.

Huge thanks to everyone who helped out with the design in the linked
issue and [the Discord
thread](https://discord.com/channels/691052431525675048/1255209923890118697/1255209999278280844):
this was very much a joint design.

@cart helped me figure out how to set the UiImage's default texture to a
transparent 1x1 image, which is a much nicer fix.

## Testing

I've checked the examples modified by this PR, and the `ui` example as
well just to be sure.

## Migration Guide

- `BackgroundColor` no longer tints the color of images in `ImageBundle`
or `ButtonBundle`. Set `UiImage::color` to tint images instead.
- The default texture for `UiImage` is now a transparent white square.
Use `UiImage::solid_color` to quickly draw debug images.
- The default value for `BackgroundColor` and `BorderColor` is now
transparent. Set the color to white manually to return to previous
behavior.
2024-06-25 21:50:41 +00:00
..
borders.rs Update borders example to match rounded_borders example (#12630) 2024-03-21 18:38:58 +00:00
button.rs Make default behavior for BackgroundColor and BorderColor more intuitive (#14017) 2024-06-25 21:50:41 +00:00
display_and_visibility.rs Make default behavior for BackgroundColor and BorderColor more intuitive (#14017) 2024-06-25 21:50:41 +00:00
flex_layout.rs Omit font size where it closely matches the default in examples (#13952) 2024-06-20 21:01:28 +00:00
font_atlas_debug.rs Adding explanation to seeded rng used in examples (#12593) 2024-03-26 19:40:18 +00:00
grid.rs Omit font size where it closely matches the default in examples (#13952) 2024-06-20 21:01:28 +00:00
overflow.rs Updates default Text font size to 24px (#13603) 2024-05-31 16:41:27 +00:00
overflow_debug.rs Updates default Text font size to 24px (#13603) 2024-05-31 16:41:27 +00:00
relative_cursor_position.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
render_ui_to_texture.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
rounded_borders.rs Add border radius to UI nodes (adopted) (#12500) 2024-03-19 22:44:00 +00:00
size_constraints.rs Make default behavior for BackgroundColor and BorderColor more intuitive (#14017) 2024-06-25 21:50:41 +00:00
text.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
text_debug.rs Updates default Text font size to 24px (#13603) 2024-05-31 16:41:27 +00:00
text_wrap_debug.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
transparency_ui.rs Make default behavior for BackgroundColor and BorderColor more intuitive (#14017) 2024-06-25 21:50:41 +00:00
ui.rs Updates default Text font size to 24px (#13603) 2024-05-31 16:41:27 +00:00
ui_material.rs Highlight dependency on shader files in examples (#13824) 2024-06-12 14:16:01 +00:00
ui_scaling.rs Updates default Text font size to 24px (#13603) 2024-05-31 16:41:27 +00:00
ui_texture_atlas.rs Make default behavior for BackgroundColor and BorderColor more intuitive (#14017) 2024-06-25 21:50:41 +00:00
ui_texture_atlas_slice.rs Slicing support for texture atlas (#12059) 2024-03-05 16:05:39 +00:00
ui_texture_slice.rs Slicing support for texture atlas (#12059) 2024-03-05 16:05:39 +00:00
viewport_debug.rs Fix green colors becoming darker in various examples (#12328) 2024-03-05 23:42:03 +00:00
window_fallthrough.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
z_index.rs Fix green colors becoming darker in various examples (#12328) 2024-03-05 23:42:03 +00:00