Struct csscolorparser::Color
source · [−]Expand description
The color
Fields
r: f64Red
g: f64Green
b: f64Blue
a: f64Alpha
Implementations
sourceimpl Color
impl Color
sourcepub fn from_rgb(r: f64, g: f64, b: f64) -> Color
pub fn from_rgb(r: f64, g: f64, b: f64) -> Color
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) -> Color
pub fn from_rgba(r: f64, g: f64, b: f64, a: f64) -> Color
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) -> Color
pub fn from_rgb_u8(r: u8, g: u8, b: u8) -> Color
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) -> Color
pub fn from_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Color
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) -> Color
pub fn from_linear_rgb(r: f64, g: f64, b: f64) -> Color
Arguments:
r: Red value [0..1]g: Green value [0..1]b: Blue value [0..1]
sourcepub fn from_lrgb(r: f64, g: f64, b: f64) -> Color
👎 Deprecated
pub fn from_lrgb(r: f64, g: f64, b: f64) -> Color
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) -> Color
pub fn from_linear_rgba(r: f64, g: f64, b: f64, a: f64) -> Color
Arguments:
r: Red value [0..1]g: Green value [0..1]b: Blue value [0..1]a: Alpha value [0..1]
sourcepub fn from_lrgba(r: f64, g: f64, b: f64, a: f64) -> Color
👎 Deprecated
pub fn from_lrgba(r: f64, g: f64, b: f64, a: f64) -> Color
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) -> Color
pub fn from_linear_rgb_u8(r: u8, g: u8, b: u8) -> Color
Arguments:
r: Red value [0..255]g: Green value [0..255]b: Blue value [0..255]
sourcepub fn from_lrgb_u8(r: u8, g: u8, b: u8) -> Color
👎 Deprecated
pub fn from_lrgb_u8(r: u8, g: u8, b: u8) -> Color
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) -> Color
pub fn from_linear_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Color
Arguments:
r: Red value [0..255]g: Green value [0..255]b: Blue value [0..255]a: Alpha value [0..255]
sourcepub fn from_lrgba_u8(r: u8, g: u8, b: u8, a: u8) -> Color
👎 Deprecated
pub fn from_lrgba_u8(r: u8, g: u8, b: u8, a: u8) -> Color
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) -> Color
pub fn from_hsv(h: f64, s: f64, v: f64) -> Color
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) -> Color
pub fn from_hsva(h: f64, s: f64, v: f64, a: f64) -> Color
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) -> Color
pub fn from_hsl(h: f64, s: f64, l: f64) -> Color
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) -> Color
pub fn from_hsla(h: f64, s: f64, l: f64, a: f64) -> Color
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) -> Color
pub fn from_hwb(h: f64, w: f64, b: f64) -> Color
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) -> Color
pub fn from_hwba(h: f64, w: f64, b: f64, a: f64) -> Color
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) -> Color
pub fn from_oklab(l: f64, a: f64, b: f64) -> Color
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) -> Color
pub fn from_oklaba(l: f64, a: f64, b: f64, alpha: f64) -> Color
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) -> Color
pub fn from_lab(l: f64, a: f64, b: f64, alpha: f64) -> Color
Arguments:
l: Lightnessa: Distance along theaaxisb: Distance along thebaxisalpha: Alpha [0..1]
sourcepub fn interpolate_lab(&self, other: &Color, t: f64) -> Color
pub fn interpolate_lab(&self, other: &Color, t: f64) -> Color
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) -> Color
pub fn from_lch(l: f64, c: f64, h: f64, alpha: f64) -> Color
Arguments:
l: Lightnessc: Chromah: Hue angle in radiansalpha: Alpha [0..1]
sourcepub fn interpolate_lch(&self, other: &Color, t: f64) -> Color
pub fn interpolate_lch(&self, other: &Color, t: f64) -> Color
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<Color, ParseColorError>
pub fn from_html<S: AsRef<str>>(s: S) -> Result<Color, ParseColorError>
Create color from CSS color string.
Examples
use csscolorparser::Color;
let c = Color::from_html("rgb(255,0,0)")?;
assert_eq!(c.rgba(), (1.0, 0.0, 0.0, 1.0));
assert_eq!(c.rgba_u8(), (255, 0, 0, 255));
assert_eq!(c.to_hex_string(), "#ff0000");
assert_eq!(c.to_rgb_string(), "rgb(255,0,0)");sourcepub fn rgba(&self) -> (f64, f64, f64, f64)
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)
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) -> (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_lrgba(&self) -> (f64, f64, f64, f64)
👎 Deprecated
pub fn to_lrgba(&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_lrgba_u8(&self) -> (u8, u8, u8, u8)
👎 Deprecated
pub fn to_lrgba_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) -> Color
pub fn interpolate_rgb(&self, other: &Color, t: f64) -> Color
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) -> Color
pub fn interpolate_linear_rgb(&self, other: &Color, t: f64) -> Color
Blend this color with the other one, in the linear RGB color-space. t in the range [0..1].
sourcepub fn interpolate_lrgb(&self, other: &Color, t: f64) -> Color
👎 Deprecated
pub fn interpolate_lrgb(&self, other: &Color, t: f64) -> Color
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) -> Color
pub fn interpolate_hsv(&self, other: &Color, t: f64) -> Color
Blend this color with the other one, in the HSV 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<f64>
impl From<Color> for EncodedSrgb<f64>
sourceimpl From<Color> for EncodedSrgb<f32>
impl From<Color> for EncodedSrgb<f32>
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
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more