pub struct Color { /* private fields */ }Expand description
The Color which is used for a Pixel.
You can create a Color as normal RGB or add an alpha channel to it.
§Example
§RGB Color
let color: Color = "ff0f00".parse().unwrap();
assert_eq!(color, Color::rgb(0xff, 0x0f, 0x00));
assert!(color.is_rgb())§RGBA Color
let color: Color = "ff0f00aa".parse().unwrap();
assert_eq!(color, Color::rgba(0xff, 0x0f, 0x00, 0xaa));
assert!(color.is_rgba())Implementations§
Source§impl Color
impl Color
Sourcepub fn rgb(r: u8, g: u8, b: u8) -> Color
pub fn rgb(r: u8, g: u8, b: u8) -> Color
Creates a new Color without an alpha channel.
let color = Color::rgb(0xff, 0x0f, 0x00);
assert!(color.is_rgb());
assert!(!color.is_rgba());Sourcepub fn rgba(r: u8, g: u8, b: u8, a: u8) -> Color
pub fn rgba(r: u8, g: u8, b: u8, a: u8) -> Color
Creates a new Color with an alpha channel.
let color = Color::rgba(0xff, 0x0f, 0x00, 0xaa);
assert!(color.is_rgba());
assert!(!color.is_rgb());Sourcepub fn rgb_values(&self) -> (u8, u8, u8)
pub fn rgb_values(&self) -> (u8, u8, u8)
Returns the rgb values of this Color.
assert_eq!((0xff, 0x0f, 0x00), Color::rgb(0xff, 0x0f, 0x00).rgb_values());Sourcepub fn rgba_values(&self) -> (u8, u8, u8, Option<u8>)
pub fn rgba_values(&self) -> (u8, u8, u8, Option<u8>)
Returns the rgb and the alpha value of this Color.
assert_eq!((0xff, 0x0f, 0x00, None), Color::rgb(0xff, 0x0f, 0x00).rgba_values());
assert_eq!((0xff, 0x0f, 0x00, Some(0xaa)), Color::rgba(0xff, 0x0f, 0x00, 0xaa).rgba_values());Trait Implementations§
impl Copy for Color
impl StructuralPartialEq for Color
Auto Trait Implementations§
impl Freeze for Color
impl RefUnwindSafe for Color
impl Send for Color
impl Sync for Color
impl Unpin for Color
impl UnwindSafe for Color
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