Skip to main content

Color

Struct Color 

Source
pub struct Color {
    pub a: u8,
    pub r: u8,
    pub g: u8,
    pub b: u8,
}
Expand description

An ARGB color.

Fields§

§a: u8

The Alpha component of the color.

§r: u8

The Red component of the color.

§g: u8

The Green component of the color.

§b: u8

The Blue component of the color.

Implementations§

Source§

impl Color

Source

pub const fn new(a: u8, r: u8, g: u8, b: u8) -> Self

Initializes a new instance of the Color struct.

Source

pub const fn from_argb(a: u8, r: u8, g: u8, b: u8) -> Color

Creates a Color from alpha, red, green and blue components.

Source

pub const fn from_rgb(r: u8, g: u8, b: u8) -> Color

Creates an opaque Color from red, green and blue components.

Source

pub const fn from_uint32(value: u32) -> Color

Creates a Color from an integer in 0xAARRGGBB layout.

Source

pub fn parse(s: &str) -> Result<Color, FormatError>

Parses a color string: #rgb, #argb, #rrggbb, #aarrggbb, rgb()/rgba(), hsl()/hsla(), hsv()/hsva() or a known color name.

Source

pub fn try_parse(s: &str) -> Option<Color>

Parses a color string, returning None when it is not a valid color.

Source

pub fn to_string_format( &self, format: Option<&str>, format_provider: Option<&CultureInfo>, ) -> Result<String, FormatError>

Returns the string representation of the color using a format specifier.

Supported format specifiers:

  • X: XAML hex with alpha, #AARRGGBB
  • x: hex without alpha, #RRGGBB
  • H: HTML/CSS hex with alpha, #RRGGBBAA
  • R / r: CSS rgba(r, g, b, a) / rgb(r, g, b)
  • R% / r%: CSS rgba(r%, g%, b%, a%) / rgb(r%, g%, b%)
  • L, l, L%, l%: converted to HSL and formatted as such
  • V, v, V%, v%: converted to HSV and formatted as such

A null or empty format is the same as to_string(). Any other format is an error. format_provider is ignored: color formatting is culture-invariant.

Source

pub const fn to_uint32(&self) -> u32

Returns the integer representation of the color in 0xAARRGGBB layout.

Source

pub fn to_hsl(&self) -> HslColor

Returns the HSL color model equivalent of this RGB color.

Source

pub fn to_hsv(&self) -> HsvColor

Returns the HSV color model equivalent of this RGB color.

Source

pub const fn equals(&self, other: Color) -> bool

Check if two colors are equal.

Source

pub fn rgb_to_hsl(red: u8, green: u8, blue: u8, alpha: u8) -> HslColor

Converts the given RGBA color component values to their HSL color equivalent.

Source

pub fn normalized_rgb_to_hsl(r: f64, g: f64, b: f64, a: f64) -> HslColor

Converts the given RGBA color component values to their HSL color equivalent. Warning: no bounds checks or clamping is done on the input component values; they are assumed to be within the 0..1 range. The result is not clamped either.

Source

pub fn rgb_to_hsv(red: u8, green: u8, blue: u8, alpha: u8) -> HsvColor

Converts the given RGBA color component values to their HSV color equivalent.

Source

pub fn normalized_rgb_to_hsv(r: f64, g: f64, b: f64, a: f64) -> HsvColor

Converts the given RGBA color component values to their HSV color equivalent. Warning: no bounds checks or clamping is done on the input component values; they are assumed to be within the 0..1 range. The result is not clamped either.

Trait Implementations§

Source§

impl BatchValue for Color

Source§

fn write_to(&self, out: &mut Vec<u8>)

Source§

fn read_from(input: &mut BatchValueReader<'_>) -> Self

Source§

impl Clone for Color

Source§

fn clone(&self) -> Self

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 Copy for Color

Source§

impl Debug for Color

Source§

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

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

impl Default for Color

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Color

Writes the known color name when there is one, #aarrggbb (lower-case) otherwise.

Source§

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

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

impl Eq for Color

Source§

impl ExpressionVariantValue for Color

Source§

const FFI_VARIANT_TYPE: Option<VariantType>

The variant type a foreign function parameter of this type is matched against, or None when the type cannot be a foreign function parameter.
Source§

fn try_from_variant(v: &ExpressionVariant) -> Option<Self>

Source§

fn into_variant(self) -> ExpressionVariant

Source§

impl From<Color> for ExpressionVariant

Source§

fn from(value: Color) -> ExpressionVariant

Converts to this type from the input type.
Source§

impl From<HslColor> for Color

Converts the HSL color to RGB (an explicit conversion in the reference API).

Source§

fn from(hsl_color: HslColor) -> Color

Converts to this type from the input type.
Source§

impl From<HsvColor> for Color

Converts the HSV color to RGB (an explicit conversion in the reference API).

Source§

fn from(hsv_color: HsvColor) -> Color

Converts to this type from the input type.
Source§

impl FromStr for Color

Source§

type Err = FormatError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, FormatError>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Color

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl IInterpolator<Color> for ColorInterpolator

Source§

fn interpolate(&self, from: Color, to: Color, progress: f32) -> Color

Source§

impl MarkupTyped for Color

Source§

const MARKUP: &'static MarkupType

The markup metadata of the type.
Source§

impl PartialEq for Color

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl ServerPropertyValue for Color

Source§

fn differs(&self, other: &Self) -> bool

Source§

fn default_equals(&self, other: &Self) -> bool

Source§

impl StructuralPartialEq for Color

Source§

impl Transition<Color> for ColorTransition

Source§

fn do_transition( this: &Self, progress: Rc<dyn IObservable<f64>>, old_value: Color, new_value: Color, ) -> Rc<dyn IObservable<Color>>

Creates the observable of the values of the transition from old_value to new_value, driven by progress (from 0 to 1).

Auto Trait Implementations§

§

impl Freeze for Color

§

impl RefUnwindSafe for Color

§

impl Send for Color

§

impl Sync for Color

§

impl Unpin for Color

§

impl UnsafeUnpin for Color

§

impl UnwindSafe for Color

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> AnyValue for T
where T: PartialEq + 'static,

Source§

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

Source§

fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool

Source§

fn any_value_type_name(&self) -> &'static str

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> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). 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> 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> PropertyValue for T
where T: Clone + PartialEq + 'static,

Source§

impl<T> ResourceKeyObject for T
where T: Eq + Hash + 'static,

Source§

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

Source§

fn dyn_eq(&self, other: &(dyn ResourceKeyObject + 'static)) -> bool

Source§

fn dyn_hash(&self, state: &mut dyn Hasher)

Source§

fn key_type_name(&self) -> &'static str

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.