pub enum Color {
Process(ProcessColor),
Spot(SpotColor),
}Expand description
A color in a specific color space.
Variants§
Implementations§
Source§impl Color
impl Color
pub const BLACK: Self
pub const GRAY: Self
pub const WHITE: Self
pub const SILVER: Self
pub const NAVY: Self
pub const BLUE: Self
pub const AQUA: Self
pub const TEAL: Self
pub const EASTERN: Self
pub const PURPLE: Self
pub const FUCHSIA: Self
pub const MAROON: Self
pub const RED: Self
pub const ORANGE: Self
pub const YELLOW: Self
pub const OLIVE: Self
pub const GREEN: Self
pub const LIME: Self
Sourcepub fn luma(args: &mut Args) -> SourceResult<Color>
pub fn luma(args: &mut Args) -> SourceResult<Color>
Create a grayscale color.
Sourcepub fn oklab(args: &mut Args) -> SourceResult<Color>
pub fn oklab(args: &mut Args) -> SourceResult<Color>
Create an #link(“https://bottosson.github.io/posts/oklab/”)Oklab color.
Sourcepub fn oklch(args: &mut Args) -> SourceResult<Color>
pub fn oklch(args: &mut Args) -> SourceResult<Color>
Create an #link(“https://bottosson.github.io/posts/oklab/”)Oklch color.
Sourcepub fn linear_rgb(args: &mut Args) -> SourceResult<Color>
pub fn linear_rgb(args: &mut Args) -> SourceResult<Color>
Create an RGB(A) color with linear luma.
Sourcepub fn rgb(args: &mut Args) -> SourceResult<Color>
pub fn rgb(args: &mut Args) -> SourceResult<Color>
Create an RGB(A) color.
Sourcepub fn cmyk(args: &mut Args) -> SourceResult<Color>
pub fn cmyk(args: &mut Args) -> SourceResult<Color>
Create a CMYK color.
Sourcepub fn hsl(args: &mut Args) -> SourceResult<Color>
pub fn hsl(args: &mut Args) -> SourceResult<Color>
Create an HSL color.
Sourcepub fn hsv(args: &mut Args) -> SourceResult<Color>
pub fn hsv(args: &mut Args) -> SourceResult<Color>
Create an HSV color.
Sourcepub fn components(&self, alpha: bool) -> Array
pub fn components(&self, alpha: bool) -> Array
Extracts the components of this color.
Sourcepub fn space(&self) -> ColorSpace
pub fn space(&self) -> ColorSpace
Returns the constructor function for this color’s space.
Sourcepub fn to_hex(&self) -> EcoString
pub fn to_hex(&self) -> EcoString
Returns the color’s RGB(A) hex representation (such as #ffaa32 or #020304fe).
Sourcepub fn saturate(&self, span: Span, factor: Ratio) -> SourceResult<Color>
pub fn saturate(&self, span: Span, factor: Ratio) -> SourceResult<Color>
Increases the saturation of a color by a given factor.
Sourcepub fn desaturate(&self, span: Span, factor: Ratio) -> SourceResult<Color>
pub fn desaturate(&self, span: Span, factor: Ratio) -> SourceResult<Color>
Decreases the saturation of a color by a given factor.
Sourcepub fn negate(&self, space: Smart<ColorSpace>) -> HintedStrResult<Color>
pub fn negate(&self, space: Smart<ColorSpace>) -> HintedStrResult<Color>
Produces the complementary color using a provided color space.
Sourcepub fn rotate(
&self,
span: Span,
angle: Angle,
space: ProcessColorSpace,
) -> SourceResult<Color>
pub fn rotate( &self, span: Span, angle: Angle, space: ProcessColorSpace, ) -> SourceResult<Color>
Rotates the hue of the color by a given angle.
Sourcepub fn mix(
colors: Vec<WeightedColor>,
space: Smart<ColorSpace>,
) -> HintedStrResult<Color>
pub fn mix( colors: Vec<WeightedColor>, space: Smart<ColorSpace>, ) -> HintedStrResult<Color>
Create a color by mixing two or more colors.
Sourcepub fn transparentize(&self, scale: Ratio) -> StrResult<Color>
pub fn transparentize(&self, scale: Ratio) -> StrResult<Color>
Makes a color more transparent by a given factor.
Source§impl Color
impl Color
Sourcepub fn mix_iter(
colors: impl IntoIterator<Item = WeightedColor, IntoIter = impl ExactSizeIterator<Item = WeightedColor>> + Clone,
space: Smart<ColorSpace>,
) -> HintedStrResult<Color>
pub fn mix_iter( colors: impl IntoIterator<Item = WeightedColor, IntoIter = impl ExactSizeIterator<Item = WeightedColor>> + Clone, space: Smart<ColorSpace>, ) -> HintedStrResult<Color>
Same as Color::mix, but takes an iterator instead of a vector.
Sourcepub fn from_u8(r: u8, g: u8, b: u8, a: u8) -> Self
pub fn from_u8(r: u8, g: u8, b: u8, a: u8) -> Self
Construct a new RGBA color from 8-bit values.
Sourcepub fn with_alpha(self, alpha: f32) -> Self
pub fn with_alpha(self, alpha: f32) -> Self
Sets the alpha channel of the color, if it has one.
Sourcepub fn to_vec4_u8(&self) -> [u8; 4]
pub fn to_vec4_u8(&self) -> [u8; 4]
Converts the color to a vec of four u8s.
pub fn to_space(&self, space: &ColorSpace) -> HintedStrResult<Self>
pub fn to_process_space(&self, space: ProcessColorSpace) -> Self
pub fn to_luma(&self) -> Luma
pub fn to_oklab(&self) -> Oklab
pub fn to_oklch(&self) -> Oklch
pub fn to_rgb(&self) -> Rgb
pub fn to_linear_rgb(&self) -> LinearRgb
pub fn to_cmyk(&self) -> Cmyk
pub fn to_hsl(&self) -> Hsl
pub fn to_hsv(&self) -> Hsv
Sourcepub fn to_process(&self) -> ProcessColor
pub fn to_process(&self) -> ProcessColor
Convert to ProcessColor, using fallback for spot colors.
This is useful for rendering and export where spot colors cannot be expressed and need to be converted to their fallback representation.
Trait Implementations§
impl Eq for Color
Source§impl FromValue for Color
impl FromValue for Color
Source§fn from_value(value: Value) -> HintedStrResult<Self>
fn from_value(value: Value) -> HintedStrResult<Self>
Self.Source§impl NativeScope for Color
impl NativeScope for Color
Source§fn constructor() -> Option<&'static NativeFuncData>
fn constructor() -> Option<&'static NativeFuncData>
Source§impl NativeType for Color
impl NativeType 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 UnsafeUnpin for Color
impl UnwindSafe for Color
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> FromValue<Spanned<Value>> for Twhere
T: FromValue,
impl<T> FromValue<Spanned<Value>> for Twhere
T: FromValue,
Source§fn from_value(value: Spanned<Value>) -> Result<T, HintedString>
fn from_value(value: Spanned<Value>) -> Result<T, HintedString>
Self.Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoResult for Twhere
T: IntoValue,
impl<T> IntoResult for Twhere
T: IntoValue,
Source§fn into_result(self, _: Span) -> Result<Value, EcoVec<SourceDiagnostic>>
fn into_result(self, _: Span) -> Result<Value, EcoVec<SourceDiagnostic>>
Source§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more