Skip to main content

Module theme

Module theme 

Source
Expand description

Design tokens and the built-in light and dark themes.

Every component resolves its colours through Tokens::of, so any iced::Theme works. light and dark are tuned for the library, and Config builds a theme with your own colours on top of either.

Modules§

radius
Corner radii in logical pixels.
space
Spacing scale in logical pixels.
text_size
Text sizes in logical pixels.

Structs§

Config
Builds a Theme from your own colours, starting from the light or dark defaults. Text on coloured surfaces, such as a primary button’s label, is picked automatically with on.
Swatch
A small filled circle of colour, for colour pickers, legends and the options of a select. Convert it into an Element to render.
Tokens
Semantic colours resolved from a theme.

Enums§

Tone
A theme colour that marks what something signals, shared by components that colour items by meaning: calendar entries, timeline steps and spans, and image compare outlines.

Constants§

SWATCH_SIZE
Default diameter of a Swatch in logical pixels.
TEXT_CONTRAST
The contrast ratio body text needs against its background.

Functions§

contrast
The WCAG contrast ratio between two colours, from 1 to 21.
dark
The library’s dark theme.
fade
Returns color with its alpha multiplied by alpha.
font
The registered base font, or iced’s default when none is set.
light
The library’s light theme.
luminance
The relative luminance of colour, from 0 for black to 1 for white, as the WCAG contrast formula uses it.
mix
Linearly blends a towards b by t (0.0 is a, 1.0 is b).
on
Near-black or near-white, whichever has the higher contrast ratio on background.
readable
colour, moved just far enough towards near-white or near-black, whichever stands out from background, for text in it to reach TEXT_CONTRAST. A colour that already reads is left as it is.
semibold
The base font at semibold weight.
set_font
Registers the font components use for emphasised text, such as card and toast titles. Pass the same font you give iced’s default_font, before the first view. Returns false if a font was already set.
swatch
Creates a swatch whose colour is resolved from the theme each time it is drawn, so it follows theme changes.
swatch_color
Creates a swatch of one fixed colour, whatever the theme.