pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}
Expand description
A color in the sRGB
color space.
Fields§
§r: f32
Red component, 0.0 - 1.0
g: f32
Green component, 0.0 - 1.0
b: f32
Blue component, 0.0 - 1.0
a: f32
Transparency, 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 parse(s: &str) -> Option<Color>
pub fn parse(s: &str) -> Option<Color>
Parses a Color
from a hex string.
Supported formats are #rrggbb
, #rrggbbaa
, #rgb
, and #rgba
.
The starting “#” is optional. Both uppercase and lowercase are supported.
If you have a static color string, using the color!
macro should be preferred
since it leverages hexadecimal literal notation and arithmetic directly.
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.