Expand description
iced toolkit connector for native-theme.
Maps native_theme::ResolvedThemeVariant data to iced’s theming system.
§Quick Start
use native_theme_iced::from_preset;
let (theme, resolved) = from_preset("catppuccin-mocha", true)?;Or from the OS-detected theme:
use native_theme_iced::from_system;
let (theme, resolved) = from_system()?;§Manual Path
For full control over the resolve/validate/convert pipeline:
use native_theme::ThemeSpec;
use native_theme_iced::to_theme;
let nt = ThemeSpec::preset("catppuccin-mocha").unwrap();
let resolved = nt.into_variant(false).unwrap().into_resolved().unwrap();
let theme = to_theme(&resolved, "My App");§Font Configuration
To use theme fonts with iced widgets, leak the family name to obtain
the &'static str required by iced_core::font::Family::Name:
let name: &'static str = Box::leak(
native_theme_iced::font_family(&resolved).to_string().into_boxed_str()
);
let font = iced_core::Font {
family: iced_core::font::Family::Name(name),
weight: native_theme_iced::to_iced_weight(
native_theme_iced::font_weight(&resolved)
),
..Default::default()
};This is the standard iced pattern for runtime font names. Each leak is ~10-20 bytes and persists for the app lifetime. Call once at theme init, not per-frame.
§Theme Field Coverage
The connector maps a subset of ResolvedThemeVariant to iced’s theming system:
| Target | Fields | Source |
|---|---|---|
Palette (6 fields) | background, text, primary, success, warning, danger | defaults.* |
Extended overrides (4) | secondary.base.color/text, background.weak.color/text | button.bg/fg, defaults.surface/foreground |
| Widget metrics | button/input padding, border radius, scrollbar width | Per-widget resolved fields |
| Typography | font family/size/weight, mono family/size/weight, line height | defaults.font.*, defaults.mono_font.* |
Per-widget geometry beyond padding/radius (e.g., min-width, disabled-opacity)
is not mapped because iced applies these via inline widget configuration,
not through the theme system. Users can read these directly from the
ResolvedThemeVariant they pass to to_theme().
Modules§
- extended
- Extended palette overrides from
native_theme::ResolvedThemeVariantfields. - icons
- Icon conversion helpers for iced.
- palette
- Maps
native_theme::ResolvedThemeVariantcolors to aniced_core::theme::Palette.
Structs§
- Resolved
Theme Variant - A fully resolved theme where every field is guaranteed populated.
- Rgba
- An sRGB color with alpha, stored as four u8 components.
- System
Theme - Result of the OS-first pipeline. Holds both resolved variants.
- Theme
Spec - A complete native theme with a name and optional light/dark variants.
- Theme
Variant - A single light or dark theme variant containing all visual properties.
Enums§
- Animated
Icon - An animated icon, either frame-based or transform-based.
- Error
- Errors that can occur when reading or processing theme data.
- Icon
Data - Icon data returned by loading functions.
- Icon
Role - Semantic icon roles for cross-platform icon resolution.
- IconSet
- Known icon sets that provide platform-specific icon identifiers.
- Transform
Animation - A CSS-like transform animation applied to a single icon.
Traits§
- Icon
Provider - Trait for types that map icon identifiers to platform-specific names and SVG data.
- System
Theme Ext - Extension trait for converting a
SystemThemeto an iced theme.
Functions§
- border_
radius - Returns the standard border radius from the resolved theme.
- border_
radius_ lg - Returns the large border radius from the resolved theme.
- button_
padding - Returns button padding from the resolved theme as an iced
Padding. - font_
family - Returns the primary UI font family name from the resolved theme.
- font_
size - Returns the primary UI font size in logical pixels from the resolved theme.
- font_
weight - Returns the primary UI font weight (CSS 100-900) from the resolved theme.
- from_
preset - Load a bundled preset and convert it to an iced
Themein one call. - from_
system - Detect the OS theme and convert it to an iced
Themein one call. - input_
padding - Returns text input padding from the resolved theme as an iced
Padding. - line_
height_ multiplier - Returns the line height multiplier from the resolved theme.
- mono_
font_ family - Returns the monospace font family name from the resolved theme.
- mono_
font_ size - Returns the monospace font size in logical pixels from the resolved theme.
- mono_
font_ weight - Returns the monospace font weight (CSS 100-900) from the resolved theme.
- scrollbar_
width - Returns the scrollbar width from the resolved theme.
- to_
iced_ weight - Convert a CSS font weight (100-900) to an iced
Weightenum. - to_
theme - Create an iced
iced_core::theme::Themefrom anative_theme::ResolvedThemeVariant.
Type Aliases§
- Result
- Convenience Result type alias for this crate.