pub struct Color {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}Expand description
RGBA color, each channel in [0, 1].
Fields§
§r: f32Red channel.
g: f32Green channel.
b: f32Blue channel.
a: f32Alpha channel.
Implementations§
Source§impl Color
impl Color
Sourcepub const fn rgb(r: f32, g: f32, b: f32) -> Self
pub const fn rgb(r: f32, g: f32, b: f32) -> Self
Constructs a fully-opaque Color from r, g, b channels.
Sourcepub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Self
pub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Self
Constructs a Color from r, g, b, a channels.
Sourcepub const fn from_rgba8(rgba: [u8; 4]) -> Self
pub const fn from_rgba8(rgba: [u8; 4]) -> Self
Constructs a Color from [R, G, B, A] bytes - the inverse of
Self::to_rgba8, and the readable spelling for hex palettes
(Color::from_rgba8([0x21, 0x25, 0x2c, 0xff])).
Sourcepub fn to_rgba8(self) -> [u8; 4]
pub fn to_rgba8(self) -> [u8; 4]
Packs into [R, G, B, A] bytes, clamping each channel to [0, 1] and rounding to u8.
Sourcepub fn from_hex(hex: &str) -> Option<Self>
pub fn from_hex(hex: &str) -> Option<Self>
Parse a CSS hex color literal: #rgb, #rgba, #rrggbb, or
#rrggbbaa, the leading # optional. None when the input matches
none of the shapes.
The engine’s one hex parser: the palette literals and every script
host’s color builtins (signal_set_color, set_color) go through
it, so a color spelled anywhere means the same bytes. Safe on
arbitrary input - script strings arrive unchecked, and a multi-byte
character is a parse miss, never a slicing panic.
Trait Implementations§
Source§impl From<&'static str> for Color
impl From<&'static str> for Color
Source§fn from(hex: &'static str) -> Self
fn from(hex: &'static str) -> Self
Parses #rgb, #rgba, #rrggbb, or #rrggbbaa literals through
Color::from_hex. Falls back to Color::default on any parse
error - this impl is intended for the Adwaita defaults table where
every literal is known-good at compile time.
Source§impl From<Color> for PropertyValue
impl From<Color> for PropertyValue
Source§impl From<PropertyValue> for Color
impl From<PropertyValue> for Color
Source§fn from(v: PropertyValue) -> Self
fn from(v: PropertyValue) -> Self
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FromTemplate for T
impl<T> FromTemplate for T
§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
Creates Self using default().
§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
§impl<T> Template for T
impl<T> Template for T
§fn build_template(
&self,
_context: &mut TemplateContext<'_, '_>,
) -> Result<<T as Template>::Output, BevyError>
fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>
entity context to produce a Template::Output.§fn clone_template(&self) -> T
fn clone_template(&self) -> T
Clone.