pub struct Color { /* private fields */ }Expand description
A struct representing a color with red, green, blue, and alpha components. Each component is stored as a float.
Implementations§
Source§impl Color
impl Color
Sourcepub const TRANSPARENT: Color
pub const TRANSPARENT: Color
Color constant for transparency, with the alpha value set to zero.
Sourcepub const LIGHT_GRAY: Color
pub const LIGHT_GRAY: Color
Constant for the color light gray.
Sourcepub const fn from_rgba(r: f32, g: f32, b: f32, a: f32) -> Self
pub const fn from_rgba(r: f32, g: f32, b: f32, a: f32) -> Self
Creates a color with the specified components, including an alpha
component. Each component should be in the range 0.0 to 1.0.
Sourcepub const fn from_rgb(r: f32, g: f32, b: f32) -> Self
pub const fn from_rgb(r: f32, g: f32, b: f32) -> Self
Creates a color with the specified components. The alpha component will
be set to 1.0 (full opacity). Each component should be in the range
0.0 to 1.0.
Sourcepub fn from_int_rgba(r: u8, g: u8, b: u8, a: u8) -> Self
pub fn from_int_rgba(r: u8, g: u8, b: u8, a: u8) -> Self
Creates a color with the specified components, including an alpha
component. Each component should be in the range 0 to 255.
Sourcepub fn from_int_rgb(r: u8, g: u8, b: u8) -> Self
pub fn from_int_rgb(r: u8, g: u8, b: u8) -> Self
Creates a color with the specified components. The alpha component will
be set to 255 (full opacity). Each component should be in the range
0 to 255.
Sourcepub fn from_hex_argb(argb: u32) -> Self
pub fn from_hex_argb(argb: u32) -> Self
Creates a color from the specified integer value, including an alpha component.
For example, the input value 0xAABBCCDD will result in a color with:
- Alpha =
0xAA - Red =
0xBB - Green =
0xCC - Blue =
0xDD
Note: If you don’t specify the alpha component, the color will be transparent.
Sourcepub fn from_hex_rgb(rgb: u32) -> Self
pub fn from_hex_rgb(rgb: u32) -> Self
Creates a color from the specified integer value, with the alpha
component set to 255 (full opacity).
For example, the input value 0xAABBCC will result in a color with:
- Alpha =
0xFF - Red =
0xAA - Green =
0xBB - Blue =
0xCC
Note: if an alpha component is specified in the high bits of the integer, it will be ignored. See Color::from_hex_argb if you wish to specify the alpha component.
Sourcepub const fn from_gray(brightness: f32) -> Self
pub const fn from_gray(brightness: f32) -> Self
Creates a shade of gray from the specified float value, between 0.0
and 1.0. All three RGB components will be set to this value.
Sourcepub const fn r(&self) -> f32
pub const fn r(&self) -> f32
Returns the red component of the color, as a value in the range 0.0 to
1.0.
Sourcepub const fn g(&self) -> f32
pub const fn g(&self) -> f32
Returns the green component of the color, as a value in the range 0.0
to 1.0.
Sourcepub const fn b(&self) -> f32
pub const fn b(&self) -> f32
Returns the blue component of the color, as a value in the range 0.0
to 1.0.
Sourcepub const fn a(&self) -> f32
pub const fn a(&self) -> f32
Returns the alpha component of the color, as a value in the range 0.0
to 1.0. The value 0.0 is fully transparent, and the value 1.0
is fully opaque.
Sourcepub fn subjective_brightness(&self) -> f32
pub fn subjective_brightness(&self) -> f32
Returns the brightness of the color as perceived by a human, as a value
in the range 0.0 to 1.0.
This is calculated using the following formula:
red * 0.299 + green * 0.587 + blue * 0.114Trait 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 UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more