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) -> Color
pub const fn new(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]
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) -> Color
sourcepub fn from_rgb(r: f64, g: f64, b: f64) -> Color
👎Deprecated: Use new instead.
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
👎Deprecated: Use new instead.
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
👎Deprecated: Use from_rgba8 instead.
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
👎Deprecated: Use from_rgba8 instead.
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_rgba8(r: u8, g: u8, b: u8, a: u8) -> Color
pub fn from_rgba8(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
👎Deprecated: Use from_linear_rgba instead.
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_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_linear_rgb_u8(r: u8, g: u8, b: u8) -> Color
👎Deprecated: Use from_linear_rgba8 instead.
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_linear_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Color
👎Deprecated: Use from_linear_rgba8 instead.
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_linear_rgba8(r: u8, g: u8, b: u8, a: u8) -> Color
pub fn from_linear_rgba8(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
👎Deprecated: Use from_hsva instead.
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
👎Deprecated: Use from_hsla instead.
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
👎Deprecated: Use from_hwba instead.
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
👎Deprecated: Use from_oklaba instead.
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_html<S>(s: S) -> Result<Color, ParseColorError>
pub fn from_html<S>(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.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) -> 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_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§
source§impl PartialEq for Color
impl PartialEq for Color
source§impl PartialOrd for Color
impl PartialOrd for Color
1.0.0 · source§fn 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 moreimpl 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
Mutably borrows from an owned value. Read more
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian()
.