Skip to content

Commit 8255185

Browse files
committed
Add docs for arguments of various color functions (#5533)
Fixes #5530
1 parent f3b5bf0 commit 8255185

File tree

1 file changed

+97
-12
lines changed
  • crates/bevy_render/src/color

1 file changed

+97
-12
lines changed

crates/bevy_render/src/color/mod.rs

Lines changed: 97 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,35 @@ use thiserror::Error;
1414
pub enum Color {
1515
/// sRGBA color
1616
Rgba {
17-
/// Red component. [0.0, 1.0]
17+
/// Red channel. [0.0, 1.0]
1818
red: f32,
19-
/// Green component. [0.0, 1.0]
19+
/// Green channel. [0.0, 1.0]
2020
green: f32,
21-
/// Blue component. [0.0, 1.0]
21+
/// Blue channel. [0.0, 1.0]
2222
blue: f32,
23-
/// Alpha component. [0.0, 1.0]
23+
/// Alpha channel. [0.0, 1.0]
2424
alpha: f32,
2525
},
2626
/// RGBA color in the Linear sRGB colorspace (often colloquially referred to as "linear", "RGB", or "linear RGB").
2727
RgbaLinear {
28-
/// Red component. [0.0, 1.0]
28+
/// Red channel. [0.0, 1.0]
2929
red: f32,
30-
/// Green component. [0.0, 1.0]
30+
/// Green channel. [0.0, 1.0]
3131
green: f32,
32-
/// Blue component. [0.0, 1.0]
32+
/// Blue channel. [0.0, 1.0]
3333
blue: f32,
34-
/// Alpha component. [0.0, 1.0]
34+
/// Alpha channel. [0.0, 1.0]
3535
alpha: f32,
3636
},
3737
/// HSL (hue, saturation, lightness) color with an alpha channel
3838
Hsla {
39-
/// Hue component. [0.0, 360.0]
39+
/// Hue channel. [0.0, 360.0]
4040
hue: f32,
41-
/// Saturation component. [0.0, 1.0]
41+
/// Saturation channel. [0.0, 1.0]
4242
saturation: f32,
43-
/// Lightness component. [0.0, 1.0]
43+
/// Lightness channel. [0.0, 1.0]
4444
lightness: f32,
45-
/// Alpha component. [0.0, 1.0]
45+
/// Alpha channel. [0.0, 1.0]
4646
alpha: f32,
4747
},
4848
}
@@ -126,6 +126,15 @@ impl Color {
126126
pub const YELLOW_GREEN: Color = Color::rgb(0.6, 0.8, 0.2);
127127

128128
/// 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+
///
129138
pub const fn rgb(r: f32, g: f32, b: f32) -> Color {
130139
Color::Rgba {
131140
red: r,
@@ -136,6 +145,16 @@ impl Color {
136145
}
137146

138147
/// 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+
///
139158
pub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Color {
140159
Color::Rgba {
141160
red: r,
@@ -146,6 +165,15 @@ impl Color {
146165
}
147166

148167
/// 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+
///
149177
pub const fn rgb_linear(r: f32, g: f32, b: f32) -> Color {
150178
Color::RgbaLinear {
151179
red: r,
@@ -156,6 +184,16 @@ impl Color {
156184
}
157185

158186
/// 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+
///
159197
pub const fn rgba_linear(r: f32, g: f32, b: f32, a: f32) -> Color {
160198
Color::RgbaLinear {
161199
red: r,
@@ -166,6 +204,15 @@ impl Color {
166204
}
167205

168206
/// 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+
///
169216
pub const fn hsl(hue: f32, saturation: f32, lightness: f32) -> Color {
170217
Color::Hsla {
171218
hue,
@@ -176,6 +223,16 @@ impl Color {
176223
}
177224

178225
/// 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+
///
179236
pub const fn hsla(hue: f32, saturation: f32, lightness: f32, alpha: f32) -> Color {
180237
Color::Hsla {
181238
hue,
@@ -186,6 +243,15 @@ impl Color {
186243
}
187244

188245
/// 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+
///
189255
pub fn hex<T: AsRef<str>>(hex: T) -> Result<Color, HexColorError> {
190256
let hex = hex.as_ref();
191257

@@ -223,13 +289,32 @@ impl Color {
223289
}
224290

225291
/// 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+
///
226301
pub fn rgb_u8(r: u8, g: u8, b: u8) -> Color {
227302
Color::rgba_u8(r, g, b, u8::MAX)
228303
}
229304

230305
// Float operations in const fn are not stable yet
231306
// see https://github.com/rust-lang/rust/issues/57241
232307
/// 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+
///
233318
pub fn rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Color {
234319
Color::rgba(
235320
r as f32 / u8::MAX as f32,

0 commit comments

Comments
 (0)