-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Do not require a BackgroundColor for UI images #11157
Comments
The current design is quite confusing to me, as it conflates the background color with the tint of the image. IMO the node that stores the UI shouldn't have a background color by default: instead, it should have a distinct component / property that is used for tinting. |
It would be nice to have a The individual components probably still need their own |
the |
Btw, |
Yeah, in the |
I'm gonna try to make a PR decoupling
|
I guess unrelated to this issue, but I noticed another inconsistency. The I'm not sure if there's a reason for this so I'm not gonna touch it. |
I think I put in a similar PR back for 0.10 or something that implemented this. Everyone agreed with it but it got no reviews and I forgot about it. It was #7451 |
Another reason I wanted this change was that it allowed for things like letter-boxing of images with a fixed aspect ratio. |
This was because For |
This is only an idea, but maybe we can do this kind of transform on the image using style? |
I've thought that the |
|
Oh yeah of course they do, I forgot 😅 . |
# Objective Fixes #11157. ## Solution Stop using `BackgroundColor` as a color tint for `UiImage`. Add a `UiImage::color` field for color tint instead. Allow a UI node to simultaneously include a solid-color background and an image, with the image rendered on top of the background (this is already how it works for e.g. text). ![2024-02-29_1709239666_563x520](https://github.com/bevyengine/bevy/assets/12173779/ec50c9ef-4c7f-4ab8-a457-d086ce5b3425) --- ## Changelog - The `BackgroundColor` component now renders a solid-color background behind `UiImage` instead of tinting its color. - Removed `BackgroundColor` from `ImageBundle`, `AtlasImageBundle`, and `ButtonBundle`. - Added `UiImage::color`. - Expanded `RenderUiSystem` variants. - Renamed `bevy_ui::extract_text_uinodes` to `extract_uinodes_text` for consistency. ## Migration Guide - `BackgroundColor` no longer tints the color of UI images. Use `UiImage::color` for that instead. - For solid color buttons, replace `ButtonBundle { background_color: my_color.into(), ... }` with `ButtonBundle { image: UiImage::default().with_color(my_color), ... }`, and update button interaction systems to use `UiImage::color` instead of `BackgroundColor` as well. - `bevy_ui::RenderUiSystem::ExtractNode` has been split into `ExtractBackgrounds`, `ExtractImages`, `ExtractBorders`, and `ExtractText`. - `bevy_ui::extract_uinodes` has been split into `bevy_ui::extract_uinode_background_colors` and `bevy_ui::extract_uinode_images`. - `bevy_ui::extract_text_uinodes` has been renamed to `extract_uinode_text`.
# Objective Fixes bevyengine#11157. ## Solution Stop using `BackgroundColor` as a color tint for `UiImage`. Add a `UiImage::color` field for color tint instead. Allow a UI node to simultaneously include a solid-color background and an image, with the image rendered on top of the background (this is already how it works for e.g. text). ![2024-02-29_1709239666_563x520](https://github.com/bevyengine/bevy/assets/12173779/ec50c9ef-4c7f-4ab8-a457-d086ce5b3425) --- ## Changelog - The `BackgroundColor` component now renders a solid-color background behind `UiImage` instead of tinting its color. - Removed `BackgroundColor` from `ImageBundle`, `AtlasImageBundle`, and `ButtonBundle`. - Added `UiImage::color`. - Expanded `RenderUiSystem` variants. - Renamed `bevy_ui::extract_text_uinodes` to `extract_uinodes_text` for consistency. ## Migration Guide - `BackgroundColor` no longer tints the color of UI images. Use `UiImage::color` for that instead. - For solid color buttons, replace `ButtonBundle { background_color: my_color.into(), ... }` with `ButtonBundle { image: UiImage::default().with_color(my_color), ... }`, and update button interaction systems to use `UiImage::color` instead of `BackgroundColor` as well. - `bevy_ui::RenderUiSystem::ExtractNode` has been split into `ExtractBackgrounds`, `ExtractImages`, `ExtractBorders`, and `ExtractText`. - `bevy_ui::extract_uinodes` has been split into `bevy_ui::extract_uinode_background_colors` and `bevy_ui::extract_uinode_images`. - `bevy_ui::extract_text_uinodes` has been renamed to `extract_uinode_text`.
What problem does this solve or what need does it fill?
Actually, in order to use an image with
Sprite
or evenUiImage
, you are forced to use a BackgroundColor that is different from transparent, and that is misleading, can lead to one to think "well, I don't want an color in my Image, so I'll set it to transparent, right?" and then being confused because the image disappearedWhat solution would you like?
The BackgroundColor, when being used with an image would apply an oppacity of determined color above the image. For example Rgb(255, 255, 0, 0.5) would taint the image slightly of yellow
but if one use Rgb(0, 0, 0, 1) the image would be tainted of black and the image itself would disappear (as alpha is 100%), leaving an black square on its place
What alternative(s) have you considered?
For that purpose, probably adding an child or something above the child with the desired color and leaving color in the background as Color::WHITE and leaving it as it is.
Additional context
The text was updated successfully, but these errors were encountered: