Struct egui::Color32

pub struct Color32(_);
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§

§

impl Color32

pub const TRANSPARENT: Color32 = Color32::from_rgba_premultiplied(0, 0, 0, 0)

pub const BLACK: Color32 = Color32::from_rgb(0, 0, 0)

pub const DARK_GRAY: Color32 = Color32::from_rgb(96, 96, 96)

pub const GRAY: Color32 = Color32::from_rgb(160, 160, 160)

pub const LIGHT_GRAY: Color32 = Color32::from_rgb(220, 220, 220)

pub const WHITE: Color32 = Color32::from_rgb(255, 255, 255)

pub const BROWN: Color32 = Color32::from_rgb(165, 42, 42)

pub const DARK_RED: Color32 = Color32::from_rgb(139, 0, 0)

pub const RED: Color32 = Color32::from_rgb(255, 0, 0)

pub const LIGHT_RED: Color32 = Color32::from_rgb(255, 128, 128)

pub const YELLOW: Color32 = Color32::from_rgb(255, 255, 0)

pub const LIGHT_YELLOW: Color32 = Color32::from_rgb(255, 255, 224)

pub const KHAKI: Color32 = Color32::from_rgb(240, 230, 140)

pub const DARK_GREEN: Color32 = Color32::from_rgb(0, 100, 0)

pub const GREEN: Color32 = Color32::from_rgb(0, 255, 0)

pub const LIGHT_GREEN: Color32 = Color32::from_rgb(144, 238, 144)

pub const DARK_BLUE: Color32 = Color32::from_rgb(0, 0, 139)

pub const BLUE: Color32 = Color32::from_rgb(0, 0, 255)

pub const LIGHT_BLUE: Color32 = Color32::from_rgb(173, 216, 230)

pub const GOLD: Color32 = Color32::from_rgb(255, 215, 0)

pub const DEBUG_COLOR: Color32 = Color32::from_rgba_premultiplied(0, 200, 0, 128)

pub const TEMPORARY_COLOR: Color32 = Color32::from_rgb(64, 254, 0)

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

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

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

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

From sRGBA with premultiplied alpha.

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

From sRGBA WITHOUT premultiplied alpha.

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

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

pub fn from_white_alpha(a: u8) -> Color32

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

pub const fn is_opaque(&self) -> bool

pub const fn r(&self) -> u8

pub const fn g(&self) -> u8

pub const fn b(&self) -> u8

pub const fn a(&self) -> u8

pub fn to_opaque(self) -> Color32

Returns an opaque version of self

pub const fn additive(self) -> Color32

Returns an additive version of self

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

Premultiplied RGBA

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

Premultiplied RGBA

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

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.

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.

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§

§

impl Clone for Color32

§

fn clone(&self) -> Color32

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
§

impl ColorInterop for Color32

§

type CintTy = PremultipliedAlpha<EncodedSrgb<u8>>

§

fn from_cint(col: Self::CintTy) -> Self

Convert self into its canonical cint type.
§

fn into_cint(self) -> Self::CintTy

Create a Self from its canonical cint type.
§

impl Debug for Color32

§

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

Formats the value using the given formatter. Read more
§

impl Default for Color32

§

fn default() -> Color32

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

impl<'de> Deserialize<'de> for Color32

§

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

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

impl From<Alpha<EncodedSrgb<u8>>> for Color32

§

fn from(srgba: Alpha<EncodedSrgb<u8>>) -> Color32

Converts to this type from the input type.
§

impl From<Color32> for Rgba

§

fn from(srgba: Color32) -> Rgba

Converts to this type from the input type.
§

impl From<Hsva> for Color32

§

fn from(hsva: Hsva) -> Color32

Converts to this type from the input type.
§

impl From<HsvaGamma> for Color32

§

fn from(hsvag: HsvaGamma) -> Color32

Converts to this type from the input type.
§

impl From<PremultipliedAlpha<EncodedSrgb<f32>>> for Color32

§

fn from(srgba: PremultipliedAlpha<EncodedSrgb<f32>>) -> Color32

Converts to this type from the input type.
§

impl From<PremultipliedAlpha<EncodedSrgb<u8>>> for Color32

§

fn from(srgba: PremultipliedAlpha<EncodedSrgb<u8>>) -> Color32

Converts to this type from the input type.
§

impl From<Rgba> for Color32

§

fn from(rgba: Rgba) -> Color32

Converts to this type from the input type.
§

impl Hash for Color32

§

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
§

impl Index<usize> for Color32

§

type Output = u8

The returned type after indexing.
§

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

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

impl IndexMut<usize> for Color32

§

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

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

impl PartialEq<Color32> for Color32

§

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

impl Serialize for Color32

§

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
§

impl Zeroable for Color32

§

fn zeroed() -> Self

§

impl Copy for Color32

§

impl Eq for Color32

§

impl Pod for Color32

§

impl StructuralEq for Color32

§

impl StructuralPartialEq for Color32

Auto Trait Implementations§

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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
§

impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,

§

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

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

const: unstable · 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 Twhere
U: From<T>,

const: unstable · 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.
const: unstable · 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.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
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
§

impl<T> AnyBitPattern for Twhere
T: Pod,

source§

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

§

impl<T> NoUninit for Twhere
T: Pod,

source§

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