Struct arcdps_imgui::color::ImColor32
source · pub struct ImColor32(/* private fields */);
Expand description
Wraps u32 that represents a packed RGBA color. Mostly used by types in the
low level custom drawing API, such as DrawListMut
.
The bits of a color are in “0xAABBGGRR
” format (e.g. RGBA as little endian
bytes). For clarity: we don’t support an equivalent to the
IMGUI_USE_BGRA_PACKED_COLOR
define.
This used to be named ImColor32
, but was renamed to avoid confusion with
the type with that name in the C++ API (which uses 32 bits per channel).
While it doesn’t provide methods to access the fields, they can be accessed
via the Deref
/DerefMut
impls it provides targeting
imgui::color::ImColor32Fields
, which has
no other meaningful uses.
§Example
let mut c = arcdps_imgui::ImColor32::from_rgba(0x80, 0xc0, 0x40, 0xff);
assert_eq!(c.to_bits(), 0xff_40_c0_80); // Note: 0xAA_BB_GG_RR
// Field access
assert_eq!(c.r, 0x80);
assert_eq!(c.g, 0xc0);
assert_eq!(c.b, 0x40);
assert_eq!(c.a, 0xff);
c.b = 0xbb;
assert_eq!(c.to_bits(), 0xff_bb_c0_80);
Implementations§
source§impl ImColor32
impl ImColor32
sourcepub const TRANSPARENT: Self = _
pub const TRANSPARENT: Self = _
Convenience constant for full transparency.
sourcepub const fn from_rgba(r: u8, g: u8, b: u8, a: u8) -> Self
pub const fn from_rgba(r: u8, g: u8, b: u8, a: u8) -> Self
Construct a color from 4 single-byte u8
channel values, which should
be between 0 and 255.
sourcepub const fn from_rgb(r: u8, g: u8, b: u8) -> Self
pub const fn from_rgb(r: u8, g: u8, b: u8) -> Self
Construct a fully opaque color from 3 single-byte u8
channel values.
Same as Self::from_rgba
with a == 255
sourcepub fn from_rgba_f32s(r: f32, g: f32, b: f32, a: f32) -> Self
pub fn from_rgba_f32s(r: f32, g: f32, b: f32, a: f32) -> Self
Construct a fully opaque color from 4 f32
channel values in the range
0.0 ..= 1.0
(values outside this range are clamped to it, with NaN
mapped to 0.0).
Note: No alpha premultiplication is done, so your input should be have premultiplied alpha if needed.
sourcepub fn to_rgba_f32s(self) -> [f32; 4]
pub fn to_rgba_f32s(self) -> [f32; 4]
Return the channels as an array of f32 in [r, g, b, a]
order.
sourcepub fn from_rgb_f32s(r: f32, g: f32, b: f32) -> Self
pub fn from_rgb_f32s(r: f32, g: f32, b: f32) -> Self
Equivalent to Self::from_rgba_f32s
, but with an alpha of 1.0 (e.g.
opaque).
sourcepub const fn from_bits(u: u32) -> Self
pub const fn from_bits(u: u32) -> Self
Construct a color from the u32
that makes up the bits in 0xAABBGGRR
format.
Specifically, this takes the RGBA values as a little-endian u32 with 8 bits per channel.
Note that ImColor32::from_rgba
may be a bit easier to use.
Trait Implementations§
source§impl Deref for ImColor32
impl Deref for ImColor32
§type Target = ImColor32Fields
type Target = ImColor32Fields
source§fn deref(&self) -> &ImColor32Fields
fn deref(&self) -> &ImColor32Fields
source§impl DerefMut for ImColor32
impl DerefMut for ImColor32
source§fn deref_mut(&mut self) -> &mut ImColor32Fields
fn deref_mut(&mut self) -> &mut ImColor32Fields
source§impl Ord for ImColor32
impl Ord for ImColor32
source§impl PartialEq for ImColor32
impl PartialEq for ImColor32
source§impl PartialOrd for ImColor32
impl PartialOrd for ImColor32
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more