Enum Color

Source
#[non_exhaustive]
pub enum Color { }
Expand description

A datatype representing color.

Currently this is only a 32 bit RGBA value, but it will likely extend to some form of wide-gamut colorspace, and in the meantime is useful for giving programs proper type.

Implementations§

Source§

impl Color

Source

pub const AQUA: Color

Opaque aqua (or cyan).

Source

pub const BLACK: Color

Opaque black.

Source

pub const BLUE: Color

Opaque blue.

Source

pub const FUCHSIA: Color

Opaque fuchsia (or magenta).

Source

pub const GRAY: Color

Opaque gray.

Source

pub const GREEN: Color

Opaque green.

Source

pub const LIME: Color

Opaque lime.

Source

pub const MAROON: Color

Opaque maroon.

Source

pub const NAVY: Color

Opaque navy.

Source

pub const OLIVE: Color

Opaque olive.

Source

pub const PURPLE: Color

Opaque purple.

Source

pub const RED: Color

Opaque red.

Source

pub const SILVER: Color

Opaque silver.

Source

pub const TEAL: Color

Opaque teal.

Source

pub const TRANSPARENT: Color

Fully transparent

Source

pub const WHITE: Color

Opaque white.

Source

pub const YELLOW: Color

Opaque yellow.

Source

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

Create a color from 8 bit per sample RGB values.

Source

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

Create a color from 8 bit per sample RGBA values.

Source

pub const fn from_rgba32_u32(rgba: u32) -> Color

Create a color from a 32-bit rgba value (alpha as least significant byte).

Source

pub const fn from_hex_str(hex: &str) -> Result<Color, ColorParseError>

Attempt to create a color from a CSS-style hex string.

This will accept strings in the following formats, with or without the leading #:

  • rrggbb
  • rrggbbaa
  • rbg
  • rbga

This method returns a ColorParseError if the color cannot be parsed.

Source

pub const fn grey8(grey: u8) -> Color

Create a color from a grey value.

use piet::Color;

let grey_val = 0x55;

let one = Color::grey8(grey_val);
// is shorthand for
let two = Color::rgb8(grey_val, grey_val, grey_val);

assert_eq!(one.as_rgba_u32(), two.as_rgba_u32());
Source

pub fn grey(grey: f64) -> Color

Create a color with a grey value in the range 0.0..=1.0.

Source

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

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 rgb(r: f64, g: f64, b: f64) -> Color

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 hlc(h: f64, L: f64, c: f64) -> Color

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 with_alpha(self, a: f64) -> Color

Change just the alpha value of a color.

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

Source

pub const fn with_r8(self, r: u8) -> Color

Change just the red value of a color.

The r value represents red as a u8 from 0 to 255.

Source

pub const fn with_g8(self, g: u8) -> Color

Change just the green value of a color.

The g value represents green as a u8 from 0 to 255.

Source

pub const fn with_b8(self, b: u8) -> Color

Change just the blue value of a color.

The b value represents blue as a u8 from 0 to 255.

Source

pub const fn with_a8(self, a: u8) -> Color

Change just the alpha value of a color.

The a value represents alpha as a u8 from 0 to 255.

Source

pub const fn as_rgba_u32(self) -> u32

Convert a color value to a 32-bit rgba value.

Source

pub fn as_rgba8(self) -> (u8, u8, u8, u8)

Convert a color value to four 8-bit rgba values.

Source

pub fn as_rgba(self) -> (f64, f64, f64, f64)

Convert a color value to four f64 values, each in the range 0.0 to 1.0.

Trait Implementations§

Source§

impl Clone for Color

Source§

fn clone(&self) -> Color

Returns a copy 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<(), Error>

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

impl From<Color> for PaintBrush

Source§

fn from(src: Color) -> PaintBrush

Converts to this type from the input type.
Source§

impl Hash for Color

Source§

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

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 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 Copy for Color

Source§

impl Eq for Color

Source§

impl<P> IntoBrush<P> for Color
where P: RenderContext,

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> RoundFrom<T> for T

Source§

fn round_from(x: T) -> T

Performs the conversion.
Source§

impl<T, U> RoundInto<U> for T
where U: RoundFrom<T>,

Source§

fn round_into(self) -> U

Performs the conversion.
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.