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) -> Self
pub const fn rgb(r: f64, g: f64, b: f64) -> Self
Sourcepub fn hsl(h: f64, s: f64, l: f64) -> Self
pub fn hsl(h: f64, s: f64, l: f64) -> Self
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) -> Self
pub fn hsva(h: f64, s: f64, v: f64, a: f64) -> Self
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.