color
tape
import colors from "color";
let accent: color = colors.rgb(54, 140, 226); // #368CE2
let hover: color = colors.lighten(accent, 8);
let glass: color = colors.with_alpha(accent, 128);
let dark: bool = colors.is_dark(accent); // trueHelpers for the color type: #RRGGBB and #RRGGBBAA literals, stored
as 0xRRGGBBAA. Import it under another name (colors), since color is
the type’s name. Pure integer arithmetic.
| Function | Does |
|---|---|
rgb(r, g, b), rgba(r, g, b, a) | A color from 0-255 channels (clamped) |
red(c), green(c), blue(c), alpha(c) | One channel, 0-255 |
with_alpha(c, a) | c with another alpha |
unpack(c) -> Color, pack(Color) | To and from Color { r; g; b; } |
lighten(c, amount), darken(c, amount) | Toward white or black; alpha kept |
hover(c), pressed(c), disabled(c) | The shades the widgets use |
lerp(a, b, t) | From a (t = 0) to b (t = 256) |
mix(a, b) | Half-way |
invert(c), multiply(a, b) | 255 minus each channel; channel products |
brightness(c) -> i64, is_dark(c) | Perceived brightness 0-255; below 128 |
to_argb(c) -> u32, from_argb(v), to_abgr(c) -> u32 | Byte orders for C libraries |
Last modified: