pub enum Color {
Rgba {
red: f32,
green: f32,
blue: f32,
alpha: f32,
},
RgbaLinear {
red: f32,
green: f32,
blue: f32,
alpha: f32,
},
Hsla {
hue: f32,
saturation: f32,
lightness: f32,
alpha: f32,
},
Lcha {
lightness: f32,
chroma: f32,
hue: f32,
alpha: f32,
},
}
Variants§
Rgba
Fields
sRGBA color
RgbaLinear
Fields
RGBA color in the Linear sRGB colorspace (often colloquially referred to as “linear”, “RGB”, or “linear RGB”).
Hsla
Fields
HSL (hue, saturation, lightness) color with an alpha channel
Lcha
Fields
LCH(ab) (lightness, chroma, hue) color with an alpha channel
Implementations§
§impl Color
impl Color
pub const ALICE_BLUE: Color = Color::rgb(0.94, 0.97, 1.0)
pub const ALICE_BLUE: Color = Color::rgb(0.94, 0.97, 1.0)
pub const ANTIQUE_WHITE: Color = Color::rgb(0.98, 0.92, 0.84)
pub const ANTIQUE_WHITE: Color = Color::rgb(0.98, 0.92, 0.84)
pub const AQUAMARINE: Color = Color::rgb(0.49, 1.0, 0.83)
pub const AQUAMARINE: Color = Color::rgb(0.49, 1.0, 0.83)
pub const DARK_GREEN: Color = Color::rgb(0.0, 0.5, 0.0)
pub const DARK_GREEN: Color = Color::rgb(0.0, 0.5, 0.0)
pub const LIME_GREEN: Color = Color::rgb(0.2, 0.8, 0.2)
pub const LIME_GREEN: Color = Color::rgb(0.2, 0.8, 0.2)
pub const MIDNIGHT_BLUE: Color = Color::rgb(0.1, 0.1, 0.44)
pub const MIDNIGHT_BLUE: Color = Color::rgb(0.1, 0.1, 0.44)
pub const ORANGE_RED: Color = Color::rgb(1.0, 0.27, 0.0)
pub const ORANGE_RED: Color = Color::rgb(1.0, 0.27, 0.0)
pub const YELLOW_GREEN: Color = Color::rgb(0.6, 0.8, 0.2)
pub const YELLOW_GREEN: Color = Color::rgb(0.6, 0.8, 0.2)
pub const fn rgb(r: f32, g: f32, b: f32) -> Color
pub const fn rgb(r: f32, g: f32, b: f32) -> Color
New Color
from sRGB colorspace.
Arguments
r
- Red channel. [0.0, 1.0]g
- Green channel. [0.0, 1.0]b
- Blue channel. [0.0, 1.0]
See also Color::rgba
, Color::rgb_u8
, Color::hex
.
pub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Color
pub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Color
New Color
from sRGB colorspace.
Arguments
r
- Red channel. [0.0, 1.0]g
- Green channel. [0.0, 1.0]b
- Blue channel. [0.0, 1.0]a
- Alpha channel. [0.0, 1.0]
See also Color::rgb
, Color::rgba_u8
, Color::hex
.
pub const fn rgb_linear(r: f32, g: f32, b: f32) -> Color
pub const fn rgb_linear(r: f32, g: f32, b: f32) -> Color
New Color
from linear RGB colorspace.
Arguments
r
- Red channel. [0.0, 1.0]g
- Green channel. [0.0, 1.0]b
- Blue channel. [0.0, 1.0]
See also Color::rgb
, Color::rgba_linear
.
pub const fn rgba_linear(r: f32, g: f32, b: f32, a: f32) -> Color
pub const fn rgba_linear(r: f32, g: f32, b: f32, a: f32) -> Color
New Color
from linear RGB colorspace.
Arguments
r
- Red channel. [0.0, 1.0]g
- Green channel. [0.0, 1.0]b
- Blue channel. [0.0, 1.0]a
- Alpha channel. [0.0, 1.0]
See also Color::rgba
, Color::rgb_linear
.
pub const fn hsl(hue: f32, saturation: f32, lightness: f32) -> Color
pub const fn hsl(hue: f32, saturation: f32, lightness: f32) -> Color
New Color
with HSL representation in sRGB colorspace.
Arguments
hue
- Hue channel. [0.0, 360.0]saturation
- Saturation channel. [0.0, 1.0]lightness
- Lightness channel. [0.0, 1.0]
See also Color::hsla
.
pub const fn hsla(
hue: f32,
saturation: f32,
lightness: f32,
alpha: f32
) -> Color
pub const fn hsla( hue: f32, saturation: f32, lightness: f32, alpha: f32 ) -> Color
New Color
with HSL representation in sRGB colorspace.
Arguments
hue
- Hue channel. [0.0, 360.0]saturation
- Saturation channel. [0.0, 1.0]lightness
- Lightness channel. [0.0, 1.0]alpha
- Alpha channel. [0.0, 1.0]
See also Color::hsl
.
pub const fn lch(lightness: f32, chroma: f32, hue: f32) -> Color
pub const fn lch(lightness: f32, chroma: f32, hue: f32) -> Color
New Color
with LCH representation in sRGB colorspace.
Arguments
lightness
- Lightness channel. [0.0, 1.5]chroma
- Chroma channel. [0.0, 1.5]hue
- Hue channel. [0.0, 360.0]
See also Color::lcha
.
pub const fn lcha(lightness: f32, chroma: f32, hue: f32, alpha: f32) -> Color
pub const fn lcha(lightness: f32, chroma: f32, hue: f32, alpha: f32) -> Color
New Color
with LCH representation in sRGB colorspace.
Arguments
lightness
- Lightness channel. [0.0, 1.5]chroma
- Chroma channel. [0.0, 1.5]hue
- Hue channel. [0.0, 360.0]alpha
- Alpha channel. [0.0, 1.0]
See also Color::lch
.
pub fn hex<T>(hex: T) -> Result<Color, HexColorError>where
T: AsRef<str>,
pub fn hex<T>(hex: T) -> Result<Color, HexColorError>where T: AsRef<str>,
New Color
from sRGB colorspace.
Examples
let color = Color::hex("FF00FF").unwrap(); // fuchsia
let color = Color::hex("FF00FF7F").unwrap(); // partially transparent fuchsia
// A standard hex color notation is also available
assert_eq!(Color::hex("#FFFFFF").unwrap(), Color::rgb(1.0, 1.0, 1.0));
pub fn rgb_u8(r: u8, g: u8, b: u8) -> Color
pub fn rgb_u8(r: u8, g: u8, b: u8) -> Color
New Color
from sRGB colorspace.
Arguments
r
- Red channel. [0, 255]g
- Green channel. [0, 255]b
- Blue channel. [0, 255]
See also Color::rgb
, Color::rgba_u8
, Color::hex
.
pub fn rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Color
pub fn rgba_u8(r: u8, g: u8, b: u8, a: u8) -> Color
New Color
from sRGB colorspace.
Arguments
r
- Red channel. [0, 255]g
- Green channel. [0, 255]b
- Blue channel. [0, 255]a
- Alpha channel. [0, 255]
See also Color::rgba
, Color::rgb_u8
, Color::hex
.
pub fn with_r(self, r: f32) -> Color
pub fn with_r(self, r: f32) -> Color
Returns this color with red set to a new value in sRGB colorspace.
pub fn with_g(self, g: f32) -> Color
pub fn with_g(self, g: f32) -> Color
Returns this color with green set to a new value in sRGB colorspace.
pub fn with_b(self, b: f32) -> Color
pub fn with_b(self, b: f32) -> Color
Returns this color with blue set to a new value in sRGB colorspace.
pub fn as_rgba_linear(&self) -> Color
pub fn as_rgba_linear(&self) -> Color
Converts a Color
to variant Color::RgbaLinear
pub fn as_rgba_u8(&self) -> [u8; 4]
pub fn as_rgba_u8(&self) -> [u8; 4]
Converts a Color
to a [u8; 4]
from sRGB colorspace
pub fn as_rgba_f32(self) -> [f32; 4]
pub fn as_rgba_f32(self) -> [f32; 4]
Converts a Color
to a [f32; 4]
from sRGB colorspace
pub fn as_linear_rgba_f32(self) -> [f32; 4]
pub fn as_linear_rgba_f32(self) -> [f32; 4]
Converts a Color
to a [f32; 4]
from linear RGB colorspace
pub fn as_hsla_f32(self) -> [f32; 4]
pub fn as_hsla_f32(self) -> [f32; 4]
Converts a Color
to a [f32; 4]
from HSL colorspace
pub fn as_lcha_f32(self) -> [f32; 4]
pub fn as_lcha_f32(self) -> [f32; 4]
Converts a Color
to a [f32; 4]
from LCH colorspace
pub fn as_rgba_u32(self) -> u32
pub fn as_rgba_u32(self) -> u32
Converts Color
to a u32
from sRGB colorspace.
Maps the RGBA channels in RGBA order to a little-endian byte array (GPUs are little-endian).
A
will be the most significant byte and R
the least significant.
pub fn as_linear_rgba_u32(self) -> u32
pub fn as_linear_rgba_u32(self) -> u32
Converts Color to a u32 from linear RGB colorspace.
Maps the RGBA channels in RGBA order to a little-endian byte array (GPUs are little-endian).
A
will be the most significant byte and R
the least significant.
Trait Implementations§
§impl AddAssign<Color> for Color
impl AddAssign<Color> for Color
§fn add_assign(&mut self, rhs: Color)
fn add_assign(&mut self, rhs: Color)
+=
operation. Read more§impl AddAssign<Vec4> for Color
impl AddAssign<Vec4> for Color
§fn add_assign(&mut self, rhs: Vec4)
fn add_assign(&mut self, rhs: Vec4)
+=
operation. Read more§impl CreateFrom for Color
impl CreateFrom for Color
fn create_from<B>(reader: &mut Reader<B>) -> Colorwhere B: BufferRef,
§impl<'de> Deserialize<'de> for Color
impl<'de> Deserialize<'de> for Color
§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>,
§impl Enum for Colorwhere
f32: FromReflect,
impl Enum for Colorwhere f32: FromReflect,
§fn field(&self, __name_param: &str) -> Option<&(dyn Reflect + 'static)>
fn field(&self, __name_param: &str) -> Option<&(dyn Reflect + 'static)>
§fn field_at(&self, __index_param: usize) -> Option<&(dyn Reflect + 'static)>
fn field_at(&self, __index_param: usize) -> Option<&(dyn Reflect + 'static)>
§fn field_mut(
&mut self,
__name_param: &str
) -> Option<&mut (dyn Reflect + 'static)>
fn field_mut( &mut self, __name_param: &str ) -> Option<&mut (dyn Reflect + 'static)>
§fn field_at_mut(
&mut self,
__index_param: usize
) -> Option<&mut (dyn Reflect + 'static)>
fn field_at_mut( &mut self, __index_param: usize ) -> Option<&mut (dyn Reflect + 'static)>
§fn index_of(&self, __name_param: &str) -> Option<usize>
fn index_of(&self, __name_param: &str) -> Option<usize>
§fn name_at(&self, __index_param: usize) -> Option<&str>
fn name_at(&self, __index_param: usize) -> Option<&str>
§fn iter_fields(&self) -> VariantFieldIter<'_> ⓘ
fn iter_fields(&self) -> VariantFieldIter<'_> ⓘ
§fn variant_name(&self) -> &str
fn variant_name(&self) -> &str
§fn variant_index(&self) -> usize
fn variant_index(&self) -> usize
§fn variant_type(&self) -> VariantType
fn variant_type(&self) -> VariantType
fn clone_dynamic(&self) -> DynamicEnum
§fn is_variant(&self, variant_type: VariantType) -> bool
fn is_variant(&self, variant_type: VariantType) -> bool
§fn variant_path(&self) -> String
fn variant_path(&self) -> String
§impl From<Color> for BackgroundColor
impl From<Color> for BackgroundColor
§fn from(color: Color) -> BackgroundColor
fn from(color: Color) -> BackgroundColor
§impl From<Color> for BorderColor
impl From<Color> for BorderColor
§fn from(color: Color) -> BorderColor
fn from(color: Color) -> BorderColor
§impl From<Color> for ColorMaterial
impl From<Color> for ColorMaterial
§fn from(color: Color) -> ColorMaterial
fn from(color: Color) -> ColorMaterial
§impl From<Color> for StandardMaterial
impl From<Color> for StandardMaterial
§fn from(color: Color) -> StandardMaterial
fn from(color: Color) -> StandardMaterial
§impl FromReflect for Colorwhere
f32: FromReflect,
impl FromReflect for Colorwhere f32: FromReflect,
§fn from_reflect(__param0: &(dyn Reflect + 'static)) -> Option<Color>
fn from_reflect(__param0: &(dyn Reflect + 'static)) -> Option<Color>
Self
from a reflected value.§impl GetTypeRegistration for Colorwhere
f32: FromReflect,
impl GetTypeRegistration for Colorwhere f32: FromReflect,
§impl MulAssign<[f32; 3]> for Color
impl MulAssign<[f32; 3]> for Color
§fn mul_assign(&mut self, rhs: [f32; 3])
fn mul_assign(&mut self, rhs: [f32; 3])
*=
operation. Read more§impl MulAssign<[f32; 4]> for Color
impl MulAssign<[f32; 4]> for Color
§fn mul_assign(&mut self, rhs: [f32; 4])
fn mul_assign(&mut self, rhs: [f32; 4])
*=
operation. Read more§impl MulAssign<Vec3> for Color
impl MulAssign<Vec3> for Color
§fn mul_assign(&mut self, rhs: Vec3)
fn mul_assign(&mut self, rhs: Vec3)
*=
operation. Read more§impl MulAssign<Vec4> for Color
impl MulAssign<Vec4> for Color
§fn mul_assign(&mut self, rhs: Vec4)
fn mul_assign(&mut self, rhs: Vec4)
*=
operation. Read more§impl MulAssign<f32> for Color
impl MulAssign<f32> for Color
§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*=
operation. Read more§impl Reflect for Colorwhere
f32: FromReflect,
impl Reflect for Colorwhere f32: FromReflect,
§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut dyn Any
.§fn into_reflect(self: Box<Color, Global>) -> Box<dyn Reflect, Global>
fn into_reflect(self: Box<Color, Global>) -> Box<dyn Reflect, Global>
§fn as_reflect(&self) -> &(dyn Reflect + 'static)
fn as_reflect(&self) -> &(dyn Reflect + 'static)
§fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
§fn clone_value(&self) -> Box<dyn Reflect, Global>
fn clone_value(&self) -> Box<dyn Reflect, Global>
Reflect
trait object. Read more§fn set(
&mut self,
__value_param: Box<dyn Reflect, Global>
) -> Result<(), Box<dyn Reflect, Global>>
fn set( &mut self, __value_param: Box<dyn Reflect, Global> ) -> Result<(), Box<dyn Reflect, Global>>
§fn apply(&mut self, __value_param: &(dyn Reflect + 'static))
fn apply(&mut self, __value_param: &(dyn Reflect + 'static))
§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
§fn reflect_owned(self: Box<Color, Global>) -> ReflectOwned
fn reflect_owned(self: Box<Color, Global>) -> ReflectOwned
§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
§fn reflect_partial_eq(&self, value: &(dyn Reflect + 'static)) -> Option<bool>
fn reflect_partial_eq(&self, value: &(dyn Reflect + 'static)) -> Option<bool>
§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
§fn serializable(&self) -> Option<Serializable<'_>>
fn serializable(&self) -> Option<Serializable<'_>>
§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
§impl Serialize for Color
impl Serialize for Color
§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,
§impl ShaderSize for Color
impl ShaderSize for Color
§const SHADER_SIZE: NonZeroU64 = Self::METADATA.min_size().0
const SHADER_SIZE: NonZeroU64 = Self::METADATA.min_size().0
ShaderType::min_size
)§impl ShaderType for Color
impl ShaderType for Color
§fn min_size() -> NonZeroU64
fn min_size() -> NonZeroU64
§fn size(&self) -> NonZeroU64
fn size(&self) -> NonZeroU64
Self
at runtime Read more§fn assert_uniform_compat()
fn assert_uniform_compat()
Self
meets the requirements of the
uniform address space restrictions on stored values and the
uniform address space layout constraints Read more§impl TypePath for Colorwhere
f32: FromReflect,
impl TypePath for Colorwhere f32: FromReflect,
§fn short_type_path() -> &'static str
fn short_type_path() -> &'static str
§fn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
§fn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
§impl Typed for Colorwhere
f32: FromReflect,
impl Typed for Colorwhere f32: FromReflect,
impl Copy for Color
impl StructuralPartialEq for Color
Auto Trait Implementations§
impl RefUnwindSafe for Color
impl Send for Color
impl Sync for Color
impl Unpin for Color
impl UnwindSafe for Color
Blanket Implementations§
§impl<T, U> AsBindGroupShaderType<U> for Twhere
U: ShaderType,
&'a T: for<'a> Into<U>,
impl<T, U> AsBindGroupShaderType<U> for Twhere U: ShaderType, &'a T: for<'a> Into<U>,
§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
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> DynamicTypePath for Twhere
T: TypePath,
impl<T> DynamicTypePath for Twhere T: TypePath,
§fn reflect_type_path(&self) -> &str
fn reflect_type_path(&self) -> &str
TypePath::type_path
.§fn reflect_short_type_path(&self) -> &str
fn reflect_short_type_path(&self) -> &str
§fn reflect_type_ident(&self) -> Option<&str>
fn reflect_type_ident(&self) -> Option<&str>
TypePath::type_ident
.§fn reflect_crate_name(&self) -> Option<&str>
fn reflect_crate_name(&self) -> Option<&str>
TypePath::crate_name
.§fn reflect_module_path(&self) -> Option<&str>
fn reflect_module_path(&self) -> Option<&str>
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere T: Default,
§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given World§impl<T> GetPath for Twhere
T: Reflect,
impl<T> GetPath for Twhere T: Reflect,
§fn reflect_path<'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r (dyn Reflect + 'static), ReflectPathError<'p>>
fn reflect_path<'r, 'p>( &'r self, path: &'p str ) -> Result<&'r (dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read more§fn reflect_path_mut<'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut (dyn Reflect + 'static), ReflectPathError<'p>>
fn reflect_path_mut<'r, 'p>( &'r mut self, path: &'p str ) -> Result<&'r mut (dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read more