Colors and gradients
Color can distinguish content, show state, and draw attention to an action. Text, shapes, or other cues need to carry the same meaning when color alone would be hard to distinguish.
Day has two color types. Color
is a concrete sRGB value an app computes with. Ink
is what a view is drawn in: a fixed Color, a light/dark pair, or a platform role. Every color
parameter of a view takes impl Into<Ink>, so all three go anywhere a color does, and the toolkit
follows the appearance with no app code running.
const INSET: Ink = Ink::adaptive(Color::rgba(0.0, 0.0, 0.0, 0.045), Color::rgba(0.0, 0.0, 0.0, 0.26));
label(res::str::sale())
.padding(Space::M)
.background(INSET) // a pair
.border(SystemColor::Separator, 1.0) // a role
.color(Color::hex(0x00e8_6a3c)) // a fixed color
Solid colors
Color stores red, green, blue, and alpha as floating-point sRGB components. Constructors include
rgb,
rgba,
hex,
hsl, and
hsv.
All produce the same RGBA representation.
with_alpha changes
opacity. parse accepts
#rgb, #rgba, #rrggbb, #rrggbbaa, and the space-separated component form produced by
Display. to_hex_string
formats a hex value. For interpolation,
lerp_hsl follows the
short hue arc, and day::motion blends in OKLab (tween.md “Lerp”).
Inks
| Spelling | Meaning |
|---|---|
Color::rgb(..), Ink::Fixed(c) | The same color in every appearance. |
Ink::adaptive(light, dark) | light in the light appearance, dark in the dark one. |
SystemColor::Separator, Ink::system(role) | The platform’s color for the role. |
SystemColor::Accent.with_alpha(0.14), ink.with_alpha(a) | The same ink at another opacity, in every appearance. |
Every constructor is const, so an app’s palette is a set of constants.
Ink::with_alpha sets
the alpha of both colors of a pair, and replaces a role’s own alpha (a translucent role such as
Separator becomes exactly a). Inks compare with ==: two pairs are equal when their colors
are, and a role equals the same role at the same alpha. An Ink is not Hash, since it holds
floats.
Ink::map(f) derives an
ink by applying f to its color in each appearance: the readable text color on a fill, a darker
shade of a brand color. A role is resolved first, so the result is a pair.
Where an ink goes
Every color a view takes: .background, a Surface’s fill, border and shadow,
.border, .shadow, a label’s
.color,
TextPreset::color, a run’s color and highlight, a
decoration’s color, a button’s
.tint, image and vector tints, list row icon and badge tints, swipe action
tints, a cover’s
.background, a shape’s fill and stroke, a gradient’s stops, and every
canvas paint. A Color, a SystemColor, an Ink, a signal of any of them, and a closure that
returns any of them are all accepted.
Resolving an ink
Code that needs the numbers resolves an ink with
day::resolve(ink): a contrast
computation, a color mixed from a role, a chart’s palette. The read is tracked, so a draw closure,
a reactive modifier or an effect that calls it runs again when the appearance, the accent or the
contrast setting changes. day::palette()
returns every role at once. A view never needs either: pass it the ink.
A canvas resolves its inks as it records (canvas.md “Colors”), and records again when the appearance changes.
System colors
A SystemColor is a role, which
each toolkit answers with its own color, following the appearance, the user’s accent and the
contrast setting. Where a platform has no such color, the role is the light/dark pair in
SystemColor::fallback.
| Role | What it is for |
|---|---|
Accent | The app’s accent: selection, the prominent button, a focus ring. |
Text | Primary text. |
SecondaryText | De-emphasized text: a caption, a detail line. |
TertiaryText | Text a step quieter than secondary: a footnote, a hint. |
Placeholder | A text field’s placeholder. |
Link | A link in running text. |
Separator | A hairline: a rule, a list separator, a grid line. |
ControlFill | A control’s track or well: a slider track, a search field. |
Background | The window’s content background. |
Surface | A region set off from the background: a panel, a card, a sidebar. |
GroupedBackground | The background behind grouped sections. |
ElevatedSurface | A surface raised above the content: a popover, a menu, a sheet. |
Selection | The highlight behind selected text or content the app draws itself. |
Destructive | A destructive action or an error. |
Success | Success, a value that rose. |
Warning | A warning, something to notice. |
Default text, controls, separators, and window backgrounds already use the toolkit’s colors.
Forms use the platform’s section-card surface, and .card() draws the
grouped-content material. A role is for what an app draws itself.
One fill vocabulary
Paint is what fills an area: a solid
Ink, or a LinearGradient, RadialGradient or ConicGradient. Every fill takes
impl Into<Paint>, so a color, a role, an ink and a gradient go into each of them:
| Where | Call |
|---|---|
| A view | .background(paint) |
| A surface | Surface::fill(paint) |
| A shape | .fill(paint) |
| A canvas | d.fill(shape, paint), d.stroke_styled(shape, paint, style) |
Gradient positions use UnitPoint coordinates relative to the filled bounds, and a radial
gradient stretches with non-square bounds. A gradient’s stops take inks, so
LinearGradient::vertical(SystemColor::Surface, SystemColor::Background)
follows the appearance like a solid fill. Its constructors take any iterable of
(offset, color) pairs:
LinearGradient::new(start, end, [(0.0, a), (1.0, b)]).
How a toolkit follows the appearance
A view keeps the ink, not a color resolved from it, and the toolkit makes the switch:
- AppKit, UIKit: one dynamic
NSColor/UIColorper ink, resolved by the system for the view’s own appearance, so a window or a subtree with its own appearance is right too. - Web: a role is a CSS custom property of the page and a pair is
light-dark(..); the browser switches them withcolor-scheme. - Android: a light/dark switch recreates the activity, and the tree mounted again resolves every ink against the new theme.
- GTK: a role is a libadwaita color in the widget’s CSS, which GTK switches itself; the toolkit re-applies pairs and the colors of label runs when the theme changes.
- Qt, WinUI, ArkUI: the toolkit re-applies every ink it has applied when the theme changes.
Day keeps the current Palette
(every role as the toolkit answers it) and refreshes it on every appearance change, so a toolkit
that applies an ink itself resolves it with Ink::resolved() against the right palette. No piece
is rebuilt and no closure runs.
Inks in motion
Ink implements Lerp, so Animated<Ink> and a background animation work with pairs and roles.
Two fixed colors blend in OKLab. A pair blends each side, so a value mid-flight still follows an
appearance switch. A role is resolved against both appearances first. The endpoints are the inks
themselves: at the end of an animation to SystemColor::Accent, the view holds the role again.
Color picker values
A color picker binds a Color, including alpha when enabled: a
picked value is a concrete color, not an ink. It does not return a gradient. The portable value
does not retain an ICC profile, a named system color, an image pattern, or the color model used to
enter it.
Converting a wide-gamut color to sRGB can lose information. RGB also cannot preserve a user’s chosen hue when saturation or brightness is zero. The composed picker retains that editing state while its panel is open; the bound value remains RGBA. AppKit pattern colors that cannot be represented are ignored.
Toolkit support
| Toolkit | Limitation |
|---|---|
| Android | A light/dark switch recreates the activity: the app’s root() runs again, root-scope state and the current route survive, and state held below the root is built again. |
| Android | Success and Warning have no Material 3 role and are Day’s light/dark pairs. |
| Android | Day’s own appearance override needs Android 12 (API 31); below it Cap::Appearance answers Unsupported and the app follows the system setting. |
| Qt | Qt has no dynamic colors, so after a palette or color-scheme change Day re-applies every ink from a per-widget table on the next event-loop turn (at once for Day’s own appearance override). |
| Qt | Day’s own appearance override needs Qt 6.8. |
| Qt | Under a style with no light/dark scheme, the dark appearance is a Fusion palette Day builds. |
| Qt | Destructive, Success and Warning are Day’s light/dark pairs, and ElevatedSurface is the palette’s Base. |
| Qt | The appearance is app-wide: a window cannot have its own. |
| Qt | On macOS the natively styled parts follow Day’s appearance override a moment after Day’s own drawing. |
| WinUI | XAML has no dynamic colors outside a {ThemeResource}, so after a system or app appearance change Day re-applies every ink from a per-view table, each for the appearance of the window its view is in. |
| WinUI | The roles are the Fluent theme resources read for each appearance (Selection is TextControlSelectionHighlightColor at 35% opacity). On the deprecated system-XAML variant every role is Day’s light/dark pair. |
| WinUI | Navigation-menu icon tints and list swipe-action tints are resolved when the rows are set or built, and follow an appearance switch only when they are set again. |
| WinUI | An ink applied to a view that is not in a window yet resolves for the app’s appearance; a window with its own appearance recolors it at the next switch. |
| WinUI | Underlines and strikethroughs are single lines in the text color: the double, dotted and wavy styles and a separate decoration color are not drawn. |
| ArkUI | Success and Warning have no system color and are Day’s light/dark pairs. |
| ArkUI | The system colors and Day’s appearance override come through the ArkTS host; a host project without Day’s staged ArkTS code gets Day’s light/dark pairs for every role and no override. |