1use std::ops::Mul;
2
3#[derive(Clone, Copy, Debug)]
4pub struct Color {
5 pub r: f32,
6 pub g: f32,
7 pub b: f32,
8 pub a: f32,
9}
10
11impl Color {
12 pub fn new(r: f32, g: f32, b: f32, a: f32) -> Self {
13 Self { r, g, b, a }
14 }
15
16 pub fn with_alpha(&self, alpha: f32) -> Self {
17 Self {
18 r: self.r,
19 g: self.g,
20 b: self.b,
21 a: alpha,
22 }
23 }
24
25 pub fn to_array(&self) -> [f32; 4] {
26 [self.r, self.g, self.b, self.a]
27 }
28
29 pub fn with_opacity(&self, opacity: f32) -> Color {
30 Color {
31 r: self.r,
32 g: self.g,
33 b: self.b,
34 a: self.a * opacity,
35 }
36 }
37}
38
39impl Mul<f32> for Color {
40 type Output = Color;
41
42 fn mul(self, rhs: f32) -> Color {
43 Color {
44 r: self.r,
45 g: self.g,
46 b: self.b,
47 a: self.a * rhs,
48 }
49 }
50}