Struct thyme::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<Color> for Color

§

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

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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 StructuralEq for Color

source§

impl StructuralPartialEq for Color

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CallHasher for Twhere T: Hash + ?Sized,

§

default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64where H: Hash + ?Sized, B: BuildHasher,

source§

impl<T> Content for Twhere T: Copy,

§

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.
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<Q, K> Equivalent<K> for Qwhere 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<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,