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

Add Color::rgb_u8 and Color::rgba_u8 #381

Merged
merged 1 commit into from
Aug 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions crates/bevy_render/src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ impl Color {
pub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Color {
Copy link
Member

Choose a reason for hiding this comment

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

I think we could do with some doc comments on Color and its associated functions about being normalised values.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah i think that probably makes sense, both on the Color struct and on functions taking floats (rgba/rgb). Probably should be a separate PR though. Feel free to create one (or an issue to track it).

Color { r, g, b, a }
}

pub fn rgb_u8(r: u8, g: u8, b: u8) -> Color {
Color::rgba_u8(r, g, b, u8::MAX)
}

// Float operations in const fn are not stable yet
// see https://github.com/rust-lang/rust/issues/57241
pub fn rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Color {
Color::rgba(
r as f32 / u8::MAX as f32,
g as f32 / u8::MAX as f32,
b as f32 / u8::MAX as f32,
a as f32 / u8::MAX as f32,
)
}
}

impl Default for Color {
Expand Down