mirror of
https://github.com/bevyengine/bevy
synced 2025-02-16 22:18:33 +00:00
add Color::rgb_u8 and Color::rgba_u8 (#381)
This commit is contained in:
parent
e6a57bad25
commit
d64882ffbf
1 changed files with 15 additions and 0 deletions
|
@ -37,6 +37,21 @@ impl Color {
|
||||||
pub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Color {
|
pub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Color {
|
||||||
Color { r, g, b, a }
|
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 {
|
impl Default for Color {
|
||||||
|
|
Loading…
Add table
Reference in a new issue