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

[Merged by Bors] - Add a BackgroundColor component to TextBundle #7596

Closed

Conversation

ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Feb 10, 2023

Objective

TextBundle should have a BackgroundColor component.

Apart from adding emphasis etc to text, adding a background color to text nodes can be extremely useful for understanding how Bevy aligns, sizes and positions text, and identifying and debugging problems.

It's easy for users to insert the BackgroundColor component themselves but not immediately obvious or discoverable that it's possible. A BackgroundColor component allows us to add a with_background_color helper function to TextBundle.

related issue: #5935

Solution

Add a BackgroundColor component to TextBundle.


Changelog

  • Added a BackgroundColor component to TextBundle.
  • Added a helper method with_background_color to TextBundle.

Migration Guide

TextBundle now has a BackgroundColor component.

Use TextBundle's background_color field or the with_background_color method to set a background color for text when spawning a text node, in place of manual insertion of a BackgroundColor component.

    * added a `BackgroundColor` component to `TextBundle`
    * added a helper method `with_background_color` to `TextBundle`
@alice-i-cecile alice-i-cecile added A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A simple quality-of-life change that makes Bevy easier to use labels Feb 10, 2023
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the field. Doc comment on it could be clearer (what area, precisely, is colored).

Builder methods on TextBundle remain controversial. I kind of like it here for consistency, but I'm also not sold on the pattern as a whole.

@ickshonpe
Copy link
Contributor Author

ickshonpe commented Feb 10, 2023

Yes I'm not bothered about the builder method but it's needed while

commands.spawn((
    TextBundle::from_section(
        "hello", 
        TextStyle {  
            font: asset_server.load("fonts/FiraSans-Bold.ttf"), 
            font_size: 32.0, 
            color: Color::WHITE 
        }
    ),
    BackgroundColor(Color::NAVY)
));

gives a duplicate component error.

Agree about the comment. It implies that it will only set a background color for the text, when the color will fill the entire containing node. I'll change it.

Co-authored-by: François <mockersf@gmail.com>
@alice-i-cecile
Copy link
Member

bors r+

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Feb 20, 2023
bors bot pushed a commit that referenced this pull request Feb 20, 2023
# Objective

`TextBundle` should have a `BackgroundColor` component.

Apart from adding emphasis etc to text, adding a background color to text nodes can be extremely useful for understanding how Bevy aligns, sizes and positions text, and identifying and debugging problems.

It's easy for users to insert the `BackgroundColor` component themselves but not immediately obvious or discoverable that it's possible. A `BackgroundColor` component allows us to add a `with_background_color` helper function to `TextBundle`.

related issue: #5935

## Solution

Add a `BackgroundColor` component to `TextBundle`.

---

## Changelog

* Added a `BackgroundColor` component to `TextBundle`.
* Added a helper method `with_background_color` to `TextBundle`.

## Migration Guide
`TextBundle` now has a `BackgroundColor` component. 

Use `TextBundle`'s `background_color` field or the `with_background_color` method to set a background color for text when spawning a text node, in place of manual insertion of a `BackgroundColor` component.
@bors bors bot changed the title Add a BackgroundColor component to TextBundle [Merged by Bors] - Add a BackgroundColor component to TextBundle Feb 20, 2023
@bors bors bot closed this Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A simple quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants