pub struct ColorSwatch<T>{ /* 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:
MaterialColorandMaterialAccentColor, 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>
impl<T> ColorSwatch<T>
Sourcepub fn new(
primary: Color,
swatch: impl IntoIterator<Item = (T, Color)>,
) -> ColorSwatch<T>
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.
Sourcepub const fn from_static(
primary: Color,
swatch: &'static [(T, Color)],
) -> ColorSwatch<T>
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.
Sourcepub fn keys(&self) -> impl Iterator<Item = &T>
pub fn keys(&self) -> impl Iterator<Item = &T>
Returns the valid keys for accessing operator[].
Sourcepub fn lerp(
a: Option<&ColorSwatch<T>>,
b: Option<&ColorSwatch<T>>,
t: f64,
) -> Option<ColorSwatch<T>>
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.
Trait Implementations§
Source§impl<T> Clone for ColorSwatch<T>
impl<T> Clone for ColorSwatch<T>
Source§fn clone(&self) -> ColorSwatch<T>
fn clone(&self) -> ColorSwatch<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> ColorExtension for ColorSwatch<T>
impl<T> ColorExtension for ColorSwatch<T>
Source§fn eq_extension(&self, other: &(dyn ColorExtension + 'static)) -> bool
fn eq_extension(&self, other: &(dyn ColorExtension + 'static)) -> bool
== 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.