Add more casts
This commit is contained in:
parent
803ff49027
commit
6e86c310d9
1 changed files with 30 additions and 0 deletions
30
src/color.rs
30
src/color.rs
|
@ -75,6 +75,21 @@ impl Into<[f32; 3]> for Color {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<[f32; 4]> for Color {
|
||||
fn into(self) -> [f32; 4] {
|
||||
match self {
|
||||
Color::White => [1.0, 1.0, 1.0, 1.0],
|
||||
Color::Black => [0.0, 0.0, 0.0, 1.0],
|
||||
Color::Red => [1.0, 0.0, 0.0, 1.0],
|
||||
Color::Blue => [0.0, 0.0, 1.0, 1.0],
|
||||
Color::Green => [0.0, 1.0, 0.0, 1.0],
|
||||
Color::Orange => [1.0, 0.65, 0.0, 1.0],
|
||||
Color::Yellow => [1.0, 1.0, 0.0, 1.0],
|
||||
Color::Custom(r, g, b) => [r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0, 1.0],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<[u8; 3]> for Color {
|
||||
fn into(self) -> [u8; 3] {
|
||||
match self {
|
||||
|
@ -90,6 +105,21 @@ impl Into<[u8; 3]> for Color {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<[u8; 4]> for Color {
|
||||
fn into(self) -> [u8; 4] {
|
||||
match self {
|
||||
Color::White => [255, 255, 255, 255],
|
||||
Color::Black => [0, 0, 0, 255],
|
||||
Color::Red => [255, 0, 0, 255],
|
||||
Color::Blue => [0, 0, 255, 255],
|
||||
Color::Green => [0, 255, 0, 255],
|
||||
Color::Orange => [255, 166, 0, 255],
|
||||
Color::Yellow => [255, 255, 0, 255],
|
||||
Color::Custom(r, g, b) => [r, g, b, 255],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<f32> for Color {
|
||||
type Output = Self;
|
||||
|
||||
|
|
Loading…
Reference in a new issue