pub struct Rgba {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}Expand description
An sRGB color with alpha, stored as four u8 components.
All values are in the sRGB color space. When parsing hex strings, alpha defaults to 255 (fully opaque) if omitted.
§Hex Format
Supports parsing from and displaying as hex strings:
#RGB/RGB– 3-digit shorthand (each digit doubled:#abc->#aabbcc)#RGBA/RGBA– 4-digit shorthand with alpha#RRGGBB/RRGGBB– standard 6-digit hex#RRGGBBAA/RRGGBBAA– 8-digit hex with alpha
Display outputs lowercase hex: #rrggbb when alpha is 255,
#rrggbbaa otherwise.
§Examples
use native_theme::Rgba;
// Create an opaque color
let blue = Rgba::rgb(0, 120, 215);
assert_eq!(blue.a, 255);
// Parse from a hex string
let parsed: Rgba = "#3daee9".parse().unwrap();
assert_eq!(parsed.r, 61);
// Convert to f32 array for toolkit interop
let arr = Rgba::rgb(255, 0, 0).to_f32_array();
assert_eq!(arr, [1.0, 0.0, 0.0, 1.0]);Fields§
§r: u8Red component (0-255).
g: u8Green component (0-255).
b: u8Blue component (0-255).
a: u8Alpha component (0-255, where 255 is fully opaque).
Implementations§
Source§impl Rgba
impl Rgba
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Rgba
impl<'de> Deserialize<'de> for Rgba
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl Copy for Rgba
impl Eq for Rgba
impl StructuralPartialEq for Rgba
Auto Trait Implementations§
impl Freeze for Rgba
impl RefUnwindSafe for Rgba
impl Send for Rgba
impl Sync for Rgba
impl Unpin for Rgba
impl UnsafeUnpin for Rgba
impl UnwindSafe for Rgba
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
Mutably borrows from an owned value. Read more