#[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.
The special value of alpha=0 means the color is to be treated as an additive color.
Implementations§
source§impl Color32
impl Color32
pub const TRANSPARENT: Color32 = _
pub const BLACK: Color32 = _
pub const DARK_GRAY: Color32 = _
pub const GRAY: Color32 = _
pub const LIGHT_GRAY: Color32 = _
pub const WHITE: Color32 = _
pub const BROWN: Color32 = _
pub const DARK_RED: Color32 = _
pub const RED: Color32 = _
pub const LIGHT_RED: Color32 = _
pub const YELLOW: Color32 = _
pub const ORANGE: Color32 = _
pub const LIGHT_YELLOW: Color32 = _
pub const KHAKI: Color32 = _
pub const DARK_GREEN: Color32 = _
pub const GREEN: Color32 = _
pub const LIGHT_GREEN: Color32 = _
pub const DARK_BLUE: Color32 = _
pub const BLUE: Color32 = _
pub const LIGHT_BLUE: Color32 = _
pub const GOLD: Color32 = _
pub const DEBUG_COLOR: Color32 = _
sourcepub const PLACEHOLDER: Color32 = _
pub const PLACEHOLDER: Color32 = _
An ugly color that is planned to be replaced before making it to the screen.
This is an invalid color, in that it does not correspond to a valid multiplied color, nor to an additive color.
This is used as a special color key, i.e. often taken to mean “no color”.
pub const TEMPORARY_COLOR: Color32 = Self::PLACEHOLDER
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
sourcepub 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.
sourcepub 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
sourcepub fn is_additive(self) -> bool
pub fn is_additive(self) -> bool
Is the alpha=0 ?
pub fn to_srgba_unmultiplied(&self) -> [u8; 4]
sourcepub 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
.
sourcepub 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 likely want to use Self::gamma_multiply
instead.
sourcepub 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.
sourcepub fn lerp_to_gamma(&self, other: Color32, t: f32) -> Color32
pub fn lerp_to_gamma(&self, other: Color32, t: f32) -> Color32
Lerp this color towards other
by t
in gamma space.
source§impl Color32
impl Color32
sourcepub fn from_hex(hex: &str) -> Result<Color32, ParseHexColorError>
pub fn from_hex(hex: &str) -> Result<Color32, ParseHexColorError>
Parses a color from a hex string.
Supports the 3, 4, 6, and 8-digit formats, according to the specification in https://drafts.csswg.org/css-color-4/#hex-color
To parse hex colors from string literals with compile-time checking, use the macro
crate::hex_color!
instead.
§Example
use ecolor::Color32;
assert_eq!(Ok(Color32::RED), Color32::from_hex("#ff0000"));
assert_eq!(Ok(Color32::GREEN), Color32::from_hex("#00ff00ff"));
assert_eq!(Ok(Color32::BLUE), Color32::from_hex("#00f"));
assert_eq!(Ok(Color32::TRANSPARENT), Color32::from_hex("#0000"));
§Errors
Returns an error if the string doesn’t start with the hash #
character, if the remaining
length does not correspond to one of the standard formats (3, 4, 6, or 8), if it contains
non-hex characters.
sourcepub fn to_hex(&self) -> String
pub fn to_hex(&self) -> String
Formats the color as a hex string.
§Example
use ecolor::Color32;
assert_eq!(Color32::RED.to_hex(), "#ff0000ff");
assert_eq!(Color32::GREEN.to_hex(), "#00ff00ff");
assert_eq!(Color32::BLUE.to_hex(), "#0000ffff");
assert_eq!(Color32::TRANSPARENT.to_hex(), "#00000000");
Uses the 8-digit format described in https://drafts.csswg.org/css-color-4/#hex-color,
as that is the only format that is lossless.
For other formats, see HexColor
.
Trait Implementations§
source§impl ColorInterop for Color32
impl ColorInterop for Color32
source§impl<'de> Deserialize<'de> for Color32
impl<'de> Deserialize<'de> for Color32
source§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>,
source§impl From<PremultipliedAlpha<EncodedSrgb<f32>>> for Color32
impl From<PremultipliedAlpha<EncodedSrgb<f32>>> for Color32
source§fn from(srgba: PremultipliedAlpha<EncodedSrgb<f32>>) -> Color32
fn from(srgba: PremultipliedAlpha<EncodedSrgb<f32>>) -> Color32
source§impl From<PremultipliedAlpha<EncodedSrgb>> for Color32
impl From<PremultipliedAlpha<EncodedSrgb>> for Color32
source§fn from(srgba: PremultipliedAlpha<EncodedSrgb>) -> Color32
fn from(srgba: PremultipliedAlpha<EncodedSrgb>) -> Color32
source§impl Serialize for Color32
impl Serialize for Color32
source§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 StructuralPartialEq for Color32
Auto Trait Implementations§
impl Freeze for Color32
impl RefUnwindSafe for Color32
impl Send for Color32
impl Sync for Color32
impl Unpin for Color32
impl UnwindSafe for Color32
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
source§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
.source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self
.source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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