Struct Color32

Source
#[repr(C)]
pub struct Color32(/* private fields */);
Expand description

This format is used for space-efficient color representation (32 bits).

Instead of manipulating this directly it is often better to first convert it to either Rgba or crate::Hsva.

Internally this uses 0-255 gamma space sRGBA color with premultiplied alpha. Alpha channel is in linear space.

Implementations§

Source§

impl Color32

Source

pub const TRANSPARENT: Color32

Source

pub const BLACK: Color32

Source

pub const DARK_GRAY: Color32

Source

pub const GRAY: Color32

Source

pub const LIGHT_GRAY: Color32

Source

pub const WHITE: Color32

Source

pub const BROWN: Color32

Source

pub const DARK_RED: Color32

Source

pub const RED: Color32

Source

pub const LIGHT_RED: Color32

Source

pub const YELLOW: Color32

Source

pub const LIGHT_YELLOW: Color32

Source

pub const KHAKI: Color32

Source

pub const DARK_GREEN: Color32

Source

pub const GREEN: Color32

Source

pub const LIGHT_GREEN: Color32

Source

pub const DARK_BLUE: Color32

Source

pub const BLUE: Color32

Source

pub const LIGHT_BLUE: Color32

Source

pub const GOLD: Color32

Source

pub const DEBUG_COLOR: Color32

Source

pub const TEMPORARY_COLOR: Color32

An ugly color that is planned to be replaced before making it to the screen.

Source

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

Source

pub const fn from_rgb_additive(r: u8, g: u8, b: u8) -> Color32

Source

pub const fn from_rgba_premultiplied(r: u8, g: u8, b: u8, a: u8) -> Color32

From sRGBA with premultiplied alpha.

Source

pub fn from_rgba_unmultiplied(r: u8, g: u8, b: u8, a: u8) -> Color32

From sRGBA WITHOUT premultiplied alpha.

Source

pub const fn from_gray(l: u8) -> Color32

Source

pub const fn from_black_alpha(a: u8) -> Color32

Source

pub fn from_white_alpha(a: u8) -> Color32

Source

pub const fn from_additive_luminance(l: u8) -> Color32

Source

pub const fn is_opaque(&self) -> bool

Source

pub const fn r(&self) -> u8

Source

pub const fn g(&self) -> u8

Source

pub const fn b(&self) -> u8

Source

pub const fn a(&self) -> u8

Source

pub fn to_opaque(self) -> Color32

Returns an opaque version of self

Source

pub const fn additive(self) -> Color32

Returns an additive version of self

Source

pub fn is_additive(self) -> bool

Is the alpha=0 ?

Source

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

Premultiplied RGBA

Source

pub const fn to_tuple(&self) -> (u8, u8, u8, u8)

Premultiplied RGBA

Source

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

Source

pub fn gamma_multiply(self, factor: f32) -> Color32

Multiply with 0.5 to make color half as opaque, perceptually.

Fast multiplication in gamma-space.

This is perceptually even, and faster that Self::linear_multiply.

Source

pub fn linear_multiply(self, factor: f32) -> Color32

Multiply with 0.5 to make color half as opaque in linear space.

This is using linear space, which is not perceptually even. You may want to use Self::gamma_multiply instead.

Source

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

Converts to floating point values in the range 0-1 without any gamma space conversion.

Use this with great care! In almost all cases, you want to convert to crate::Rgba instead in order to obtain linear space color values.

Trait Implementations§

Source§

impl Clone for Color32

Source§

fn clone(&self) -> Color32

Returns a duplicate 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 Color32

Source§

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

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

impl Default for Color32

Source§

fn default() -> Color32

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

impl From<Color32> for Hsva

Source§

fn from(srgba: Color32) -> Hsva

Converts to this type from the input type.
Source§

impl From<Color32> for HsvaGamma

Source§

fn from(srgba: Color32) -> HsvaGamma

Converts to this type from the input type.
Source§

impl From<Color32> for Rgba

Source§

fn from(srgba: Color32) -> Rgba

Converts to this type from the input type.
Source§

impl From<Hsva> for Color32

Source§

fn from(hsva: Hsva) -> Color32

Converts to this type from the input type.
Source§

impl From<HsvaGamma> for Color32

Source§

fn from(hsvag: HsvaGamma) -> Color32

Converts to this type from the input type.
Source§

impl From<Rgba> for Color32

Source§

fn from(rgba: Rgba) -> Color32

Converts to this type from the input type.
Source§

impl Hash for Color32

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 Index<usize> for Color32

Source§

type Output = u8

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &u8

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for Color32

Source§

fn index_mut(&mut self, index: usize) -> &mut u8

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl PartialEq for Color32

Source§

fn eq(&self, other: &Color32) -> 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 Zeroable for Color32

Source§

fn zeroed() -> Self

Source§

impl Copy for Color32

Source§

impl Eq for Color32

Source§

impl Pod for Color32

Source§

impl StructuralPartialEq for Color32

Auto Trait Implementations§

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> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
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<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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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> AnyBitPattern for T
where T: Pod,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> NoUninit for T
where T: Pod,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,