DynamicColor

Struct DynamicColor 

Source
pub struct DynamicColor {
    pub raw: Vec3,
    pub space: DynamicColorSpace,
    pub state: DynamicState,
}
Expand description

A dynamic color, with its Space and State defined as data. This is mostly useful for (de)serialization.

See Color, ColorSpace and State for more.

Fields§

§raw: Vec3

The raw tristimulus value of the color. Be careful when modifying this directly, i.e. don’t multiply two Colors’ raw values unless they are in the same color space and state.

§space: DynamicColorSpace§state: DynamicState

Implementations§

Source§

impl DynamicColor

Source

pub fn new(raw: Vec3, space: DynamicColorSpace, state: DynamicState) -> Self

Create a new DynamicColor with specified raw color components, color space, and state.

Source

pub fn convert(self, dest_space: DynamicColorSpace) -> ColorResult<Self>

Convert self to the given color space. Must not attempt to convert to or from a nonlinear color space while in scene-referred state.

Source

pub fn convert_state<F>( self, dest_state: DynamicState, conversion: F, ) -> ColorResult<Self>
where F: FnOnce(Vec3) -> Vec3,

Convert self’s state to the given state using the given conversion function.

self.space must be linear. See docs for Color::<Space, State>::convert_state

Source

pub fn downcast_convert<DstSpace, DstState>( self, ) -> ColorResult<Color<DstSpace, DstState>>
where DstSpace: ColorSpace, DstState: State,

Convert self to the specified space and downcast it to a typed Color with the space and state specified. self must already be in the correct DynamicState

Source

pub fn linearize(self) -> Self

Convert self into the closest linear color space, if it is not linear already

Source

pub fn with_alpha( &self, alpha: f32, alpha_state: DynamicAlphaState, ) -> DynamicColorAlpha

Converts self to a DynamicColorAlpha with specified DynamicAlphaState by adding an alpha component.

Source

pub fn from_kolor(color: Color, state: DynamicState) -> Self

Trait Implementations§

Source§

impl AnyColor for DynamicColor

Source§

fn space(&self) -> DynamicColorSpace

Source§

fn state(&self) -> DynamicState

Source§

fn raw(&self) -> Vec3

Source§

fn dynamic(&self) -> DynamicColor

Upcasts self into a DynamicColor
Source§

impl Clone for DynamicColor

Source§

fn clone(&self) -> DynamicColor

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 DynamicColor

Source§

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

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

impl<'de> Deserialize<'de> for DynamicColor

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'a> From<&'a dyn AnyColor> for DynamicColor

Source§

fn from(color: &'a dyn AnyColor) -> DynamicColor

Converts to this type from the input type.
Source§

impl<Spc: ColorSpace, St: State> From<Color<Spc, St>> for DynamicColor

Source§

fn from(color: Color<Spc, St>) -> DynamicColor

Converts to this type from the input type.
Source§

impl From<DynamicColor> for Color

Source§

fn from(color: DynamicColor) -> Color

Converts to this type from the input type.
Source§

impl PartialEq for DynamicColor

Source§

fn eq(&self, other: &DynamicColor) -> 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 Serialize for DynamicColor

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for DynamicColor

Source§

impl StructuralPartialEq for DynamicColor

Auto Trait Implementations§

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

Source§

fn convert_raw(raw: Vec3, _alpha: f32) -> Vec3

Source§

impl<SrcAlpha, DstAlpha> ConvertToAlphaRaw<DstAlpha> for SrcAlpha
where DstAlpha: ConvertFromAlphaRaw<SrcAlpha>,

Source§

fn convert_raw(raw: Vec3, alpha: f32) -> Vec3

Source§

impl<C> DynColor for C
where C: AnyColor,

Source§

fn downcast<Spc, St>(&self) -> Result<Color<Spc, St>, ColorError>
where Spc: ColorSpace, St: State,

Attempt to convert to a typed Color. Returns an error if self’s color space and state do not match the given types.

Source§

fn downcast_unchecked<Spc, St>(&self) -> Color<Spc, St>
where Spc: ColorSpace, St: State,

Convert to a typed Color without checking if the color space and state types match this color’s space and state. Use only if you are sure that this color is in the correct format.

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,