pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}Expand description
A color in the sRGB color space.
§String Representation
A color can be represented in either of the following valid formats: #rrggbb, #rrggbbaa, #rgb, and #rgba.
Where rgba represent hexadecimal digits. Both uppercase and lowercase letters are supported.
If a (transparency) is not specified, 1.0 (completely opaque) would be used by default.
If you have a static color string, using the color! macro should be preferred
since it leverages hexadecimal literal notation and arithmetic directly.
Fields§
§r: f32Red component, 0.0 - 1.0
g: f32Green component, 0.0 - 1.0
b: f32Blue component, 0.0 - 1.0
a: f32Transparency, 0.0 - 1.0
Implementations§
Source§impl Color
impl Color
Sourcepub const TRANSPARENT: Color
pub const TRANSPARENT: Color
A color with no opacity.
Sourcepub const fn from_rgb(r: f32, g: f32, b: f32) -> Color
pub const fn from_rgb(r: f32, g: f32, b: f32) -> Color
Creates a Color from its RGB components.
Sourcepub const fn from_rgba(r: f32, g: f32, b: f32, a: f32) -> Color
pub const fn from_rgba(r: f32, g: f32, b: f32, a: f32) -> Color
Creates a Color from its RGBA components.
Sourcepub const fn from_rgba8(r: u8, g: u8, b: u8, a: f32) -> Color
pub const fn from_rgba8(r: u8, g: u8, b: u8, a: f32) -> Color
Creates a Color from its RGB8 components and an alpha value.
Sourcepub fn from_linear_rgba(r: f32, g: f32, b: f32, a: f32) -> Self
pub fn from_linear_rgba(r: f32, g: f32, b: f32, a: f32) -> Self
Creates a Color from its linear RGBA components.
Sourcepub fn into_rgba8(self) -> [u8; 4]
pub fn into_rgba8(self) -> [u8; 4]
Converts the Color into its RGBA8 equivalent.
Sourcepub fn into_linear(self) -> [f32; 4]
pub fn into_linear(self) -> [f32; 4]
Converts the Color into its linear values.
Sourcepub fn scale_alpha(self, factor: f32) -> Color
pub fn scale_alpha(self, factor: f32) -> Color
Scales the alpha channel of the Color by the given factor.
Sourcepub fn relative_luminance(self) -> f32
pub fn relative_luminance(self) -> f32
Returns the relative luminance of the Color.
https://www.w3.org/TR/WCAG21/#dfn-relative-luminance
Sourcepub fn relative_contrast(self, b: Color) -> f32
pub fn relative_contrast(self, b: Color) -> f32
Returns the relative contrast ratio of the Color against another one.