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

source

pub const BLACK: Self = _

Convenience constant for solid black.

source

pub const WHITE: Self = _

Convenience constant for solid white.

source

pub const TRANSPARENT: Self = _

Convenience constant for full transparency.

source

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.

source

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

source

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.

source

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

Return the channels as an array of f32 in [r, g, b, a] order.

source

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

Return the channels as an array of u8 in [r, g, b, a] order.

source

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

source

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.

source

pub const fn to_bits(self) -> u32

Return the bits of the color as a u32. These are in “0xAABBGGRR” format, that is, little-endian RGBA with 8 bits per channel.

Trait Implementations§

source§

impl Clone for ImColor32

source§

fn clone(&self) -> ImColor32

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

impl Debug for ImColor32

source§

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

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

impl Default for ImColor32

source§

fn default() -> Self

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

impl Deref for ImColor32

source§

type Target = ImColor32Fields

The resulting type after dereferencing.
source§

fn deref(&self) -> &ImColor32Fields

Dereferences the value.
source§

impl DerefMut for ImColor32

source§

fn deref_mut(&mut self) -> &mut ImColor32Fields

Mutably dereferences the value.
source§

impl From<[f32; 3]> for ImColor32

source§

fn from(v: [f32; 3]) -> Self

Converts to this type from the input type.
source§

impl From<[f32; 4]> for ImColor32

source§

fn from(v: [f32; 4]) -> Self

Converts to this type from the input type.
source§

impl From<(f32, f32, f32)> for ImColor32

source§

fn from(v: (f32, f32, f32)) -> Self

Converts to this type from the input type.
source§

impl From<(f32, f32, f32, f32)> for ImColor32

source§

fn from(v: (f32, f32, f32, f32)) -> Self

Converts to this type from the input type.
source§

impl From<ImColor32> for [f32; 4]

source§

fn from(v: ImColor32) -> Self

Converts to this type from the input type.
source§

impl From<ImColor32> for (f32, f32, f32, f32)

source§

fn from(color: ImColor32) -> Self

Converts to this type from the input type.
source§

impl From<ImColor32> for u32

source§

fn from(color: ImColor32) -> Self

Converts to this type from the input type.
source§

impl From<u32> for ImColor32

source§

fn from(color: u32) -> Self

Converts to this type from the input type.
source§

impl Hash for ImColor32

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

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 Ord for ImColor32

source§

fn cmp(&self, other: &ImColor32) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for ImColor32

source§

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

source§

fn partial_cmp(&self, other: &ImColor32) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for ImColor32

source§

impl Eq for ImColor32

source§

impl StructuralPartialEq for ImColor32

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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