Skip to content

Add Color::srgb_u32 #14454

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Add Color::srgb_u32 #14454

wants to merge 4 commits into from

Conversation

amytimed
Copy link

Objective

Allows using a color value like 0xffffff.

Instead of doing this:

let r = ((delta.background_color >> 16) & 0xff) as f32 / 255.;
let g = ((delta.background_color >> 8) & 0xff) as f32 / 255.;
let b = (delta.background_color & 0xff) as f32 / 255.;

let color = Color::srgb(r, g, b);

This PR allows doing this:

let color = Color::srgb_u32(delta.background_color);

Solution

New method srgb_u32, similar to srgb_u8 but all in one value.

///
/// For example, a value of `0x000000` results in black, and a value of `0xff0000` results in red.
pub fn srgb_u32(color: u32) -> Self {
Self::Srgba(Srgba {
Copy link
Member

Choose a reason for hiding this comment

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

This should call an equivalent public method on Srgba :)

Copy link
Member

Choose a reason for hiding this comment

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

I still want this comment resolved :)

@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged A-Color Color spaces and color math labels Jul 23, 2024
@mnmaita
Copy link
Member

mnmaita commented Nov 8, 2024

@amytimed thanks for such an useful contribution! Would you be able to address the comments? I think this PR is an easy win if you include the requested additions.

@alice-i-cecile alice-i-cecile added S-Needs-Review Needs reviewer attention (from anyone!) to move forward S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Color Color spaces and color math C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants