Struct Color

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

A Color with red, green, blue, and alpha components, with each component stored as a u8.

Colors can be deserialized from strings consisting of either one of the predefined names: white, black, red, green, blue, cyan, yellow, or magenta. Or, the # character followed by a hex color code. The hex code can either be 8, 6, 4 or 3 digits long.

  • 8 digits - each set of 2 digits specifies one color component - red, green, blue, then alpha
  • 6 digits - each set of 2 digits specifies one color component - red, green, and blue. Alpha is assumed to be the maximum value of FF.
  • 4 digits - each single digit specifies one color component - red, green, blue, then alpha, with half precision.
  • 3 digits - each single digit specifies one color component - red, green, then blue. Alpha ia assumed to be the maximum value of F. For the 4 and 3 digit variants - each component has one of 16 possible values. The value is multiplied by 17 to determine the corresponding full precision value. For example, 0 maps to 00, F maps to FF, and 8 maps to 88.

Fields§

§r: u8

The red component

§g: u8

The green component

§b: u8

The blue component

§a: u8

The alpha or transparency component

Implementations§

Source§

impl Color

Source

pub fn white() -> Self

The color white. #FFFFFF or #FFF in the theme

Source

pub fn black() -> Self

The color black. #000000 or #000 in the theme

Source

pub fn red() -> Self

The color red. #FF0000 or #F00 in the theme

Source

pub fn green() -> Self

The color green. #00FF00 or #0F0 in the theme

Source

pub fn blue() -> Self

The color blue. #0000FF or #00F in the theme

Source

pub fn cyan() -> Self

The color cyan. #00FFFF or #0FF in the theme

Source

pub fn yellow() -> Self

The color yellow. #FFFF00 or #FF0 in the theme

Source

pub fn magenta() -> Self

The color magenta or purple. #FF00FF or #F0F in the theme

Source

pub fn grey() -> Self

The color gray or grey. #888888 or #888 in the theme

Source

pub fn parse_str(value: &str) -> Option<Color>

Attempts to parse a Color from the specified value string. Returns None if it cannot be parsed. See the main Color serialization rules.

Trait Implementations§

Source§

impl Clone for Color

Source§

fn clone(&self) -> Color

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
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<'de> Deserialize<'de> for Color

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Color, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<[f32; 4]> for Color

Source§

fn from(value: [f32; 4]) -> Self

Converts to this type from the input type.
Source§

impl From<Color> for [f32; 4]

Source§

fn from(c: Color) -> [f32; 4]

Converts to this type from the input type.
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 Mul for Color

Source§

type Output = Color

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl PartialEq for Color

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Color

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Color

Source§

impl Eq for Color

Source§

impl StructuralPartialEq for Color

Auto Trait Implementations§

§

impl Freeze for Color

§

impl RefUnwindSafe for Color

§

impl Send for Color

§

impl Sync for Color

§

impl Unpin 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> 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> 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> Content for T
where T: Copy,

Source§

type Owned = T

A type that holds a sized version of the content.
Source§

unsafe fn read<F, E>(size: usize, f: F) -> Result<T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

Prepares an output buffer, then turns this buffer into an Owned. User-provided closure F must only write to and not read from &mut Self.
Source§

fn get_elements_size() -> usize

Returns the size of each element.
Source§

fn to_void_ptr(&self) -> *const ()

Produces a pointer to the data.
Source§

fn ref_from_ptr<'a>(ptr: *mut (), size: usize) -> Option<*mut T>

Builds a pointer to this type from a raw pointer.
Source§

fn is_size_suitable(size: usize) -> bool

Returns true if the size is suitable to store a type like this.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,