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.

Use Color for fixed sRGB colors and Paint for canvas fills and styled strokes. Leave a control’s color unset when it should follow the platform’s default appearance.

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.

let accent = Color::hex(0x2463eb);
let translucent = accent.with_alpha(0.5);
rectangle().fill(translucent).frame(80.0, 40.0)

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 rather than a straight line through RGB.

Gradients

Paint represents a solid color, a LinearGradient, or a RadialGradient. Gradient positions use UnitPoint coordinates relative to the drawing bounds. A radial gradient stretches with non-square bounds.

SurfaceAPI
Canvas fillDraw::fill accepts a solid color or gradient.
Canvas styled strokeDraw::stroke_styled accepts Paint.
Shape fill.fill_linear and .fill_radial accept their respective gradients.
Ordinary background, text color, or tintTakes a solid Color; does not accept a gradient.

For a gradient card, place a filled shape behind its content in a zstack. Set the shape’s bounds and corner radius explicitly. See Canvas for drawing and export support.

Native appearance

Default text, controls, separators, and window backgrounds use colors selected by the toolkit. Forms use the platform’s section-card surface. These defaults can respond to appearance and accessibility settings without a fixed app color.

Color itself is a concrete value, not a dynamic system-color token. Assigning a fixed color replaces that default; choose suitable values for each appearance your app supports. The Settings theme preference controls the app’s light or dark appearance.

Color picker values

A color picker binds a Color, including alpha when enabled. 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.

Platform guidance