Struct csscolorparser::Color
source · [−]Expand description
The color
Fields
r: f64Red
g: f64Green
b: f64Blue
a: f64Alpha
Implementations
sourceimpl Color
impl Color
sourcepub const fn new(r: f64, g: f64, b: f64, a: f64) -> Self
pub const fn new(r: f64, g: f64, b: f64, a: f64) -> 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) -> [f64; 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: f64, g: f64, b: f64) -> Self
👎 Deprecated: Use new instead.
pub fn from_rgb(r: f64, g: f64, b: f64) -> Self
Use new instead.
Arguments:
r: Red value [0..1]g: Green value [0..1]b: Blue value [0..1]
sourcepub fn from_rgba(r: f64, g: f64, b: f64, a: f64) -> Self
👎 Deprecated: Use new instead.
pub fn from_rgba(r: f64, g: f64, b: f64, a: f64) -> Self
Use new instead.
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
Use from_rgba8 instead.
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
Use from_rgba8 instead.
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: f64, g: f64, b: f64) -> Self
👎 Deprecated: Use from_linear_rgba instead.
pub fn from_linear_rgb(r: f64, g: f64, b: f64) -> Self
Use from_linear_rgba instead.
Arguments:
r: Red value [0..1]g: Green value [0..1]b: Blue value [0..1]
sourcepub fn from_linear_rgba(r: f64, g: f64, b: f64, a: f64) -> Self
pub fn from_linear_rgba(r: f64, g: f64, b: f64, a: f64) -> 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
Use from_linear_rgba8 instead.
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
Use from_linear_rgba8 instead.
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: f64, s: f64, v: f64) -> Self
👎 Deprecated: Use from_hsva instead.
pub fn from_hsv(h: f64, s: f64, v: f64) -> Self
Use from_hsva instead.
Arguments:
h: Hue angle [0..360]s: Saturation [0..1]v: Value [0..1]
sourcepub fn from_hsva(h: f64, s: f64, v: f64, a: f64) -> Self
pub fn from_hsva(h: f64, s: f64, v: f64, a: f64) -> Self
Arguments:
h: Hue angle [0..360]s: Saturation [0..1]v: Value [0..1]a: Alpha [0..1]
sourcepub fn from_hsl(h: f64, s: f64, l: f64) -> Self
👎 Deprecated: Use from_hsla instead.
pub fn from_hsl(h: f64, s: f64, l: f64) -> Self
Use from_hsla instead.
Arguments:
h: Hue angle [0..360]s: Saturation [0..1]l: Lightness [0..1]
sourcepub fn from_hsla(h: f64, s: f64, l: f64, a: f64) -> Self
pub fn from_hsla(h: f64, s: f64, l: f64, a: f64) -> Self
Arguments:
h: Hue angle [0..360]s: Saturation [0..1]l: Lightness [0..1]a: Alpha [0..1]
sourcepub fn from_hwb(h: f64, w: f64, b: f64) -> Self
👎 Deprecated: Use from_hwba instead.
pub fn from_hwb(h: f64, w: f64, b: f64) -> Self
Use from_hwba instead.
Arguments:
h: Hue angle [0..360]w: Whiteness [0..1]b: Blackness [0..1]
sourcepub fn from_hwba(h: f64, w: f64, b: f64, a: f64) -> Self
pub fn from_hwba(h: f64, w: f64, b: f64, a: f64) -> Self
Arguments:
h: Hue angle [0..360]w: Whiteness [0..1]b: Blackness [0..1]a: Alpha [0..1]
sourcepub fn from_oklab(l: f64, a: f64, b: f64) -> Self
👎 Deprecated: Use from_oklaba instead.
pub fn from_oklab(l: f64, a: f64, b: f64) -> Self
Use from_oklaba instead.
Arguments:
l: Perceived lightnessa: How green/red the color isb: How blue/yellow the color is
sourcepub fn from_oklaba(l: f64, a: f64, b: f64, alpha: f64) -> Self
pub fn from_oklaba(l: f64, a: f64, b: f64, alpha: f64) -> Self
Arguments:
l: Perceived lightnessa: How green/red the color isb: How blue/yellow the color isalpha: Alpha [0..1]
sourcepub fn from_lab(l: f64, a: f64, b: f64, alpha: f64) -> Self
pub fn from_lab(l: f64, a: f64, b: f64, alpha: f64) -> Self
Arguments:
l: Lightnessa: Distance along theaaxisb: Distance along thebaxisalpha: Alpha [0..1]
sourcepub fn interpolate_lab(&self, other: &Color, t: f64) -> Self
pub fn interpolate_lab(&self, other: &Color, t: f64) -> Self
Blend this color with the other one, in the Lab color-space. t in the range [0..1].
sourcepub fn from_lch(l: f64, c: f64, h: f64, alpha: f64) -> Self
pub fn from_lch(l: f64, c: f64, h: f64, alpha: f64) -> Self
Arguments:
l: Lightnessc: Chromah: Hue angle in radiansalpha: Alpha [0..1]
sourcepub fn interpolate_lch(&self, other: &Color, t: f64) -> Self
pub fn interpolate_lch(&self, other: &Color, t: f64) -> Self
Blend this color with the other one, in the LCH color-space. t in the range [0..1].
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) -> (f64, f64, f64, f64)
👎 Deprecated
pub fn rgba(&self) -> (f64, f64, f64, f64)
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)
Use to_rgba8 instead.
Returns: (r, g, b, a)
- Red, green, blue and alpha in the range [0..255]
sourcepub fn to_hsva(&self) -> (f64, f64, f64, f64)
pub fn to_hsva(&self) -> (f64, f64, f64, f64)
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) -> (f64, f64, f64, f64)
pub fn to_hsla(&self) -> (f64, f64, f64, f64)
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) -> (f64, f64, f64, f64)
pub fn to_hwba(&self) -> (f64, f64, f64, f64)
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) -> (f64, f64, f64, f64)
pub fn to_linear_rgba(&self) -> (f64, f64, f64, f64)
Returns: (r, g, b, a)
- Red, green, blue and alpha in the range [0..1]
sourcepub fn to_linear_rgba_u8(&self) -> (u8, u8, u8, u8)
pub fn to_linear_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_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: f64) -> Self
pub fn interpolate_rgb(&self, other: &Color, t: f64) -> 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: f64) -> Self
pub fn interpolate_linear_rgb(&self, other: &Color, t: f64) -> 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: f64) -> Self
pub fn interpolate_hsv(&self, other: &Color, t: f64) -> 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: f64) -> Self
pub fn interpolate_oklab(&self, other: &Color, t: f64) -> Self
Blend this color with the other one, in the Oklab color-space. t in the range [0..1].
Trait Implementations
sourceimpl ColorInterop for Color
impl ColorInterop for Color
sourceimpl<'de> Deserialize<'de> for Color
impl<'de> Deserialize<'de> for Color
Implement Serde deserialization from string
sourcefn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
sourceimpl From<Alpha<EncodedSrgb<f32>>> for Color
impl From<Alpha<EncodedSrgb<f32>>> for Color
sourcefn from(c: Alpha<EncodedSrgb<f32>>) -> Self
fn from(c: Alpha<EncodedSrgb<f32>>) -> Self
Converts to this type from the input type.
sourceimpl From<Alpha<EncodedSrgb<f64>>> for Color
impl From<Alpha<EncodedSrgb<f64>>> for Color
sourcefn from(c: Alpha<EncodedSrgb<f64>>) -> Self
fn from(c: Alpha<EncodedSrgb<f64>>) -> Self
Converts to this type from the input type.
sourceimpl From<Alpha<EncodedSrgb<u8>>> for Color
impl From<Alpha<EncodedSrgb<u8>>> for Color
sourcefn from(c: Alpha<EncodedSrgb<u8>>) -> Self
fn from(c: Alpha<EncodedSrgb<u8>>) -> Self
Converts to this type from the input type.
sourceimpl From<Color> for EncodedSrgb<f32>
impl From<Color> for EncodedSrgb<f32>
sourceimpl From<Color> for EncodedSrgb<f64>
impl From<Color> for EncodedSrgb<f64>
sourceimpl From<Color> for EncodedSrgb<u8>
impl From<Color> for EncodedSrgb<u8>
sourceimpl From<EncodedSrgb<f32>> for Color
impl From<EncodedSrgb<f32>> for Color
sourcefn from(c: EncodedSrgb<f32>) -> Self
fn from(c: EncodedSrgb<f32>) -> Self
Converts to this type from the input type.
sourceimpl From<EncodedSrgb<f64>> for Color
impl From<EncodedSrgb<f64>> for Color
sourcefn from(c: EncodedSrgb<f64>) -> Self
fn from(c: EncodedSrgb<f64>) -> Self
Converts to this type from the input type.
sourceimpl From<EncodedSrgb<u8>> for Color
impl From<EncodedSrgb<u8>> for Color
sourcefn from(c: EncodedSrgb<u8>) -> Self
fn from(c: EncodedSrgb<u8>) -> Self
Converts to this type from the input type.
sourceimpl PartialOrd<Color> for Color
impl PartialOrd<Color> for Color
sourcefn partial_cmp(&self, other: &Color) -> Option<Ordering>
fn partial_cmp(&self, other: &Color) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
impl StructuralPartialEq for Color
Auto Trait Implementations
impl RefUnwindSafe for Color
impl Send for Color
impl Sync for Color
impl Unpin for Color
impl UnwindSafe for Color
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more