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
impl AnyColor
Sourcepub const fn with_static(
color: Color,
extension: &'static dyn ColorExtension,
) -> AnyColor
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.
A subclass instance built at run time.
Sourcepub fn extension<T>(&self) -> Option<&T>where
T: ColorExtension,
pub fn extension<T>(&self) -> Option<&T>where
T: ColorExtension,
Dart’s color is T: the subclass instance, if this color is one.
Sourcepub fn has_extension(&self) -> bool
pub fn has_extension(&self) -> bool
Whether this color is a subclass instance.
Methods from Deref<Target = Color>§
Sourcepub fn value(&self) -> u32
👎Deprecated: Use component accessors like .r or .g, or to_argb32 for an explicit conversion
pub fn value(&self) -> u32
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.
Sourcepub fn to_argb32(&self) -> u32
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
achannel as an 8-bit unsigned integer. - Bits 16-23 represents the
rchannel as an 8-bit unsigned integer. - Bits 8-15 represents the
gchannel as an 8-bit unsigned integer. - Bits 0-7 represents the
bchannel 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 theto_argb32method; the returned value is not guaranteed to be stable across different platforms or executions due to the complexity of floating-point math.
Sourcepub fn alpha(&self) -> i32
👎Deprecated: Use (*.a * 255.0).round().clamp(0, 255)
pub fn alpha(&self) -> i32
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.
Sourcepub fn opacity(&self) -> f64
👎Deprecated: Use .a.
pub fn opacity(&self) -> f64
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.
Sourcepub fn red(&self) -> i32
👎Deprecated: Use (*.r * 255.0).round().clamp(0, 255)
pub fn red(&self) -> i32
Use (*.r * 255.0).round().clamp(0, 255)
The red channel of this color in an 8 bit value.
Sourcepub fn green(&self) -> i32
👎Deprecated: Use (*.g * 255.0).round().clamp(0, 255)
pub fn green(&self) -> i32
Use (*.g * 255.0).round().clamp(0, 255)
The green channel of this color in an 8 bit value.
Sourcepub fn blue(&self) -> i32
👎Deprecated: Use (*.b * 255.0).round().clamp(0, 255)
pub fn blue(&self) -> i32
Use (*.b * 255.0).round().clamp(0, 255)
The blue channel of this color in an 8 bit value.
Sourcepub fn with_values(
&self,
alpha: Option<f64>,
red: Option<f64>,
green: Option<f64>,
blue: Option<f64>,
color_space: Option<ColorSpace>,
) -> Color
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)
}Sourcepub fn with_alpha(&self, a: i32) -> Color
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.
Sourcepub fn with_opacity(&self, opacity: f64) -> Color
👎Deprecated: Use .with_values() to avoid precision loss.
pub fn with_opacity(&self, opacity: f64) -> Color
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.
Sourcepub fn with_red(&self, r: i32) -> Color
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.
Sourcepub fn with_green(&self, g: i32) -> Color
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.
Sourcepub fn with_blue(&self, b: i32) -> Color
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.
Sourcepub fn compute_luminance(&self) -> f64
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.
Trait Implementations§
Source§impl Display for AnyColor
Dart’s Color.toString and a color subclass’s, which the inner Debug writes.
impl Display for AnyColor
Dart’s Color.toString and a color subclass’s, which the inner Debug writes.
Source§impl<T> From<ColorSwatch<T>> for AnyColor
impl<T> From<ColorSwatch<T>> for AnyColor
Source§fn from(swatch: ColorSwatch<T>) -> AnyColor
fn from(swatch: ColorSwatch<T>) -> AnyColor
Source§impl From<WidgetStateColor> for AnyColor
impl From<WidgetStateColor> for AnyColor
Source§fn from(color: WidgetStateColor) -> AnyColor
fn from(color: WidgetStateColor) -> AnyColor
Source§impl MaybeWidgetStateProperty<Color> for AnyColor
impl MaybeWidgetStateProperty<Color> for AnyColor
Source§fn as_widget_state_property(&self) -> Option<&dyn WidgetStateProperty<Color>>
fn as_widget_state_property(&self) -> Option<&dyn WidgetStateProperty<Color>>
Source§fn from_resolved(value: Color) -> AnyColor
fn from_resolved(value: Color) -> AnyColor
T is both).