@@ -14,35 +14,35 @@ use thiserror::Error;
14
14
pub enum Color {
15
15
/// sRGBA color
16
16
Rgba {
17
- /// Red component . [0.0, 1.0]
17
+ /// Red channel . [0.0, 1.0]
18
18
red : f32 ,
19
- /// Green component . [0.0, 1.0]
19
+ /// Green channel . [0.0, 1.0]
20
20
green : f32 ,
21
- /// Blue component . [0.0, 1.0]
21
+ /// Blue channel . [0.0, 1.0]
22
22
blue : f32 ,
23
- /// Alpha component . [0.0, 1.0]
23
+ /// Alpha channel . [0.0, 1.0]
24
24
alpha : f32 ,
25
25
} ,
26
26
/// RGBA color in the Linear sRGB colorspace (often colloquially referred to as "linear", "RGB", or "linear RGB").
27
27
RgbaLinear {
28
- /// Red component . [0.0, 1.0]
28
+ /// Red channel . [0.0, 1.0]
29
29
red : f32 ,
30
- /// Green component . [0.0, 1.0]
30
+ /// Green channel . [0.0, 1.0]
31
31
green : f32 ,
32
- /// Blue component . [0.0, 1.0]
32
+ /// Blue channel . [0.0, 1.0]
33
33
blue : f32 ,
34
- /// Alpha component . [0.0, 1.0]
34
+ /// Alpha channel . [0.0, 1.0]
35
35
alpha : f32 ,
36
36
} ,
37
37
/// HSL (hue, saturation, lightness) color with an alpha channel
38
38
Hsla {
39
- /// Hue component . [0.0, 360.0]
39
+ /// Hue channel . [0.0, 360.0]
40
40
hue : f32 ,
41
- /// Saturation component . [0.0, 1.0]
41
+ /// Saturation channel . [0.0, 1.0]
42
42
saturation : f32 ,
43
- /// Lightness component . [0.0, 1.0]
43
+ /// Lightness channel . [0.0, 1.0]
44
44
lightness : f32 ,
45
- /// Alpha component . [0.0, 1.0]
45
+ /// Alpha channel . [0.0, 1.0]
46
46
alpha : f32 ,
47
47
} ,
48
48
}
@@ -126,6 +126,15 @@ impl Color {
126
126
pub const YELLOW_GREEN : Color = Color :: rgb ( 0.6 , 0.8 , 0.2 ) ;
127
127
128
128
/// New `Color` from sRGB colorspace.
129
+ ///
130
+ /// # Arguments
131
+ ///
132
+ /// * `r` - Red channel. [0.0, 1.0]
133
+ /// * `g` - Green channel. [0.0, 1.0]
134
+ /// * `b` - Blue channel. [0.0, 1.0]
135
+ ///
136
+ /// See also [`Color::rgba`], [`Color::rgb_u8`], [`Color::hex`].
137
+ ///
129
138
pub const fn rgb ( r : f32 , g : f32 , b : f32 ) -> Color {
130
139
Color :: Rgba {
131
140
red : r,
@@ -136,6 +145,16 @@ impl Color {
136
145
}
137
146
138
147
/// New `Color` from sRGB colorspace.
148
+ ///
149
+ /// # Arguments
150
+ ///
151
+ /// * `r` - Red channel. [0.0, 1.0]
152
+ /// * `g` - Green channel. [0.0, 1.0]
153
+ /// * `b` - Blue channel. [0.0, 1.0]
154
+ /// * `a` - Alpha channel. [0.0, 1.0]
155
+ ///
156
+ /// See also [`Color::rgb`], [`Color::rgba_u8`], [`Color::hex`].
157
+ ///
139
158
pub const fn rgba ( r : f32 , g : f32 , b : f32 , a : f32 ) -> Color {
140
159
Color :: Rgba {
141
160
red : r,
@@ -146,6 +165,15 @@ impl Color {
146
165
}
147
166
148
167
/// New `Color` from linear RGB colorspace.
168
+ ///
169
+ /// # Arguments
170
+ ///
171
+ /// * `r` - Red channel. [0.0, 1.0]
172
+ /// * `g` - Green channel. [0.0, 1.0]
173
+ /// * `b` - Blue channel. [0.0, 1.0]
174
+ ///
175
+ /// See also [`Color::rgb`], [`Color::rgba_linear`].
176
+ ///
149
177
pub const fn rgb_linear ( r : f32 , g : f32 , b : f32 ) -> Color {
150
178
Color :: RgbaLinear {
151
179
red : r,
@@ -156,6 +184,16 @@ impl Color {
156
184
}
157
185
158
186
/// New `Color` from linear RGB colorspace.
187
+ ///
188
+ /// # Arguments
189
+ ///
190
+ /// * `r` - Red channel. [0.0, 1.0]
191
+ /// * `g` - Green channel. [0.0, 1.0]
192
+ /// * `b` - Blue channel. [0.0, 1.0]
193
+ /// * `a` - Alpha channel. [0.0, 1.0]
194
+ ///
195
+ /// See also [`Color::rgba`], [`Color::rgb_linear`].
196
+ ///
159
197
pub const fn rgba_linear ( r : f32 , g : f32 , b : f32 , a : f32 ) -> Color {
160
198
Color :: RgbaLinear {
161
199
red : r,
@@ -166,6 +204,15 @@ impl Color {
166
204
}
167
205
168
206
/// New `Color` with HSL representation in sRGB colorspace.
207
+ ///
208
+ /// # Arguments
209
+ ///
210
+ /// * `hue` - Hue channel. [0.0, 360.0]
211
+ /// * `saturation` - Saturation channel. [0.0, 1.0]
212
+ /// * `lightness` - Lightness channel. [0.0, 1.0]
213
+ ///
214
+ /// See also [`Color::hsla`].
215
+ ///
169
216
pub const fn hsl ( hue : f32 , saturation : f32 , lightness : f32 ) -> Color {
170
217
Color :: Hsla {
171
218
hue,
@@ -176,6 +223,16 @@ impl Color {
176
223
}
177
224
178
225
/// New `Color` with HSL representation in sRGB colorspace.
226
+ ///
227
+ /// # Arguments
228
+ ///
229
+ /// * `hue` - Hue channel. [0.0, 360.0]
230
+ /// * `saturation` - Saturation channel. [0.0, 1.0]
231
+ /// * `lightness` - Lightness channel. [0.0, 1.0]
232
+ /// * `alpha` - Alpha channel. [0.0, 1.0]
233
+ ///
234
+ /// See also [`Color::hsl`].
235
+ ///
179
236
pub const fn hsla ( hue : f32 , saturation : f32 , lightness : f32 , alpha : f32 ) -> Color {
180
237
Color :: Hsla {
181
238
hue,
@@ -186,6 +243,15 @@ impl Color {
186
243
}
187
244
188
245
/// New `Color` from sRGB colorspace.
246
+ ///
247
+ /// # Examples
248
+ ///
249
+ /// ```
250
+ /// # use bevy_render::color::Color;
251
+ /// let color = Color::hex("FF00FF").unwrap(); // fuchsia
252
+ /// let color = Color::hex("FF00FF7F").unwrap(); // partially transparent fuchsia
253
+ /// ```
254
+ ///
189
255
pub fn hex < T : AsRef < str > > ( hex : T ) -> Result < Color , HexColorError > {
190
256
let hex = hex. as_ref ( ) ;
191
257
@@ -223,13 +289,32 @@ impl Color {
223
289
}
224
290
225
291
/// New `Color` from sRGB colorspace.
292
+ ///
293
+ /// # Arguments
294
+ ///
295
+ /// * `r` - Red channel. [0, 255]
296
+ /// * `g` - Green channel. [0, 255]
297
+ /// * `b` - Blue channel. [0, 255]
298
+ ///
299
+ /// See also [`Color::rgb`], [`Color::rgba_u8`], [`Color::hex`].
300
+ ///
226
301
pub fn rgb_u8 ( r : u8 , g : u8 , b : u8 ) -> Color {
227
302
Color :: rgba_u8 ( r, g, b, u8:: MAX )
228
303
}
229
304
230
305
// Float operations in const fn are not stable yet
231
306
// see https://github.com/rust-lang/rust/issues/57241
232
307
/// New `Color` from sRGB colorspace.
308
+ ///
309
+ /// # Arguments
310
+ ///
311
+ /// * `r` - Red channel. [0, 255]
312
+ /// * `g` - Green channel. [0, 255]
313
+ /// * `b` - Blue channel. [0, 255]
314
+ /// * `a` - Alpha channel. [0, 255]
315
+ ///
316
+ /// See also [`Color::rgba`], [`Color::rgb_u8`], [`Color::hex`].
317
+ ///
233
318
pub fn rgba_u8 ( r : u8 , g : u8 , b : u8 , a : u8 ) -> Color {
234
319
Color :: rgba (
235
320
r as f32 / u8:: MAX as f32 ,
0 commit comments