Skip to main content

Crate native_theme_iced

Crate native_theme_iced 

Source
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:

TargetFieldsSource
Palette (6 fields)background, text, primary, success, warning, dangerdefaults.*
Extended overrides (4)secondary.base.color/text, background.weak.color/textbutton.bg/fg, defaults.surface/foreground
Widget metricsbutton/input padding, border radius, scrollbar widthPer-widget resolved fields
Typographyfont family/size/weight, mono family/size/weight, line heightdefaults.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::ResolvedThemeVariant fields.
icons
Icon conversion helpers for iced.
palette
Maps native_theme::ResolvedThemeVariant colors to an iced_core::theme::Palette.

Structs§

ResolvedThemeVariant
A fully resolved theme where every field is guaranteed populated.
Rgba
An sRGB color with alpha, stored as four u8 components.
SystemTheme
Result of the OS-first pipeline. Holds both resolved variants.
ThemeSpec
A complete native theme with a name and optional light/dark variants.
ThemeVariant
A single light or dark theme variant containing all visual properties.

Enums§

AnimatedIcon
An animated icon, either frame-based or transform-based.
Error
Errors that can occur when reading or processing theme data.
IconData
Icon data returned by loading functions.
IconRole
Semantic icon roles for cross-platform icon resolution.
IconSet
Known icon sets that provide platform-specific icon identifiers.
TransformAnimation
A CSS-like transform animation applied to a single icon.

Traits§

IconProvider
Trait for types that map icon identifiers to platform-specific names and SVG data.
SystemThemeExt
Extension trait for converting a SystemTheme to 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 Theme in one call.
from_system
Detect the OS theme and convert it to an iced Theme in 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 Weight enum.
to_theme
Create an iced iced_core::theme::Theme from a native_theme::ResolvedThemeVariant.

Type Aliases§

Result
Convenience Result type alias for this crate.