pub struct Color {
pub r: f64,
pub g: f64,
pub b: f64,
pub a: f64,
}
Expand description
The color
Fields§
§r: f64
Red
g: f64
Green
b: f64
Blue
a: f64
Alpha
Implementations§
source§impl 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
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
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: f64, g: f64, b: f64) -> Self
👎Deprecated: Use from_linear_rgba instead.
pub fn from_linear_rgb(r: f64, g: f64, b: f64) -> Self
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
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: f64, s: f64, v: f64) -> Self
👎Deprecated: Use from_hsva instead.
pub fn from_hsv(h: f64, s: f64, v: f64) -> Self
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
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
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
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_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)
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§
source§impl<'de> Deserialize<'de> for Color
impl<'de> Deserialize<'de> for Color
Implement Serde deserialization from string
source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
source§impl PartialOrd for Color
impl PartialOrd for Color
impl StructuralPartialEq for Color
Auto Trait Implementations§
impl Freeze for Color
impl RefUnwindSafe for Color
impl Send for Color
impl Sync for Color
impl Unpin for Color
impl UnwindSafe for Color
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)