Skip to main content

Color

Struct Color 

Source
pub struct Color {
    pub r: f32,
    pub g: f32,
    pub b: f32,
    pub a: f32,
}
Expand description

A non-premultiplied RGBA color with components in 0.0..=1.0, in the sRGB color space (the space design tokens are written in).

Fields§

§r: f32

Red component, 0.0..=1.0.

§g: f32

Green component, 0.0..=1.0.

§b: f32

Blue component, 0.0..=1.0.

§a: f32

Alpha (opacity), 0.0 transparent to 1.0 opaque.

Implementations§

Source§

impl Color

Source

pub const TRANSPARENT: Color

Fully transparent black.

Source

pub const BLACK: Color

Opaque black.

Source

pub const WHITE: Color

Opaque white.

Source

pub const fn rgba(r: f32, g: f32, b: f32, a: f32) -> Color

Builds a color from sRGB components and alpha, each in 0.0..=1.0.

Source

pub const fn rgb(r: f32, g: f32, b: f32) -> Color

Builds an opaque color from sRGB components in 0.0..=1.0.

Source

pub const fn hex(rgb: u32) -> Color

Builds an opaque color from 0xRRGGBB.

Source

pub const fn hex_alpha(rgba: u32) -> Color

Builds a color from 0xRRGGBBAA.

Source

pub const fn faded(self, factor: f32) -> Color

Returns the same color, factor times as opaque as it already is. Use this on a theme’s tokens: in a glass theme they are translucent to begin with, and Self::with_alpha would make them more opaque, not less.

use ravenrs_core::Color;

let glass = Color::rgba(1.0, 1.0, 1.0, 0.2);
assert_eq!(glass.faded(0.5).a, 0.1);
assert_eq!(glass.with_alpha(0.5).a, 0.5);
Source

pub const fn with_alpha(self, a: f32) -> Color

Returns the same color with alpha replaced by a (0.0..=1.0).

Source

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

Component-wise interpolation in sRGB space, t clamped to 0..=1.

Source

pub fn to_linear(self) -> [f32; 4]

Converts to linear-light RGB (alpha unchanged), as needed by *Srgb render targets.

Source

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

Returns the sRGB components as [r, g, b, a], without linearization.

Source

pub fn luminance(self) -> f32

WCAG relative luminance.

Source

pub fn contrast_ratio(self, other: Color) -> f32

WCAG contrast ratio between two opaque colors (1.0 to 21.0).

Trait Implementations§

Source§

impl Animatable for Color

Source§

const REST: f32 = 0.002

Below this distance from the target, the animation counts as finished.
Source§

fn to_components(self) -> [f32; 4]

The value as numbers to interpolate.
Source§

fn from_components(c: [f32; 4]) -> Color

The value back from interpolated numbers, which may overshoot.
Source§

impl Clone for Color

Source§

fn clone(&self) -> Color

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<(), Error>

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

impl Default for Color

Source§

fn default() -> Color

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

impl From<Color> for Fill

Source§

fn from(c: Color) -> Fill

Converts to this type from the input type.
Source§

impl PartialEq for Color

Source§

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

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

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

Inequality operator !=. Read more
Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

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

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
§

impl<T> Brush for T
where T: Clone + PartialEq + Default + Debug,

§

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

§

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

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
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

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

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

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.

§

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
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

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

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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