Skip to main content

ColorSwatch

Struct ColorSwatch 

Source
pub struct ColorSwatch<T>
where T: Clone + Eq + Debug + 'static,
{ /* private fields */ }
Expand description

A color that has a small table of related colors called a “swatch”.

The table is accessed by key values of type T.

The table keeps its entries in the order they were given, as a Dart map literal does, so keys answers in that order. A table from a const item (from_static) is borrowed; one built at run time is owned.

See also:

  • MaterialColor and MaterialAccentColor, which define Material Design primary and accent color swatches.
  • Colors, which defines all of the standard Material Design colors.

Implementations§

Source§

impl<T> ColorSwatch<T>
where T: Clone + Eq + Debug + 'static,

Source

pub fn new( primary: Color, swatch: impl IntoIterator<Item = (T, Color)>, ) -> ColorSwatch<T>

Creates a color that has a small table of related colors called a “swatch”.

The primary argument should be the 32 bit ARGB value of one of the values in the swatch, as would be passed to the Color.new constructor for that same color, and as is exposed by value. (This is distinct from the key of any color in the swatch.)

swatch is read as a Dart map is filled: a key given twice keeps its first place and its last color.

Source

pub const fn from_static( primary: Color, swatch: &'static [(T, Color)], ) -> ColorSwatch<T>

Dart’s const ColorSwatch(primary, {...}): the table is a const slice of distinct keys, in the order a map literal would list them.

Source

pub const fn primary(&self) -> Color

The primary color: what Dart’s swatch is, as a Color.

Source

pub fn get(&self, key: &T) -> Option<Color>

Returns an element of the swatch table.

Source

pub fn keys(&self) -> impl Iterator<Item = &T>

Returns the valid keys for accessing operator[].

Source

pub fn lerp( a: Option<&ColorSwatch<T>>, b: Option<&ColorSwatch<T>>, t: f64, ) -> Option<ColorSwatch<T>>

Linearly interpolate between two ColorSwatches.

It delegates to Color.lerp to interpolate the different colors of the swatch.

If either color is null, this function linearly interpolates from a transparent instance of the other color.

The t argument represents position on the timeline, with 0.0 meaning that the interpolation has not started, returning a (or something equivalent to a), 1.0 meaning that the interpolation has finished, returning b (or something equivalent to b), and values in between meaning that the interpolation is at the relevant point on the timeline between a and b. The interpolation can be extrapolated beyond 0.0 and 1.0, so negative values and values greater than 1.0 are valid (and can easily be generated by curves such as Curves.elasticInOut). Each channel will be clamped to the range 0 to 255.

Values for t are usually obtained from an Animation<double>, such as an AnimationController.

Source

pub fn into_any(self) -> AnyColor

The swatch as the Color it is in Dart.

Trait Implementations§

Source§

impl<T> Clone for ColorSwatch<T>
where T: Clone + Eq + Debug + 'static,

Source§

fn clone(&self) -> ColorSwatch<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T> ColorExtension for ColorSwatch<T>
where T: Clone + Eq + Debug + 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

The extension as Any, for Dart’s is checks (AnyColor::extension).
Source§

fn eq_extension(&self, other: &(dyn ColorExtension + 'static)) -> bool

Dart’s == override on the subclass, called once the values compared equal. other is the same runtime type when it downcasts; any other type is unequal, as Dart’s runtimeType check makes it.
Source§

impl<T> Debug for ColorSwatch<T>
where T: Clone + Eq + Debug + 'static,

Source§

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

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

impl<T> From<ColorSwatch<T>> for AnyColor
where T: Clone + Eq + Debug + 'static,

Source§

fn from(swatch: ColorSwatch<T>) -> AnyColor

Converts to this type from the input type.
Source§

impl<T> PartialEq for ColorSwatch<T>
where T: Clone + Eq + Debug + 'static,

Source§

fn eq(&self, other: &ColorSwatch<T>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<T> Forget for ColorSwatch<T>

§

impl<T> Freeze for ColorSwatch<T>
where &'static [(T, Color)]: Freeze, Vec<(T, Color)>: Freeze,

§

impl<T> Move for ColorSwatch<T>

§

impl<T> RefUnwindSafe for ColorSwatch<T>

§

impl<T> Send for ColorSwatch<T>
where &'static [(T, Color)]: Send, Vec<(T, Color)>: Send,

§

impl<T> Sync for ColorSwatch<T>
where T: Sync, Vec<(T, Color)>: Sync,

§

impl<T> Unpin for ColorSwatch<T>
where &'static [(T, Color)]: Unpin, Vec<(T, Color)>: Unpin,

§

impl<T> UnsafeUnpin for ColorSwatch<T>
where &'static [(T, Color)]: UnsafeUnpin, Vec<(T, Color)>: UnsafeUnpin,

§

impl<T> UnwindSafe for ColorSwatch<T>
where &'static [(T, Color)]: UnwindSafe, Vec<(T, Color)>: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

fn downcast(&self) -> &T

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,