#[repr(C)]pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}Expand description
Straight RGBA components in linear sRGB, normally in the range [0, 1].
Fields§
§r: f32Red component (0.0 to 1.0)
g: f32Green component (0.0 to 1.0)
b: f32Blue component (0.0 to 1.0)
a: f32Alpha (transparency) component (0.0 = fully transparent, 1.0 = fully opaque)
Implementations§
Source§impl Color
impl Color
Sourcepub const TRANSPARENT: Self
pub const TRANSPARENT: Self
Fully transparent color (0, 0, 0, 0).
Sourcepub const GREY: Self = Self::GRAY
pub const GREY: Self = Self::GRAY
Alias for Color::GRAY.
Sourcepub const fn new(r: f32, g: f32, b: f32, a: f32) -> Self
pub const fn new(r: f32, g: f32, b: f32, a: f32) -> Self
Creates a new Color from four f32 values (red, green, blue, alpha).
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 new opaque Color from three f32 values (red, green, blue).
Sourcepub const fn from_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Self
pub const fn from_rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Self
Normalizes byte RGBA components to [0, 1] without sRGB decoding.
Sourcepub const fn from_rgb_u8(r: u8, g: u8, b: u8) -> Self
pub const fn from_rgb_u8(r: u8, g: u8, b: u8) -> Self
Normalizes byte RGB components without sRGB decoding; alpha is 1.
Sourcepub const fn with_alpha(self, alpha: f32) -> Self
pub const fn with_alpha(self, alpha: f32) -> Self
Sets the alpha (transparency) component of the color.
Sourcepub fn blend_over(self, overlay: Color, overlay_alpha: f32) -> Self
pub fn blend_over(self, overlay: Color, overlay_alpha: f32) -> Self
Composites overlay over this base color using straight RGBA values.
overlay_alpha scales the overlay’s own alpha. Transparent colors do
not darken the result, and a fully transparent result returns
transparent black.
§Parameters
overlay- The color to be composited on top ofself.overlay_alpha- Opacity of the overlay in range[0.0, 1.0].
§Returns
A new Color representing the blended result.
Trait Implementations§
impl Copy for Color
Source§impl From<[f32; 3]> for Color
Converts from a 3-element f32 array [r, g, b] to an opaque Color.
impl From<[f32; 3]> for Color
Converts from a 3-element f32 array [r, g, b] to an opaque Color.
impl Pod 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§
impl<T> AnyBitPattern for Twhere
T: Pod,
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
§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§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>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§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.§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.