[−]Enum druid::piet::Color
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.
Variants
Rgba32(u32)
Implementations
impl Color
pub const fn rgb8(r: u8, g: u8, b: u8) -> Color
Create a color from 8 bit per sample RGB values.
pub const fn rgba8(r: u8, g: u8, b: u8, a: u8) -> Color
Create a color from 8 bit per sample RGBA values.
pub const fn from_rgba32_u32(rgba: u32) -> Color
Create a color from a 32-bit rgba value (alpha as least significant byte).
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.
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());
pub fn grey(grey: f64) -> Color
Create a color with a grey value in the range 0.0..=1.0.
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.
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.
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.
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.
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.
pub fn as_rgba_u32(&self) -> u32
Convert a color value to a 32-bit rgba value.
pub fn as_rgba8(&self) -> (u8, u8, u8, u8)
Convert a color value to four 8-bit rgba values.
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.
pub const AQUA: Color
Opaque aqua (or cyan).
pub const BLACK: Color
Opaque black.
pub const BLUE: Color
Opaque blue.
pub const FUCHSIA: Color
Opaque fuchsia (or magenta).
pub const GRAY: Color
Opaque gray.
pub const GREEN: Color
Opaque green.
pub const LIME: Color
Opaque lime.
pub const MAROON: Color
Opaque maroon.
pub const NAVY: Color
Opaque navy.
pub const OLIVE: Color
Opaque olive.
pub const PURPLE: Color
Opaque purple.
pub const RED: Color
Opaque red.
pub const SILVER: Color
Opaque silver.
pub const TEAL: Color
Opaque teal.
pub const WHITE: Color
Opaque white.
pub const YELLOW: Color
Opaque yellow.
Trait Implementations
impl Clone for Color
pub fn clone(&self) -> Color
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Data for Color
[src]
impl Debug for Color
impl From<Color> for PaintBrush
pub fn from(src: Color) -> PaintBrush
impl<T> From<Color> for BackgroundBrush<T>
[src]
pub fn from(src: Color) -> BackgroundBrush<T>
[src]
impl Into<Value> for Color
[src]
impl<P> IntoBrush<P> for Color where
P: RenderContext,
P: RenderContext,
pub fn make_brush(
&'a self,
piet: &mut P,
_bbox: impl FnOnce() -> Rect
) -> Cow<'a, <P as RenderContext>::Brush>
&'a self,
piet: &mut P,
_bbox: impl FnOnce() -> Rect
) -> Cow<'a, <P as RenderContext>::Brush>
impl PartialEq<Color> for Color
impl StructuralPartialEq for Color
impl ValueType for Color
[src]
pub fn try_from_value(value: &Value) -> Result<Self, ValueTypeError>
[src]
Auto Trait Implementations
impl RefUnwindSafe for Color
[src]
impl Send for Color
[src]
impl Sync for Color
[src]
impl Unpin for Color
[src]
impl UnwindSafe for Color
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> AnyEq for T where
T: PartialEq<T> + Any,
[src]
T: PartialEq<T> + Any,
pub fn equals(&self, other: &(dyn Any + 'static)) -> bool
[src]
pub fn as_any(&self) -> &(dyn Any + 'static)
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> RoundFrom<T> for T
pub fn round_from(x: T) -> T
impl<T, U> RoundInto<U> for T where
U: RoundFrom<T>,
U: RoundFrom<T>,
pub fn round_into(self) -> U
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,