Skip to content
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

Separate image and background color values #7451

Closed

Conversation

ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Jan 31, 2023

Objective

  • It's confusing that the BackgroundColor component is also used to control image color.
  • Padding for ImageNodes isn't implemented atm, but when it is, BackgroundColor could be used to set the color of the padded area.
  • At the moment you have to nest a transparent image inside of another node to give it a background color.
  • If a texture doesn't load at the moment, nothing is drawn. With a separate background color, you could fill the node with a bright color to indicate a missing texture.

Solution

Add a color field to UiImage and use it instead of BackgroundColor for image colors.
Draw separate background and image rects for each node, if the respective components are present.

Changelog

* added a `color` field to `UiImage`
* added a manual impl of `Default` for `ImageBundle`
* changed default `background_color` of `ImageBundle` to `Color::NONE`
* changed extract_uinodes to queue separate rects for the background color and the image

Migration Guide

To set the color tint of an image, instead of using the BackgroundColor component use the color field of UiImage.

    * added a color field to UiImage
    * added a manual impl of Default for ImageBundle
    * changed default background_color of ImageBundle to Color::NONE
    * changed extract_uinodes to draw the background color and the image separately
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A targeted quality-of-life change that makes Bevy easier to use M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide labels Jan 31, 2023
@ickshonpe
Copy link
Contributor Author

Another motivation for this is to support forced aspect ratio images with letterboxing when they can't be made to fit into the UI layout (something I implemented in bevy_ui_exact_image). You'd use background_color to specify a color for the letterbox area.

@ChristopherBiscardi
Copy link
Contributor

I believe #11165 included the changes that this PR would've addressed.

@mockersf mockersf closed this Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A targeted quality-of-life change that makes Bevy easier to use M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants