pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}
Expand description
Fields§
§r: f32
Red component
g: f32
Green component
b: f32
Blue component
a: f32
Alpha component
Implementations§
source§impl Color
impl Color
sourcepub const fn new(r: f32, g: f32, b: f32, a: f32) -> Self
pub const fn new(r: f32, g: f32, b: f32, a: f32) -> Self
Create a new Color
from four f32
’s in the range [0.0-1.0]
sourcepub fn from_rgba(r: u8, g: u8, b: u8, a: u8) -> Color
pub fn from_rgba(r: u8, g: u8, b: u8, a: u8) -> Color
Create a new Color
from four u8
’s in the range [0-255]
sourcepub fn from_rgb(r: u8, g: u8, b: u8) -> Color
pub fn from_rgb(r: u8, g: u8, b: u8) -> Color
Create a new Color
from three u8’s in the range [0-255]
,
with the alpha component fixed to 255 (opaque)
sourcepub fn to_rgba(self) -> (u8, u8, u8, u8)
pub fn to_rgba(self) -> (u8, u8, u8, u8)
Return a tuple of four u8
’s in the range [0-255]
with the Color
’s
components.
sourcepub fn to_rgb(self) -> (u8, u8, u8)
pub fn to_rgb(self) -> (u8, u8, u8)
Return a tuple of three u8
’s in the range [0-255]
with the Color
’s
components.
sourcepub fn from_rgba_u32(c: u32) -> Color
pub fn from_rgba_u32(c: u32) -> Color
Convert a packed u32
containing 0xRRGGBBAA
into a Color
sourcepub fn from_rgb_u32(c: u32) -> Color
pub fn from_rgb_u32(c: u32) -> Color
Convert a packed u32
containing 0x00RRGGBB
into a Color
.
This lets you do things like Color::from_rgb_u32(0xCD09AA)
easily if you want.
sourcepub fn to_rgba_u32(self) -> u32
pub fn to_rgba_u32(self) -> u32
Convert a Color
into a packed u32
, containing 0xRRGGBBAA
as bytes.
sourcepub fn to_rgb_u32(self) -> u32
pub fn to_rgb_u32(self) -> u32
Convert a Color
into a packed u32
, containing 0x00RRGGBB
as bytes.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Color
impl<'de> Deserialize<'de> for Color
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl From<Color> for LinearColor
impl From<Color> for LinearColor
source§fn from(c: Color) -> Self
fn from(c: Color) -> Self
Convert an (sRGB) Color into a linear color, per https://en.wikipedia.org/wiki/Srgb#The_reverse_transformation