pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}
Expand description
The color
Fields§
§r: f32
Red
g: f32
Green
b: f32
Blue
a: f32
Alpha
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
Arguments:
r
: Red value [0..1]g
: Green value [0..1]b
: Blue value [0..1]a
: Alpha value [0..1]
pub fn to_array(&self) -> [f32; 4]
pub fn to_rgba8(&self) -> [u8; 4]
pub fn to_rgba16(&self) -> [u16; 4]
pub fn clamp(&self) -> Self
Sourcepub fn from_rgb(r: f32, g: f32, b: f32) -> Self
👎Deprecated: Use new instead.
pub fn from_rgb(r: f32, g: f32, b: f32) -> Self
Arguments:
r
: Red value [0..1]g
: Green value [0..1]b
: Blue value [0..1]
Sourcepub fn from_rgba(r: f32, g: f32, b: f32, a: f32) -> Self
👎Deprecated: Use new instead.
pub fn from_rgba(r: f32, g: f32, b: f32, a: f32) -> Self
Arguments:
r
: Red value [0..1]g
: Green value [0..1]b
: Blue value [0..1]a
: Alpha value [0..1]
Sourcepub fn from_rgb_u8(r: u8, g: u8, b: u8) -> Self
👎Deprecated: Use from_rgba8 instead.
pub fn from_rgb_u8(r: u8, g: u8, b: u8) -> Self
Arguments:
r
: Red value [0..255]g
: Green value [0..255]b
: Blue value [0..255]
Sourcepub fn from_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Self
👎Deprecated: Use from_rgba8 instead.
pub fn from_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Self
Arguments:
r
: Red value [0..255]g
: Green value [0..255]b
: Blue value [0..255]a
: Alpha value [0..255]
Sourcepub fn from_rgba8(r: u8, g: u8, b: u8, a: u8) -> Self
pub fn from_rgba8(r: u8, g: u8, b: u8, a: u8) -> Self
Arguments:
r
: Red value [0..255]g
: Green value [0..255]b
: Blue value [0..255]a
: Alpha value [0..255]
Sourcepub fn from_linear_rgb(r: f32, g: f32, b: f32) -> Self
👎Deprecated: Use from_linear_rgba instead.
pub fn from_linear_rgb(r: f32, g: f32, b: f32) -> Self
Arguments:
r
: Red value [0..1]g
: Green value [0..1]b
: Blue value [0..1]
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
Arguments:
r
: Red value [0..1]g
: Green value [0..1]b
: Blue value [0..1]a
: Alpha value [0..1]
Sourcepub fn from_linear_rgb_u8(r: u8, g: u8, b: u8) -> Self
👎Deprecated: Use from_linear_rgba8 instead.
pub fn from_linear_rgb_u8(r: u8, g: u8, b: u8) -> Self
Arguments:
r
: Red value [0..255]g
: Green value [0..255]b
: Blue value [0..255]
Sourcepub fn from_linear_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Self
👎Deprecated: Use from_linear_rgba8 instead.
pub fn from_linear_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Self
Arguments:
r
: Red value [0..255]g
: Green value [0..255]b
: Blue value [0..255]a
: Alpha value [0..255]
Sourcepub fn from_linear_rgba8(r: u8, g: u8, b: u8, a: u8) -> Self
pub fn from_linear_rgba8(r: u8, g: u8, b: u8, a: u8) -> Self
Arguments:
r
: Red value [0..255]g
: Green value [0..255]b
: Blue value [0..255]a
: Alpha value [0..255]
Sourcepub fn from_hsv(h: f32, s: f32, v: f32) -> Self
👎Deprecated: Use from_hsva instead.
pub fn from_hsv(h: f32, s: f32, v: f32) -> Self
Arguments:
h
: Hue angle [0..360]s
: Saturation [0..1]v
: Value [0..1]
Sourcepub fn from_hsva(h: f32, s: f32, v: f32, a: f32) -> Self
pub fn from_hsva(h: f32, s: f32, v: f32, a: f32) -> Self
Arguments:
h
: Hue angle [0..360]s
: Saturation [0..1]v
: Value [0..1]a
: Alpha [0..1]
Sourcepub fn from_hsl(h: f32, s: f32, l: f32) -> Self
👎Deprecated: Use from_hsla instead.
pub fn from_hsl(h: f32, s: f32, l: f32) -> Self
Arguments:
h
: Hue angle [0..360]s
: Saturation [0..1]l
: Lightness [0..1]
Sourcepub fn from_hsla(h: f32, s: f32, l: f32, a: f32) -> Self
pub fn from_hsla(h: f32, s: f32, l: f32, a: f32) -> Self
Arguments:
h
: Hue angle [0..360]s
: Saturation [0..1]l
: Lightness [0..1]a
: Alpha [0..1]
Sourcepub fn from_hwb(h: f32, w: f32, b: f32) -> Self
👎Deprecated: Use from_hwba instead.
pub fn from_hwb(h: f32, w: f32, b: f32) -> Self
Arguments:
h
: Hue angle [0..360]w
: Whiteness [0..1]b
: Blackness [0..1]
Sourcepub fn from_hwba(h: f32, w: f32, b: f32, a: f32) -> Self
pub fn from_hwba(h: f32, w: f32, b: f32, a: f32) -> Self
Arguments:
h
: Hue angle [0..360]w
: Whiteness [0..1]b
: Blackness [0..1]a
: Alpha [0..1]
Sourcepub fn from_oklab(l: f32, a: f32, b: f32) -> Self
👎Deprecated: Use from_oklaba instead.
pub fn from_oklab(l: f32, a: f32, b: f32) -> Self
Arguments:
l
: Perceived lightnessa
: How green/red the color isb
: How blue/yellow the color is
Sourcepub fn from_oklaba(l: f32, a: f32, b: f32, alpha: f32) -> Self
pub fn from_oklaba(l: f32, a: f32, b: f32, alpha: f32) -> Self
Arguments:
l
: Perceived lightnessa
: How green/red the color isb
: How blue/yellow the color isalpha
: Alpha [0..1]
pub fn from_oklcha(l: f32, c: f32, h: f32, alpha: f32) -> Self
Sourcepub fn from_html<S: AsRef<str>>(s: S) -> Result<Self, ParseColorError>
pub fn from_html<S: AsRef<str>>(s: S) -> Result<Self, ParseColorError>
Create color from CSS color string.
§Examples
use csscolorparser::Color;
let c = Color::from_html("rgb(255,0,0)")?;
assert_eq!(c.to_array(), [1.0, 0.0, 0.0, 1.0]);
assert_eq!(c.to_rgba8(), [255, 0, 0, 255]);
assert_eq!(c.to_hex_string(), "#ff0000");
assert_eq!(c.to_rgb_string(), "rgb(255,0,0)");
pub fn name(&self) -> Option<&'static str>
Sourcepub fn rgba(&self) -> (f32, f32, f32, f32)
👎Deprecated
pub fn rgba(&self) -> (f32, f32, f32, f32)
Returns: (r, g, b, a)
- Red, green, blue and alpha in the range [0..1]
Sourcepub fn rgba_u8(&self) -> (u8, u8, u8, u8)
👎Deprecated: Use to_rgba8 instead.
pub fn rgba_u8(&self) -> (u8, u8, u8, u8)
Returns: (r, g, b, a)
- Red, green, blue and alpha in the range [0..255]
Sourcepub fn to_hsva(&self) -> [f32; 4]
pub fn to_hsva(&self) -> [f32; 4]
Returns: [h, s, v, a]
h
: Hue angle [0..360]s
: Saturation [0..1]v
: Value [0..1]a
: Alpha [0..1]
Sourcepub fn to_hsla(&self) -> [f32; 4]
pub fn to_hsla(&self) -> [f32; 4]
Returns: [h, s, l, a]
h
: Hue angle [0..360]s
: Saturation [0..1]l
: Lightness [0..1]a
: Alpha [0..1]
Sourcepub fn to_hwba(&self) -> [f32; 4]
pub fn to_hwba(&self) -> [f32; 4]
Returns: [h, w, b, a]
h
: Hue angle [0..360]w
: Whiteness [0..1]b
: Blackness [0..1]a
: Alpha [0..1]
Sourcepub fn to_linear_rgba(&self) -> [f32; 4]
pub fn to_linear_rgba(&self) -> [f32; 4]
Returns: [r, g, b, a]
- Red, green, blue and alpha in the range [0..1]
Sourcepub fn to_linear_rgba_u8(&self) -> [u8; 4]
pub fn to_linear_rgba_u8(&self) -> [u8; 4]
Returns: [r, g, b, a]
- Red, green, blue and alpha in the range [0..255]
Sourcepub fn to_hex_string(&self) -> String
pub fn to_hex_string(&self) -> String
Get the RGB hexadecimal color string.
Sourcepub fn to_rgb_string(&self) -> String
pub fn to_rgb_string(&self) -> String
Get the CSS rgb()
format string.
Sourcepub fn interpolate_rgb(&self, other: &Color, t: f32) -> Self
pub fn interpolate_rgb(&self, other: &Color, t: f32) -> Self
Blend this color with the other one, in the RGB color-space. t
in the range [0..1].
Sourcepub fn interpolate_linear_rgb(&self, other: &Color, t: f32) -> Self
pub fn interpolate_linear_rgb(&self, other: &Color, t: f32) -> Self
Blend this color with the other one, in the linear RGB color-space. t
in the range [0..1].
Sourcepub fn interpolate_hsv(&self, other: &Color, t: f32) -> Self
pub fn interpolate_hsv(&self, other: &Color, t: f32) -> Self
Blend this color with the other one, in the HSV color-space. t
in the range [0..1].
Sourcepub fn interpolate_oklab(&self, other: &Color, t: f32) -> Self
pub fn interpolate_oklab(&self, other: &Color, t: f32) -> Self
Blend this color with the other one, in the Oklab color-space. t
in the range [0..1].
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Color
Implement Serde deserialization from string
impl<'de> Deserialize<'de> for Color
Implement Serde deserialization from string