bevy/examples/3d
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
..
3d_scene.rs Swapping back to using From<Color> for StandardMaterial in examples (#13566) 2024-05-29 13:50:28 +00:00
3d_shapes.rs Meshable extrusions (#13478) 2024-06-04 17:27:32 +00:00
3d_viewport_to_world.rs Swapping back to using From<Color> for StandardMaterial in examples (#13566) 2024-05-29 13:50:28 +00:00
animated_material.rs Add hue traits (#12399) 2024-03-22 00:36:46 +00:00
anisotropy.rs Omit font size where it closely matches the default in examples (#13952) 2024-06-20 21:01:28 +00:00
anti_aliasing.rs Implement subpixel morphological antialiasing, or SMAA. (#13423) 2024-06-04 17:07:34 +00:00
atmospheric_fog.rs glTF labels: add enum to avoid misspelling and keep up-to-date list documented (#13586) 2024-05-31 23:25:57 +00:00
auto_exposure.rs Updates default Text font size to 24px (#13603) 2024-05-31 16:41:27 +00:00
blend_modes.rs Omit font size where it closely matches the default in examples (#13952) 2024-06-20 21:01:28 +00:00
bloom_3d.rs Updates default Text font size to 24px (#13603) 2024-05-31 16:41:27 +00:00
clearcoat.rs glTF labels: add enum to avoid misspelling and keep up-to-date list documented (#13586) 2024-05-31 23:25:57 +00:00
color_grading.rs Make default behavior for BackgroundColor and BorderColor more intuitive (#14017) 2024-06-25 21:50:41 +00:00
deferred_rendering.rs glTF labels: add enum to avoid misspelling and keep up-to-date list documented (#13586) 2024-05-31 23:25:57 +00:00
depth_of_field.rs glTF labels: add enum to avoid misspelling and keep up-to-date list documented (#13586) 2024-05-31 23:25:57 +00:00
fog.rs Updates default Text font size to 24px (#13603) 2024-05-31 16:41:27 +00:00
generate_custom_mesh.rs Fix a few "repeated word" typos (#13955) 2024-06-20 21:35:20 +00:00
irradiance_volumes.rs Highlight dependency on shader files in examples (#13824) 2024-06-12 14:16:01 +00:00
lighting.rs Updates default Text font size to 24px (#13603) 2024-05-31 16:41:27 +00:00
lightmaps.rs glTF labels: add enum to avoid misspelling and keep up-to-date list documented (#13586) 2024-05-31 23:25:57 +00:00
lines.rs Highlight dependency on shader files in examples (#13824) 2024-06-12 14:16:01 +00:00
load_gltf.rs glTF labels: add enum to avoid misspelling and keep up-to-date list documented (#13586) 2024-05-31 23:25:57 +00:00
load_gltf_extras.rs add handling of all missing gltf extras: scene, mesh & materials (#13453) 2024-06-03 13:16:38 +00:00
meshlet.rs revert reflections PR changes to the meshlet example (#13539) 2024-05-27 19:48:18 +00:00
motion_blur.rs Updates default Text font size to 24px (#13603) 2024-05-31 16:41:27 +00:00
orthographic.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
parallax_mapping.rs Updates default Text font size to 24px (#13603) 2024-05-31 16:41:27 +00:00
parenting.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
pbr.rs Updates default Text font size to 24px (#13603) 2024-05-31 16:41:27 +00:00
reflection_probes.rs glTF labels: add enum to avoid misspelling and keep up-to-date list documented (#13586) 2024-05-31 23:25:57 +00:00
render_to_texture.rs example render_to_texture: remove extra light (#13398) 2024-05-16 23:26:55 +00:00
shadow_biases.rs Updates default Text font size to 24px (#13603) 2024-05-31 16:41:27 +00:00
shadow_caster_receiver.rs Remove redundant imports (#12817) 2024-04-01 19:59:08 +00:00
skybox.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
spherical_area_lights.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
split_screen.rs Make default behavior for BackgroundColor and BorderColor more intuitive (#14017) 2024-06-25 21:50:41 +00:00
spotlight.rs Updates default Text font size to 24px (#13603) 2024-05-31 16:41:27 +00:00
ssao.rs Updates default Text font size to 24px (#13603) 2024-05-31 16:41:27 +00:00
ssr.rs Highlight dependency on shader files in examples (#13824) 2024-06-12 14:16:01 +00:00
texture.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
tonemapping.rs Highlight dependency on shader files in examples (#13824) 2024-06-12 14:16:01 +00:00
transmission.rs Updates default Text font size to 24px (#13603) 2024-05-31 16:41:27 +00:00
transparency_3d.rs Implement alpha to coverage (A2C) support. (#12970) 2024-04-15 20:37:52 +00:00
two_passes.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
update_gltf_scene.rs glTF labels: add enum to avoid misspelling and keep up-to-date list documented (#13586) 2024-05-31 23:25:57 +00:00
vertex_colors.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
visibility_range.rs glTF labels: add enum to avoid misspelling and keep up-to-date list documented (#13586) 2024-05-31 23:25:57 +00:00
volumetric_fog.rs glTF labels: add enum to avoid misspelling and keep up-to-date list documented (#13586) 2024-05-31 23:25:57 +00:00
wireframe.rs Updates default Text font size to 24px (#13603) 2024-05-31 16:41:27 +00:00