#[repr(C)]pub struct Color32 {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}
Expand description
A 32 bit color struct! This is often directly used by StereoKit data structures, and so is often necessary for setting texture data, or mesh data. Note that the Color type implicitly converts to Color32, so you can use the static methods there to create Color32 values!
It’s generally best to avoid doing math on 32-bit color values, as they lack the precision necessary to create results. It’s best to think of a Color32 as an optimized end stage format of a color. https://stereokit.net/Pages/StereoKit/Color32.html
see also Color128
§Examples
use stereokit_rust::util::{Color32, named_colors, Color128};
// Cyan from different sources:
let color_cyan1 = named_colors::CYAN;
let color_cyan2: Color32 = [0, 255, 255, 255].into();
let color_cyan3: Color32 = Color128 { r: 0.0, g: 1.0, b: 1.0, a: 1.0 }.into();
let color_cyan4 = Color32 {r: 0, g: 255, b: 255, a: 255};
let color_cyan5 = Color32::new (0, 255, 255, 255);
let color_cyan6 = Color32::rgba(0, 255, 255, 255);
let color_cyan7 = Color32::rgb (0, 255, 255 );
let color_cyan8 = Color32::hex (0x00FFFFFF);
assert_eq!(color_cyan1, color_cyan8);
Fields§
§r: u8
§g: u8
§b: u8
§a: u8
Implementations§
Source§impl Color32
impl Color32
Sourcepub const BLACK_TRANSPARENT: Color32
pub const BLACK_TRANSPARENT: Color32
transparent black color.
Sourcepub const fn new(r: u8, g: u8, b: u8, a: u8) -> Self
pub const fn new(r: u8, g: u8, b: u8, a: u8) -> Self
Constructs a 32-bit color from bytes! You may also be interested in Color32::hex. https://stereokit.net/Pages/StereoKit/Color32/Color32.html
Sourcepub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self
pub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self
Constructs a 32-bit color from bytes! You may also be interested in Color32::hex. https://stereokit.net/Pages/StereoKit/Color32/Color32.html
Sourcepub const fn rgb(r: u8, g: u8, b: u8) -> Self
pub const fn rgb(r: u8, g: u8, b: u8) -> Self
Constructs a 32-bit color from bytes! You may also be interested in Color32::hex. https://stereokit.net/Pages/StereoKit/Color32/Color32.html
Sourcepub const fn new_rgb(r: u8, g: u8, b: u8) -> Self
👎Deprecated: Use Color32::rgb instead
pub const fn new_rgb(r: u8, g: u8, b: u8) -> Self
Constructs a 32-bit color from bytes! You may also be interested in Color32::hex. a is set to 255 ! https://stereokit.net/Pages/StereoKit/Color32/Color32.html
Sourcepub fn hex(hex_value: u32) -> Self
pub fn hex(hex_value: u32) -> Self
Create a color from an integer based hex value! This can make it easier to copy over colors from the web. This isn’t a string function though, so you’ll need to fill it out the whole way. Ex: Color.Hex(0x0000FFFF) would be RGBA(0,0,255,255). https://stereokit.net/Pages/StereoKit/Color32/Hex.html
Trait Implementations§
impl Copy 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.