Struct Color

Source
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

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 fn from_hex(hex: &str) -> Result<Color, IndexedImageError>

Source§

impl Color

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 ColorConversion<[f32; 4]> for Color

Source§

fn to_rgba(self) -> [f32; 4]

Source§

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

Source§

fn to_argb(self) -> [f32; 4]

Source§

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

Source§

impl ColorConversion<[u8; 4]> for Color

Source§

fn to_rgba(self) -> [u8; 4]

Source§

fn to_argb(self) -> [u8; 4]

Source§

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

Source§

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

Source§

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

Source§

fn to_rgba(self) -> (f32, f32, f32, f32)

Source§

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

Source§

fn to_argb(self) -> (f32, f32, f32, f32)

Source§

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

Source§

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

Source§

fn to_rgba(self) -> (u8, u8, u8, u8)

Source§

fn to_argb(self) -> (u8, u8, u8, u8)

Source§

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

Source§

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

Source§

impl ColorConversion<u32> for Color

Source§

fn to_rgba(self) -> u32

Source§

fn from_rgba(value: u32) -> Color

Source§

fn to_argb(self) -> u32

Source§

fn from_argb(value: u32) -> Color

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

Black

Source§

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

Source§

fn deserialize<D>(d: 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<Color> for TextFormat

Source§

fn from(color: Color) -> TextFormat

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 OpaqueColorConversion<[f32; 3]> for Color

Source§

fn to_rgb(self) -> [f32; 3]

Source§

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

Sets alpha to 255
Source§

impl OpaqueColorConversion<[u8; 3]> for Color

Source§

fn to_rgb(self) -> [u8; 3]

Source§

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

Sets alpha to 255
Source§

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

Source§

fn to_rgb(self) -> (f32, f32, f32)

Source§

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

Sets alpha to 255
Source§

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

Source§

fn to_rgb(self) -> (u8, u8, u8)

Source§

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

Sets alpha to 255
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>( &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> 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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

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

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

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

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSync for T
where T: Sync,