Skip to main content

AnyColor

Struct AnyColor 

Source
pub struct AnyColor { /* private fields */ }
Expand description

A Color that may be an instance of a Color subclass.

Painting and the framework store this wherever Flutter stores a Color. The engine’s Color is the value the subclass passed to super, reached by color or by deref, so every Color method is available and returns a plain Color, as an inherited method does in Dart. The subclass is recovered with extension, Dart’s is check.

Equality follows Dart’s: two plain colors compare by value, two extended colors compare by value and by the subclass’s ==, and a plain color never equals an extended one.

Implementations§

Source§

impl AnyColor

Source

pub const fn new(color: Color) -> AnyColor

A plain color.

Source

pub const fn with_static( color: Color, extension: &'static dyn ColorExtension, ) -> AnyColor

A subclass instance from a const table: color is what the subclass passes to super, extension the subclass itself.

Source

pub fn with_shared(color: Color, extension: Rc<dyn ColorExtension>) -> AnyColor

A subclass instance built at run time.

Source

pub fn color(&self) -> Color

The color as the engine sees it: the subclass’s super value.

Source

pub fn extension<T>(&self) -> Option<&T>
where T: ColorExtension,

Dart’s color is T: the subclass instance, if this color is one.

Source

pub fn has_extension(&self) -> bool

Whether this color is a subclass instance.

Source

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

Color.lerp on the values; the subclasses do not survive interpolation, as in Dart.

Methods from Deref<Target = Color>§

Source

pub fn value(&self) -> u32

👎Deprecated:

Use component accessors like .r or .g, or to_argb32 for an explicit conversion

A 32 bit value representing this color.

This getter is a stub. It is recommended instead to use the explicit to_argb32 method.

Source

pub fn to_argb32(&self) -> u32

Returns a 32-bit value representing this color.

The returned value is compatible with the default constructor (Color::new) but does not guarantee to result in the same color due to imprecisions in numeric conversions.

Unlike accessing the floating point equivalent channels individually (a, r, g, b), this method is intentionally lossy, and scales each channel using (channel * 255.0).round().clamp(0, 255).

While useful for storing a 32-bit integer value, prefer accessing the individual channels (and storing the double equivalent) where higher precision is required.

The bits are assigned as follows:

  • Bits 24-31 represents the a channel as an 8-bit unsigned integer.
  • Bits 16-23 represents the r channel as an 8-bit unsigned integer.
  • Bits 8-15 represents the g channel as an 8-bit unsigned integer.
  • Bits 0-7 represents the b channel as an 8-bit unsigned integer.

Warning The value returned by this getter implicitly converts floating-point component values (such as 0.5) into their 8-bit equivalent by using the to_argb32 method; the returned value is not guaranteed to be stable across different platforms or executions due to the complexity of floating-point math.

Source

pub fn alpha(&self) -> i32

👎Deprecated:

Use (*.a * 255.0).round().clamp(0, 255)

The alpha channel of this color in an 8 bit value.

A value of 0 means this color is fully transparent. A value of 255 means this color is fully opaque.

Source

pub fn opacity(&self) -> f64

👎Deprecated:

Use .a.

The alpha channel of this color as a double.

A value of 0.0 means this color is fully transparent. A value of 1.0 means this color is fully opaque.

Source

pub fn red(&self) -> i32

👎Deprecated:

Use (*.r * 255.0).round().clamp(0, 255)

The red channel of this color in an 8 bit value.

Source

pub fn green(&self) -> i32

👎Deprecated:

Use (*.g * 255.0).round().clamp(0, 255)

The green channel of this color in an 8 bit value.

Source

pub fn blue(&self) -> i32

👎Deprecated:

Use (*.b * 255.0).round().clamp(0, 255)

The blue channel of this color in an 8 bit value.

Source

pub fn with_values( &self, alpha: Option<f64>, red: Option<f64>, green: Option<f64>, blue: Option<f64>, color_space: Option<ColorSpace>, ) -> Color

Returns a new color with the provided components updated.

Each component (alpha, red, green, blue) represents a floating-point value; see Color::from for details and examples.

If color_space is provided, and is different than the current color space, the component values are updated before transforming them to the provided ColorSpace.

Example:

/// Create a color with 50% opacity.
fn make_transparent(color: Color) -> Color {
    color.with_values(Some(0.5), None, None, None, None)
}
Source

pub fn with_alpha(&self, a: i32) -> Color

Returns a new color that matches this color with the alpha channel replaced with a (which ranges from 0 to 255).

Out of range values will have unexpected effects.

Source

pub fn with_opacity(&self, opacity: f64) -> Color

👎Deprecated:

Use .with_values() to avoid precision loss.

Returns a new color that matches this color with the alpha channel replaced with the given opacity (which ranges from 0.0 to 1.0).

Out of range values will have unexpected effects.

Source

pub fn with_red(&self, r: i32) -> Color

Returns a new color that matches this color with the red channel replaced with r (which ranges from 0 to 255).

Out of range values will have unexpected effects.

Source

pub fn with_green(&self, g: i32) -> Color

Returns a new color that matches this color with the green channel replaced with g (which ranges from 0 to 255).

Out of range values will have unexpected effects.

Source

pub fn with_blue(&self, b: i32) -> Color

Returns a new color that matches this color with the blue channel replaced with b (which ranges from 0 to 255).

Out of range values will have unexpected effects.

Source

pub fn compute_luminance(&self) -> f64

Returns a brightness value between 0 for darkest and 1 for lightest.

Represents the relative luminance of the color. This value is computationally expensive to calculate.

See https://en.wikipedia.org/wiki/Relative_luminance.

Trait Implementations§

Source§

impl Clone for AnyColor

Source§

fn clone(&self) -> AnyColor

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 Debug for AnyColor

Source§

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

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

impl Deref for AnyColor

Source§

type Target = Color

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Color

Dereferences the value.
Source§

impl Display for AnyColor

Dart’s Color.toString and a color subclass’s, which the inner Debug writes.

Source§

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

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

impl From<Color> for AnyColor

Source§

fn from(color: Color) -> AnyColor

Converts to this type from the input type.
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 From<WidgetStateColor> for AnyColor

Source§

fn from(color: WidgetStateColor) -> AnyColor

Converts to this type from the input type.
Source§

impl MaybeWidgetStateProperty<Color> for AnyColor

Source§

fn as_widget_state_property(&self) -> Option<&dyn WidgetStateProperty<Color>>

The property this value is, if it is one.
Source§

fn from_resolved(value: Color) -> AnyColor

A resolved value as this type (Dart’s T is both).
Source§

impl PartialEq for AnyColor

Source§

fn eq(&self, other: &AnyColor) -> bool

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<Color> for AnyColor

Source§

fn eq(&self, other: &Color) -> 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 !RefUnwindSafe for AnyColor

§

impl !Send for AnyColor

§

impl !Sync for AnyColor

§

impl !UnwindSafe for AnyColor

§

impl Forget for AnyColor

§

impl Freeze for AnyColor
where &'static dyn ColorExtension: Freeze, *const RcInner<dyn ColorExtension> is !null: Freeze, PhantomData<RcInner<dyn ColorExtension>>: Freeze,

§

impl Move for AnyColor

§

impl Unpin for AnyColor
where &'static dyn ColorExtension: Unpin, Rc<dyn ColorExtension>: Unpin,

§

impl UnsafeUnpin for AnyColor
where &'static dyn ColorExtension: UnsafeUnpin, *const RcInner<dyn ColorExtension> is !null: UnsafeUnpin, PhantomData<RcInner<dyn ColorExtension>>: UnsafeUnpin,

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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>