@@ -6,19 +6,20 @@ pub use colors::*;
6
6
#[ repr( C ) ]
7
7
#[ derive( Clone , Copy , Debug , Default , PartialEq ) ]
8
8
pub struct Color {
9
- /// Red channel value from 0.0 to 1.0
9
+ /// Red channel value from 0.0 to 1.0.
10
10
pub r : f32 ,
11
- /// Green channel value from 0.0 to 1.0
11
+ /// Green channel value from 0.0 to 1.0.
12
12
pub g : f32 ,
13
- /// Blue channel value from 0.0 to 1.0
13
+ /// Blue channel value from 0.0 to 1.0.
14
14
pub b : f32 ,
15
- /// Alpha channel value from 0.0 to 1.0
15
+ /// Alpha channel value from 0.0 to 1.0.
16
16
pub a : f32 ,
17
17
}
18
18
19
- /// Build a color from 4 components of 0..255 values
20
- /// This is a temporary solution and going to be replaced with const fn,
21
- /// waiting for [this issue](https://github.com/rust-lang/rust/issues/57241) to be resolved.
19
+ /// Build a color from 4 components of 0..255 values.
20
+ /// This was a temporary solution because [Color::from_rgba] was not a const fn due to
21
+ /// [this issue](https://github.com/rust-lang/rust/issues/57241) waiting to be resolved.
22
+ /// It is not needed anymore.
22
23
#[ macro_export]
23
24
macro_rules! color_u8 {
24
25
( $r: expr, $g: expr, $b: expr, $a: expr) => {
@@ -101,8 +102,6 @@ impl Color {
101
102
}
102
103
103
104
/// Build a color from 4 components between 0 and 255.
104
- /// Unfortunately it can't be const fn due to [this issue](https://github.com/rust-lang/rust/issues/57241).
105
- /// When const version is needed "color_u8" macro may be a workaround.
106
105
pub const fn from_rgba ( r : u8 , g : u8 , b : u8 , a : u8 ) -> Color {
107
106
Color :: new (
108
107
r as f32 / 255. ,
@@ -112,7 +111,7 @@ impl Color {
112
111
)
113
112
}
114
113
115
- /// Build a color from a hexadecimal u32
114
+ /// Build a color from a hexadecimal u32.
116
115
///
117
116
/// # Example
118
117
///
@@ -141,6 +140,7 @@ impl Color {
141
140
Self :: new ( vec. x , vec. y , vec. z , vec. w )
142
141
}
143
142
143
+ /// Create a copy of the current color, but with a different alpha value.
144
144
pub const fn with_alpha ( & self , alpha : f32 ) -> Color {
145
145
Color :: new ( self . r , self . g , self . b , alpha)
146
146
}
0 commit comments