Struct buffer_graphics_lib::prelude::Color
source · pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}
Expand description
This represents an RGBA color
Fields§
§r: u8
§g: u8
§b: u8
§a: u8
Implementations§
source§impl Color
impl Color
sourcepub const fn new(r: u8, g: u8, b: u8, a: u8) -> Color
pub const fn new(r: u8, g: u8, b: u8, a: u8) -> Color
Converts 0.0..=1.0 to 0..=255 Values outside 0.0..=1.0 are clamped
sourcepub const fn gray(value: u8) -> Color
pub const fn gray(value: u8) -> Color
Create a new color with red
, green
and blue
set to value
and alpha
set to 255
sourcepub const fn from_i32(value: i32) -> Color
pub const fn from_i32(value: i32) -> Color
Convert an i32 into a Color
where bytes match the format [R,G,B,A]
pub fn from_hex(hex: &str) -> Result<Color, IndexedImageError>
source§impl Color
impl Color
sourcepub fn as_f32_array(&self) -> [f32; 4]
pub fn as_f32_array(&self) -> [f32; 4]
Convert color to f32 array in the format [R,G,B,A] where 0.0 = 0, and 1.0 = 255
pub fn blend(&self, other: Color) -> Color
sourcepub fn brightness(&self) -> f32
pub fn brightness(&self) -> f32
ignores alpha
pub fn is_dark(&self) -> bool
pub fn is_transparent(&self) -> bool
pub fn darken(&self) -> Color
pub fn lighten(&self) -> Color
sourcepub fn with_brightness(&self, amount: f32) -> Color
pub fn with_brightness(&self, amount: f32) -> Color
Copy color with brightness
sourcepub fn with_saturate(&self, amount: f32) -> Color
pub fn with_saturate(&self, amount: f32) -> Color
De/saturate color by percentage Negative amount increases saturation
sourcepub fn desaturate(&self) -> Color
pub fn desaturate(&self) -> Color
Decrease saturation by 10%
Trait Implementations§
source§impl ChangeColors for Color
impl ChangeColors for Color
source§fn with_saturate(&self, amount: f32) -> Color
fn with_saturate(&self, amount: f32) -> Color
De/saturate color by percentage
Negative amount increases saturation
So
-0.1
is 10% more saturatedsource§fn with_brightness(&self, amount: f32) -> Color
fn with_brightness(&self, amount: f32) -> Color
Change brightness to
amount
So 1.1
is 10% brightersource§fn desaturate(&self) -> Selfwhere
Self: Sized,
fn desaturate(&self) -> Selfwhere
Self: Sized,
Decrease saturation by 10%
fn lighten(&self) -> Selfwhere
Self: Sized,
fn darken(&self) -> Selfwhere
Self: Sized,
source§impl<'de> Deserialize<'de> for Color
impl<'de> Deserialize<'de> for Color
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<Color, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Color, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl From<Color> for TextFormat
impl From<Color> for TextFormat
source§impl PartialEq for Color
impl PartialEq for Color
source§impl Serialize for Color
impl Serialize for Color
source§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Copy for Color
impl Eq 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