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
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)
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
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
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_srgba_unmultiplied(&self) -> [u8; 4]
pub fn gamma_multiply(self, factor: f32) -> Color32
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
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]
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<'de> Deserialize<'de> for Color32
impl<'de> Deserialize<'de> for Color32
§fn deserialize<__D>(
__deserializer: __D
) -> Result<Color32, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Color32, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl Serialize for Color32
impl Serialize for Color32
§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Copy for Color32
impl Eq for Color32
impl Pod for Color32
impl StructuralEq for Color32
impl StructuralPartialEq for Color32
Auto Trait Implementations§
impl RefUnwindSafe for Color32
impl Send for Color32
impl Sync for Color32
impl Unpin for Color32
impl UnwindSafe for Color32
Blanket Implementations§
§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
§type Bits = T
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
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self
.