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).unwrap();

Or from the OS-detected theme:

use native_theme_iced::from_system;

let (theme, resolved, is_dark) = from_system().unwrap();

§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 (_, resolved) = native_theme_iced::from_preset("catppuccin-mocha", true).unwrap();
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 (8)secondary.base.color/text, background.weak.color/text, primary/success/danger/warning.base.textbutton.bg/fg, defaults.surface/foreground, *_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.*
Color helpersborder, link, selection, info, info_foreground, warning_foreground, focus_ringdefaults.*
Geometry helpersspacing (7 tiers), icon_sizes, disabled_opacitydefaults.*

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§

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.
DialogButtonOrder
Specifies the order of primary/cancel buttons in dialogs.
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.
LinuxDesktop
Desktop environments recognized on Linux.
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_color
Returns the border/divider color from the resolved theme.
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.
disabled_opacity
Returns the disabled control opacity from the resolved theme.
focus_ring_color
Returns the focus ring indicator color from the resolved theme.
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.
icon_sizes
Returns a reference to the per-context icon sizes from the resolved theme.
info_color
Returns the info/attention color from the resolved theme.
info_foreground_color
Returns the text color for info-colored backgrounds from the resolved theme.
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.
link_color
Returns the hyperlink color 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 groove width from the resolved theme.
selection_color
Returns the selection highlight background color 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.
warning_foreground_color
Returns the warning foreground text color from the resolved theme.

Type Aliases§

Result
Convenience Result type alias for this crate.