pub struct Color {
pub r: f64,
pub g: f64,
pub b: f64,
pub a: f64,
}Expand description
sRGB color, 0.0–1.0 components. Semantic theme tokens (§6.3) resolve to these in the backend.
Fields§
§r: f64§g: f64§b: f64§a: f64Implementations§
Source§impl Color
impl Color
pub const BLACK: Color
pub const WHITE: Color
pub const CLEAR: Color
pub const fn rgba(r: f64, g: f64, b: f64, a: f64) -> Color
pub const fn rgb(r: f64, g: f64, b: f64) -> Color
Sourcepub fn hsl(h: f64, s: f64, l: f64) -> Color
pub fn hsl(h: f64, s: f64, l: f64) -> Color
From HSL: h in degrees (wraps mod 360), s/l in 0.0..=1.0. Color is the one color
type every parameter accepts, so this makes HSL usable everywhere a color is.
pub fn hsla(h: f64, s: f64, l: f64, a: f64) -> Color
pub fn hsva(h: f64, s: f64, v: f64, a: f64) -> Color
Sourcepub fn to_hsl(&self) -> (f64, f64, f64)
pub fn to_hsl(&self) -> (f64, f64, f64)
Decompose to (hue°, saturation, lightness) (HSL). Hue is 0.0 for grays.
Sourcepub fn to_hsv(&self) -> (f64, f64, f64)
pub fn to_hsv(&self) -> (f64, f64, f64)
Decompose to (hue°, saturation, value) (HSV/HSB), the model every native color picker’s
spectrum tab is built on, so this is what a renderer seeds its sliders from. Hue is 0.0
for grays. Inverse of Color::hsv.
Sourcepub fn with_alpha(self, a: f64) -> Color
pub fn with_alpha(self, a: f64) -> Color
The same color at a different opacity: what a picker’s alpha slider produces, and what
tinting a surface down to a wash needs (palette.with_alpha(0.14)).
Sourcepub fn to_hex_string(&self) -> String
pub fn to_hex_string(&self) -> String
#rrggbb, or #rrggbbaa when the color is not fully opaque. The 8-bit form every
platform’s own color field speaks, and what Color::parse round-trips.
Sourcepub fn parse(s: &str) -> Option<Color>
pub fn parse(s: &str) -> Option<Color>
Parse a color from either interchange form:
- hex:
#rgb,#rgba,#rrggbb,#rrggbbaa(the leading#optional). What a person types, and what an 8-bit platform field (<input type="color">,Windows.UI.Color,android.graphics.Color) hands back. - components: 3 or 4 space-separated floats in
0.0..=1.0,"r g b"/"r g b a". The lossless form, for the toolkits whose picker really is float-precision (NSColor,GdkRGBA,QColor::getRgbF).
None on anything else. See docs/color.md for
why the currency stays sRGB for now and what a wider one would carry.
Sourcepub fn lerp_hsl(self, to: Color, t: f64) -> Color
pub fn lerp_hsl(self, to: Color, t: f64) -> Color
Interpolate toward to in HSL space, taking the shortest hue arc (t in 0.0..=1.0). A
hue-space blend (red→green sweeps through yellow) rather than the muddy RGB straight line,
used by the canvas / self-driven animation path (native widget color animation interpolates
in the toolkit’s own space).
Trait Implementations§
impl Copy for Color
Source§impl Display for Color
The lossless interchange form: four space-separated components, exactly what
Color::parse reads back. This is what crosses a JNI / C-ABI / JS boundary when a native
color picker reports a pick, so the float precision NSColor and GdkRGBA really carry is
not rounded to 8 bits on the way. For the form a person reads (and types into a dayscript
step) use Color::to_hex_string.
impl Display for Color
The lossless interchange form: four space-separated components, exactly what
Color::parse reads back. This is what crosses a JNI / C-ABI / JS boundary when a native
color picker reports a pick, so the float precision NSColor and GdkRGBA really carry is
not rounded to 8 bits on the way. For the form a person reads (and types into a dayscript
step) use Color::to_hex_string.
Source§impl Lerp for Color
Colors blend in OKLab (Björn Ottosson’s perceptual space), alpha linearly: the midpoint of blue
and yellow is a clean mid-lightness color rather than sRGB’s dim gray, and a sequential scale’s
in-between cells read as in-between values. The endpoints are exact.
impl Lerp for Color
Colors blend in OKLab (Björn Ottosson’s perceptual space), alpha linearly: the midpoint of blue and yellow is a clean mid-lightness color rather than sRGB’s dim gray, and a sequential scale’s in-between cells read as in-between values. The endpoints are exact.
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> AnyEq for T
impl<T> AnyEq for T
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> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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