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

This represents an RGBA color

Fields§

§r: u8§g: u8§b: u8§a: u8

Implementations§

source§

impl Color

source

pub const fn with_red(&self, red: u8) -> Color

source

pub const fn with_green(&self, green: u8) -> Color

source

pub const fn with_blue(&self, blue: u8) -> Color

source

pub const fn with_alpha(&self, alpha: u8) -> Color

source§

impl Color

source

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

Converts 0.0..=1.0 to 0..=255 Values outside 0.0..=1.0 are clamped

source

pub const fn gray(value: u8) -> Color

Create a new color with red, green and blue set to value and alpha set to 255

source

pub const fn from_i32(value: i32) -> Color

Convert an i32 into a Color where bytes match the format [R,G,B,A]

source

pub fn from_hex(hex: &str) -> Result<Color, IndexedImageError>

source§

impl Color

source

pub fn as_array(&self) -> [u8; 4]

Split color into array in the format [R,G,B,A]

source

pub fn as_i32(&self) -> i32

Convert color to i32 in the format [R,G,B,A]

source

pub fn as_f32_array(&self) -> [f32; 4]

Convert color to f32 array in the format [R,G,B,A] where 0.0 = 0, and 1.0 = 255

source

pub fn blend(&self, other: Color) -> Color

source

pub fn brightness(&self) -> f32

ignores alpha

source

pub fn is_dark(&self) -> bool

source

pub fn is_transparent(&self) -> bool

source

pub fn darken(&self) -> Color

source

pub fn lighten(&self) -> Color

source

pub fn with_brightness(&self, amount: f32) -> Color

Copy color with brightness

source

pub fn with_saturate(&self, amount: f32) -> Color

De/saturate color by percentage Negative amount increases saturation

source

pub fn desaturate(&self) -> Color

Decrease saturation by 10%

source

pub fn saturate(&self) -> Color

Increase saturation by 10%

source

pub fn to_hex(&self) -> String

Returns color as hex format: #RRGGBBAA

source

pub fn mid(&self, other: &Color) -> Color

mid point between two colors

source

pub fn diff(&self, other: &Color) -> usize

diff between two colors

Trait Implementations§

source§

impl ChangeColors for Color

source§

fn with_saturate(&self, amount: f32) -> Color

De/saturate color by percentage Negative amount increases saturation So -0.1 is 10% more saturated
source§

fn with_brightness(&self, amount: f32) -> Color

Change brightness to amount So 1.1 is 10% brighter
source§

fn saturate(&self) -> Self
where Self: Sized,

Increase saturation by 10%
source§

fn desaturate(&self) -> Self
where Self: Sized,

Decrease saturation by 10%
source§

fn lighten(&self) -> Self
where Self: Sized,

source§

fn darken(&self) -> Self
where Self: Sized,

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<(), Error>

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

impl Default for Color

source§

fn default() -> Color

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

impl<'de> Deserialize<'de> for Color

source§

fn deserialize<__D>( __deserializer: __D ) -> Result<Color, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

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

impl From<[f32; 3]> for Color

source§

fn from(value: [f32; 3]) -> Color

Converts to this type from the input type.
source§

impl From<[f32; 4]> for Color

source§

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

Converts to this type from the input type.
source§

impl From<[u8; 3]> for Color

source§

fn from(value: [u8; 3]) -> Color

Converts to this type from the input type.
source§

impl From<[u8; 4]> for Color

source§

fn from(value: [u8; 4]) -> Color

Converts to this type from the input type.
source§

impl From<(f32, f32, f32)> for Color

source§

fn from(value: (f32, f32, f32)) -> Color

Converts to this type from the input type.
source§

impl From<(f32, f32, f32, f32)> for Color

source§

fn from(value: (f32, f32, f32, f32)) -> Color

Converts to this type from the input type.
source§

impl From<(u8, u8, u8)> for Color

source§

fn from(value: (u8, u8, u8)) -> Color

Converts to this type from the input type.
source§

impl From<(u8, u8, u8, u8)> for Color

source§

fn from(value: (u8, u8, u8, u8)) -> Color

Converts to this type from the input type.
source§

impl From<Color> for TextFormat

source§

fn from(color: Color) -> Self

Converts to this type from the input type.
source§

impl Hash for Color

source§

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

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 PartialEq 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>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

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

impl Tint for Color

source§

fn tint_add( &mut self, r_diff: isize, g_diff: isize, b_diff: isize, a_diff: isize )

Add to the RGBA channels by the amounts specified Read more
source§

fn tint_mul(&mut self, r_diff: f32, g_diff: f32, b_diff: f32, a_diff: f32)

Multiply the RGBA channels by the amounts specified 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> AnyToAny for T
where T: 'static,

source§

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

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> 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,

§

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>,

§

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>,

§

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