pub struct Color { /* private fields */ }
Expand description
A struct representing a color with red, green, blue, and alpha components. Each component is stored as a float.
Implementations§
source§impl Color
impl Color
sourcepub const TRANSPARENT: Color = _
pub const TRANSPARENT: Color = _
Color constant for transparency, with the alpha value set to zero.
sourcepub const LIGHT_GRAY: Color = _
pub const LIGHT_GRAY: Color = _
Constant for the color light gray.
sourcepub const fn from_rgba(r: f32, g: f32, b: f32, a: f32) -> Self
pub const fn from_rgba(r: f32, g: f32, b: f32, a: f32) -> Self
Creates a color with the specified components, including an alpha
component. Each component should be in the range 0.0
to 1.0
.
sourcepub const fn from_rgb(r: f32, g: f32, b: f32) -> Self
pub const fn from_rgb(r: f32, g: f32, b: f32) -> Self
Creates a color with the specified components. The alpha component will
be set to 1.0 (full opacity). Each component should be in the range
0.0
to 1.0
.
sourcepub fn from_int_rgba(r: u8, g: u8, b: u8, a: u8) -> Self
pub fn from_int_rgba(r: u8, g: u8, b: u8, a: u8) -> Self
Creates a color with the specified components, including an alpha
component. Each component should be in the range 0
to 255
.
sourcepub fn from_int_rgb(r: u8, g: u8, b: u8) -> Self
pub fn from_int_rgb(r: u8, g: u8, b: u8) -> Self
Creates a color with the specified components. The alpha component will
be set to 255 (full opacity). Each component should be in the range
0
to 255
.
sourcepub fn from_hex_argb(argb: u32) -> Self
pub fn from_hex_argb(argb: u32) -> Self
Creates a color from the specified integer value, including an alpha component.
For example, the input value 0xAABBCCDD
will result in a color with:
- Alpha =
0xAA
- Red =
0xBB
- Green =
0xCC
- Blue =
0xDD
Note: If you don’t specify the alpha component, the color will be transparent.
sourcepub fn from_hex_rgb(rgb: u32) -> Self
pub fn from_hex_rgb(rgb: u32) -> Self
Creates a color from the specified integer value, with the alpha
component set to 255
(full opacity).
For example, the input value 0xAABBCC
will result in a color with:
- Alpha =
0xFF
- Red =
0xAA
- Green =
0xBB
- Blue =
0xCC
Note: if an alpha component is specified in the high bits of the integer, it will be ignored. See Color::from_hex_argb if you wish to specify the alpha component.
sourcepub const fn from_gray(brightness: f32) -> Self
pub const fn from_gray(brightness: f32) -> Self
Creates a shade of gray from the specified float value, between 0.0
and 1.0
. All three RGB components will be set to this value.
sourcepub const fn r(&self) -> f32
pub const fn r(&self) -> f32
Returns the red component of the color, as a value in the range 0.0
to
1.0
.
sourcepub const fn g(&self) -> f32
pub const fn g(&self) -> f32
Returns the green component of the color, as a value in the range 0.0
to 1.0
.
sourcepub const fn b(&self) -> f32
pub const fn b(&self) -> f32
Returns the blue component of the color, as a value in the range 0.0
to 1.0
.
sourcepub const fn a(&self) -> f32
pub const fn a(&self) -> f32
Returns the alpha component of the color, as a value in the range 0.0
to 1.0
. The value 0.0
is fully transparent, and the value 1.0
is fully opaque.
sourcepub fn subjective_brightness(&self) -> f32
pub fn subjective_brightness(&self) -> f32
Returns the brightness of the color as perceived by a human, as a value
in the range 0.0
to 1.0
.
This is calculated using the following formula:
red * 0.299 + green * 0.587 + blue * 0.114