Skip to content

Commit

Permalink
add Color::rgb_u8 and Color::rgba_u8 (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
dallenng authored Aug 28, 2020
1 parent e6a57ba commit d64882f
Showing 1 changed file with 15 additions and 0 deletions.
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 {
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

0 comments on commit d64882f

Please sign in to comment.