Color

Struct Color 

Source
pub struct Color {
    pub r: u8,
    pub g: u8,
    pub b: u8,
    pub a: u8,
}
Expand description

32-bit RGBA color.

Fields§

§r: u8

Red component.

§g: u8

Green component.

§b: u8

Blue component.

§a: u8

Alpha component.

Implementations§

Source§

impl Color

Source

pub const fn rgb8(r: u8, g: u8, b: u8) -> Self

Creates a new RGB color with 255 alpha.

Source

pub const fn rgba8(r: u8, g: u8, b: u8, a: u8) -> Self

Creates a new RGBA color.

Source

pub fn rgb(r: f64, g: f64, b: f64) -> Self

Create a color from three floating point values, each in the range 0.0 to 1.0.

The interpretation is the same as rgb8, and no greater precision is (currently) assumed.

Source

pub fn rgba(r: f64, g: f64, b: f64, a: f64) -> Self

Create a color from four floating point values, each in the range 0.0 to 1.0.

The interpretation is the same as rgba32, and no greater precision is (currently) assumed.

Source

pub fn hlc(h: f64, l: f64, c: f64) -> Self

Create a color from a CIEL*a*b* polar (also known as CIE HCL) specification.

The h parameter is an angle in degrees, with 0 roughly magenta, 90 roughly yellow, 180 roughly cyan, and 270 roughly blue. The l parameter is perceptual luminance, with 0 black and 100 white. The c parameter is a chrominance concentration, with 0 grayscale and a nominal maximum of 127 (in the future, higher values might be useful, for high gamut contexts).

Currently this is just converted into sRGB, but in the future as we support high-gamut colorspaces, it can be used to specify more colors or existing colors with a higher accuracy.

Currently out-of-gamut values are clipped to the nearest sRGB color, which is perhaps not ideal (the clipping might change the hue). See https://github.com/d3/d3-color/issues/33 for discussion.

Source

pub fn hlca(h: f64, l: f64, c: f64, a: f64) -> Color

Create a color from a CIEL*a*b* polar specification and alpha.

The a value represents alpha in the range 0.0 to 1.0.

Source

pub fn parse(s: &str) -> Option<Self>

Parses a color from a string.

Currently accepts CSS style hexidecimal colors of the forms #RGB, #RGBA, #RRGGBB, #RRGGBBAA or the name of an SVG color such as “aliceblue”.

Source

pub fn with_alpha_factor(self, alpha: f32) -> Self

Returns the color with the alpha component multiplied by the specified factor.

Source

pub fn to_premul_u32(self) -> u32

Returns the color as a packed premultiplied value.

Source§

impl Color

Named SVG colors.

Source

pub const ALICE_BLUE: Color

Alice blue (240, 248, 255, 255)

Source

pub const ANTIQUE_WHITE: Color

Antique white (250, 235, 215, 255)

Source

pub const AQUA: Color

Aqua (0, 255, 255, 255)

Source

pub const AQUAMARINE: Color

Aquamarine (127, 255, 212, 255)

Source

pub const AZURE: Color

Azure (240, 255, 255, 255)

Source

pub const BEIGE: Color

Beige (245, 245, 220, 255)

Source

pub const BISQUE: Color

Bisque (255, 228, 196, 255)

Source

pub const BLACK: Color

Black (0, 0, 0, 255)

Source

pub const BLANCHED_ALMOND: Color

Blanched almond (255, 235, 205, 255)

Source

pub const BLUE: Color

Blue (0, 0, 255, 255)

Source

pub const BLUE_VIOLET: Color

Blue violet (138, 43, 226, 255)

Source

pub const BROWN: Color

Brown (165, 42, 42, 255)

Source

pub const BURLYWOOD: Color

Burlywood (222, 184, 135, 255)

Source

pub const CADET_BLUE: Color

Cadet blue (95, 158, 160, 255)

Source

pub const CHARTREUSE: Color

Chartreuse (127, 255, 0, 255)

Source

pub const CHOCOLATE: Color

Chocolate (210, 105, 30, 255)

Source

pub const CORAL: Color

Coral (255, 127, 80, 255)

Source

pub const CORNFLOWER_BLUE: Color

Cornflower blue (100, 149, 237, 255)

Source

pub const CORNSILK: Color

Cornsilk (255, 248, 220, 255)

Source

pub const CRIMSON: Color

Crimson (220, 20, 60, 255)

Source

pub const CYAN: Color

Cyan (0, 255, 255, 255)

Source

pub const DARK_BLUE: Color

Dark blue (0, 0, 139, 255)

Source

pub const DARK_CYAN: Color

Dark cyan (0, 139, 139, 255)

Source

pub const DARK_GOLDENROD: Color

Dark goldenrod (184, 134, 11, 255)

Source

pub const DARK_GRAY: Color

Dark gray (169, 169, 169, 255)

Source

pub const DARK_GREEN: Color

Dark green (0, 100, 0, 255)

Source

pub const DARK_KHAKI: Color

Dark khaki (189, 183, 107, 255)

Source

pub const DARK_MAGENTA: Color

Dark magenta (139, 0, 139, 255)

Source

pub const DARK_OLIVE_GREEN: Color

Dark olive green (85, 107, 47, 255)

Source

pub const DARK_ORANGE: Color

Dark orange (255, 140, 0, 255)

Source

pub const DARK_ORCHID: Color

Dark orchid (153, 50, 204, 255)

Source

pub const DARK_RED: Color

Dark red (139, 0, 0, 255)

Source

pub const DARK_SALMON: Color

Dark salmon (233, 150, 122, 255)

Source

pub const DARK_SEA_GREEN: Color

Dark sea green (143, 188, 143, 255)

Source

pub const DARK_SLATE_BLUE: Color

Dark slate blue (72, 61, 139, 255)

Source

pub const DARK_SLATE_GRAY: Color

Dark slate gray (47, 79, 79, 255)

Source

pub const DARK_TURQUOISE: Color

Dark turquoise (0, 206, 209, 255)

Source

pub const DARK_VIOLET: Color

Dark violet (148, 0, 211, 255)

Source

pub const DEEP_PINK: Color

Deep pink (255, 20, 147, 255)

Source

pub const DEEP_SKY_BLUE: Color

Deep sky blue (0, 191, 255, 255)

Source

pub const DIM_GRAY: Color

Dim gray (105, 105, 105, 255)

Source

pub const DODGER_BLUE: Color

Dodger blue (30, 144, 255, 255)

Source

pub const FIREBRICK: Color

Firebrick (178, 34, 34, 255)

Source

pub const FLORAL_WHITE: Color

Floral white (255, 250, 240, 255)

Source

pub const FOREST_GREEN: Color

Forest green (34, 139, 34, 255)

Source

pub const FUCHSIA: Color

Fuchsia (255, 0, 255, 255)

Source

pub const GAINSBORO: Color

Gainsboro (220, 220, 220, 255)

Source

pub const GHOST_WHITE: Color

Ghost white (248, 248, 255, 255)

Source

pub const GOLD: Color

Gold (255, 215, 0, 255)

Source

pub const GOLDENROD: Color

Goldenrod (218, 165, 32, 255)

Source

pub const GRAY: Color

Gray (128, 128, 128, 255)

Source

pub const GREEN: Color

Green (0, 128, 0, 255)

Source

pub const GREEN_YELLOW: Color

Green yellow (173, 255, 47, 255)

Source

pub const HONEYDEW: Color

Honeydew (240, 255, 240, 255)

Source

pub const HOT_PINK: Color

Hot pink (255, 105, 180, 255)

Source

pub const INDIAN_RED: Color

Indian red (205, 92, 92, 255)

Source

pub const INDIGO: Color

Indigo (75, 0, 130, 255)

Source

pub const IVORY: Color

Ivory (255, 255, 240, 255)

Source

pub const KHAKI: Color

Khaki (240, 230, 140, 255)

Source

pub const LAVENDER: Color

Lavender (230, 230, 250, 255)

Source

pub const LAVENDER_BLUSH: Color

Lavender blush (255, 240, 245, 255)

Source

pub const LAWN_GREEN: Color

Lawn green (124, 252, 0, 255)

Source

pub const LEMON_CHIFFON: Color

Lemon chiffon (255, 250, 205, 255)

Source

pub const LIGHT_BLUE: Color

Light blue (173, 216, 230, 255)

Source

pub const LIGHT_CORAL: Color

Light coral (240, 128, 128, 255)

Source

pub const LIGHT_CYAN: Color

Light cyan (224, 255, 255, 255)

Source

pub const LIGHT_GOLDENROD_YELLOW: Color

Light goldenrod yellow (250, 250, 210, 255)

Source

pub const LIGHT_GRAY: Color

Light gray (211, 211, 211, 255)

Source

pub const LIGHT_GREEN: Color

Light green (144, 238, 144, 255)

Source

pub const LIGHT_PINK: Color

Light pink (255, 182, 193, 255)

Source

pub const LIGHT_SALMON: Color

Light salmon (255, 160, 122, 255)

Source

pub const LIGHT_SEA_GREEN: Color

Light sea green (32, 178, 170, 255)

Source

pub const LIGHT_SKY_BLUE: Color

Light sky blue (135, 206, 250, 255)

Source

pub const LIGHT_SLATE_GRAY: Color

Light slate gray (119, 136, 153, 255)

Source

pub const LIGHT_STEEL_BLUE: Color

Light steel blue (176, 196, 222, 255)

Source

pub const LIGHT_YELLOW: Color

Light yellow (255, 255, 224, 255)

Source

pub const LIME: Color

Lime (0, 255, 0, 255)

Source

pub const LIME_GREEN: Color

Lime green (50, 205, 50, 255)

Source

pub const LINEN: Color

Linen (250, 240, 230, 255)

Source

pub const MAGENTA: Color

Magenta (255, 0, 255, 255)

Source

pub const MAROON: Color

Maroon (128, 0, 0, 255)

Source

pub const MEDIUM_AQUAMARINE: Color

Medium aquamarine (102, 205, 170, 255)

Source

pub const MEDIUM_BLUE: Color

Medium blue (0, 0, 205, 255)

Source

pub const MEDIUM_ORCHID: Color

Medium orchid (186, 85, 211, 255)

Source

pub const MEDIUM_PURPLE: Color

Medium purple (147, 112, 219, 255)

Source

pub const MEDIUM_SEA_GREEN: Color

Medium sea green (60, 179, 113, 255)

Source

pub const MEDIUM_SLATE_BLUE: Color

Medium slate blue (123, 104, 238, 255)

Source

pub const MEDIUM_SPRING_GREEN: Color

Medium spring green (0, 250, 154, 255)

Source

pub const MEDIUM_TURQUOISE: Color

Medium turquoise (72, 209, 204, 255)

Source

pub const MEDIUM_VIOLET_RED: Color

Medium violet red (199, 21, 133, 255)

Source

pub const MIDNIGHT_BLUE: Color

Midnight blue (25, 25, 112, 255)

Source

pub const MINT_CREAM: Color

Mint cream (245, 255, 250, 255)

Source

pub const MISTY_ROSE: Color

Misty rose (255, 228, 225, 255)

Source

pub const MOCCASIN: Color

Moccasin (255, 228, 181, 255)

Source

pub const NAVAJO_WHITE: Color

Navajo white (255, 222, 173, 255)

Source

pub const NAVY: Color

Navy (0, 0, 128, 255)

Source

pub const OLD_LACE: Color

Old lace (253, 245, 230, 255)

Source

pub const OLIVE: Color

Olive (128, 128, 0, 255)

Source

pub const OLIVE_DRAB: Color

Olive drab (107, 142, 35, 255)

Source

pub const ORANGE: Color

Orange (255, 165, 0, 255)

Source

pub const ORANGE_RED: Color

Orange red (255, 69, 0, 255)

Source

pub const ORCHID: Color

Orchid (218, 112, 214, 255)

Source

pub const PALE_GOLDENROD: Color

Pale goldenrod (238, 232, 170, 255)

Source

pub const PALE_GREEN: Color

Pale green (152, 251, 152, 255)

Source

pub const PALE_TURQUOISE: Color

Pale turquoise (175, 238, 238, 255)

Source

pub const PALE_VIOLET_RED: Color

Pale violet red (219, 112, 147, 255)

Source

pub const PAPAYA_WHIP: Color

Papaya whip (255, 239, 213, 255)

Source

pub const PEACH_PUFF: Color

Peach puff (255, 218, 185, 255)

Source

pub const PERU: Color

Peru (205, 133, 63, 255)

Source

pub const PINK: Color

Pink (255, 192, 203, 255)

Source

pub const PLUM: Color

Plum (221, 160, 221, 255)

Source

pub const POWDER_BLUE: Color

Powder blue (176, 224, 230, 255)

Source

pub const PURPLE: Color

Purple (128, 0, 128, 255)

Source

pub const REBECCA_PURPLE: Color

Rebecca purple (102, 51, 153, 255)

Source

pub const RED: Color

Red (255, 0, 0, 255)

Source

pub const ROSY_BROWN: Color

Rosy brown (188, 143, 143, 255)

Source

pub const ROYAL_BLUE: Color

Royal blue (65, 105, 225, 255)

Source

pub const SADDLE_BROWN: Color

Saddle brown (139, 69, 19, 255)

Source

pub const SALMON: Color

Salmon (250, 128, 114, 255)

Source

pub const SANDY_BROWN: Color

Sandy brown (244, 164, 96, 255)

Source

pub const SEA_GREEN: Color

Sea green (46, 139, 87, 255)

Source

pub const SEASHELL: Color

Seashell (255, 245, 238, 255)

Source

pub const SIENNA: Color

Sienna (160, 82, 45, 255)

Source

pub const SILVER: Color

Silver (192, 192, 192, 255)

Source

pub const SKY_BLUE: Color

Sky blue (135, 206, 235, 255)

Source

pub const SLATE_BLUE: Color

Slate blue (106, 90, 205, 255)

Source

pub const SLATE_GRAY: Color

Slate gray (112, 128, 144, 255)

Source

pub const SNOW: Color

Snow (255, 250, 250, 255)

Source

pub const SPRING_GREEN: Color

Spring green (0, 255, 127, 255)

Source

pub const STEEL_BLUE: Color

Steel blue (70, 130, 180, 255)

Source

pub const TAN: Color

Tan (210, 180, 140, 255)

Source

pub const TEAL: Color

Teal (0, 128, 128, 255)

Source

pub const THISTLE: Color

Thistle (216, 191, 216, 255)

Source

pub const TOMATO: Color

Tomato (255, 99, 71, 255)

Source

pub const TRANSPARENT: Color

Transparent (0, 0, 0, 0)

Source

pub const TURQUOISE: Color

Turquoise (64, 224, 208, 255)

Source

pub const VIOLET: Color

Violet (238, 130, 238, 255)

Source

pub const WHEAT: Color

Wheat (245, 222, 179, 255)

Source

pub const WHITE: Color

White (255, 255, 255, 255)

Source

pub const WHITE_SMOKE: Color

White smoke (245, 245, 245, 255)

Source

pub const YELLOW: Color

Yellow (255, 255, 0, 255)

Source

pub const YELLOW_GREEN: Color

Yellow green (154, 205, 50, 255)

Trait Implementations§

Source§

impl Clone for Color

Source§

fn clone(&self) -> Color

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Color

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Color

Source§

fn default() -> Color

Returns the “default value” for a type. Read more
Source§

impl<'a> From<&'a Color> for BrushRef<'_>

Source§

fn from(color: &'a Color) -> Self

Converts to this type from the input type.
Source§

impl From<[u8; 3]> for Color

Source§

fn from(rgb: [u8; 3]) -> Self

Converts to this type from the input type.
Source§

impl From<[u8; 4]> for Color

Source§

fn from(rgba: [u8; 4]) -> Self

Converts to this type from the input type.
Source§

impl From<Color> for Brush

Source§

fn from(c: Color) -> Self

Converts to this type from the input type.
Source§

impl From<Color> for BrushRef<'_>

Source§

fn from(color: Color) -> Self

Converts to this type from the input type.
Source§

impl Hash for Color

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Color

Source§

fn cmp(&self, other: &Color) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Color

Source§

fn eq(&self, other: &Color) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Color

Source§

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 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Color

Source§

impl Eq for Color

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.