Skip to main content

Color

Struct Color 

Source
#[repr(C)]
pub struct Color { pub r: f32, pub g: f32, pub b: f32, pub a: f32, }

Fields§

§r: f32§g: f32§b: f32§a: f32

Implementations§

Source§

impl Color

Source

pub const fn new(r: f32, g: f32, b: f32, a: f32) -> Self

Create a color using r, g, b, a. All values go from 0-1

Source

pub const fn with_alpha(&self, alpha: f32) -> Self

Get the same color a different transparency/alpha.

Source

pub const fn splat_alpha(v: f32, alpha: f32) -> Self

Create a color where RGA is a single number.

Source

pub const fn splat(v: f32) -> Self

Create a color where RGA is a single number. (Alpha = 1)

Source

pub fn lerp(self, other: Color, t: f32) -> Self

Linearly interpolate to another color using 0-1.

Source

pub const fn clamped(&self) -> Self

Source

pub const fn from_rgba8(r: u8, g: u8, b: u8, a: u8) -> Self

Create a color using RGBA. Each value goes from 0-255.

Source

pub const fn from_rgb8(r: u8, g: u8, b: u8) -> Self

Create a color using RGB. Each value goes from 0-255. (Alpha = 1)

Source

pub fn from_hsv(h: f32, s: f32, v: f32) -> Self

Create a color using hue-saturation-value-alpha. All values go from 0-1.

Source

pub fn from_hsva(h: f32, s: f32, v: f32, a: f32) -> Self

Create a color using hue-saturation-value-alpha. All values go from 0-1.

Source

pub fn to_hsv(&self) -> (f32, f32, f32)

Returns (h, s, v) all values from 0-1.

Source

pub fn to_hsva(&self) -> (f32, f32, f32, f32)

Returns (h, s, v, a) all values from 0-1.

Source

pub fn from_hex(hex: &str) -> Option<Self>

Accepts “RRGGBB”, “RGB”, “RRGGBBAA”, “RGBA”, with or without leading ‘#’

Source

pub fn to_hex(&self) -> String

Returns “#RRGGBB”

Source

pub fn to_hex_alpha(&self) -> String

Returns “#RRGGBBAA”

Source

pub const fn to_rgb(&self) -> (u8, u8, u8)

Returns a tuple of (r, g, b) from 0-255.

Source

pub const fn to_rgba(&self) -> (u8, u8, u8, u8)

Returns a tuple of (r, g, b, a) from 0-255.

Source

pub const fn from_vec4(vec: Vector4) -> Self

Create a color from a Vector4<f32> where x -> r, y -> g, z -> b, w -> a

Source

pub const fn to_vec4(&self) -> Vector4

Create a Vector4<f32> from a color where r -> x, g -> y, b -> z, a -> w

Source

pub const fn from_vec3(vec: Vector3) -> Self

Create a color from a Vector3<f32> where x -> r, y -> g, z -> b

Source

pub const fn to_vec3(&self) -> Vector3

Create a Vector3<f32> from a color where r -> x, g -> y, b -> z

Source

pub const fn to_array(&self) -> [f32; 4]

Convert color to an array of [r, g, b, a]

Source

pub const fn to_wgpu(&self) -> Color

Convert color to a wgpu::Color

Source§

impl Color

Source

pub const TRANSPARENT: Self

Source

pub const WHITE: Self

Source

pub const BLACK: Self

Source

pub const LIGHT_BLACK: Self

Source

pub const GRAY: Self

Source

pub const DARK_GRAY: Self

Source

pub const LIGHT_GRAY: Self

Source

pub const RED: Self

Source

pub const DARK_RED: Self

Source

pub const LIGHT_RED: Self

Source

pub const GREEN: Self

Source

pub const DARK_GREEN: Self

Source

pub const LIGHT_GREEN: Self

Source

pub const BLUE: Self

Source

pub const DARK_BLUE: Self

Source

pub const LIGHT_BLUE: Self

Source

pub const YELLOW: Self

Source

pub const DARK_YELLOW: Self

Source

pub const LIGHT_YELLOW: Self

Source

pub const MAGENTA: Self

Source

pub const DARK_MAGENTA: Self

Source

pub const LIGHT_MAGENTA: Self

Source

pub const PURPLE: Self

Source

pub const DARK_PURPLE: Self

Source

pub const LIGHT_PURPLE: Self

Source

pub const CYAN: Self

Source

pub const DARK_CYAN: Self

Source

pub const LIGHT_CYAN: Self

Source

pub const ORANGE: Self

Source

pub const DARK_ORANGE: Self

Source

pub const LIGHT_ORANGE: Self

Trait Implementations§

Source§

impl Add for Color

Source§

type Output = Color

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Color) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign for Color

Source§

fn add_assign(&mut self, rhs: Color)

Performs the += operation. Read more
Source§

impl Clone for Color

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Color

Source§

impl Debug for Color

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Color

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Div for Color

Source§

type Output = Color

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Color) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<f32> for Color

Source§

type Output = Color

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f32) -> Self::Output

Performs the / operation. Read more
Source§

impl DivAssign for Color

Source§

fn div_assign(&mut self, rhs: Color)

Performs the /= operation. Read more
Source§

impl DivAssign<f32> for Color

Source§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
Source§

impl From<Color> for [f32; 4]

Source§

fn from(c: Color) -> Self

Converts to this type from the input type.
Source§

impl From<[f32; 4]> for Color

Source§

fn from(arr: [f32; 4]) -> Self

Converts to this type from the input type.
Source§

impl Mul for Color

Source§

type Output = Color

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Color) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<f32> for Color

Source§

type Output = Color

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f32) -> Self::Output

Performs the * operation. Read more
Source§

impl MulAssign for Color

Source§

fn mul_assign(&mut self, rhs: Color)

Performs the *= operation. Read more
Source§

impl MulAssign<f32> for Color

Source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
Source§

impl PartialEq for Color

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Pod for Color

Source§

impl StructuralPartialEq for Color

Source§

impl Sub for Color

Source§

type Output = Color

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Color) -> Self::Output

Performs the - operation. Read more
Source§

impl SubAssign for Color

Source§

fn sub_assign(&mut self, rhs: Color)

Performs the -= operation. Read more
Source§

impl Zeroable for Color

Source§

fn zeroed() -> Self

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnyBitPattern for T
where T: Pod,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

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.
Source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> NoUninit for T
where T: Pod,

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more