native-theme
Cross-platform native theme detection and loading for Rust GUI applications.
Overview
native-theme provides a toolkit-agnostic theme data model with 36 semantic color roles, bundled TOML presets, and optional OS theme reading. It gives your Rust GUI application access to consistent, structured theme data regardless of which toolkit you use.
Quick Start
Add the dependency:
Load a preset and access theme fields:
let theme = preset.unwrap;
let dark = theme.dark.as_ref.unwrap;
let accent = dark.colors.accent.unwrap;
let bg = dark.colors.background.unwrap;
// Convert to f32 for toolkits that use normalized colors
let = accent.to_f32_array;
Preset Workflow
Start with a bundled preset, then layer sparse user overrides on top.
The merge() method fills in only the fields present in the overlay,
leaving everything else from the base preset intact.
use NativeTheme;
let mut theme = preset.unwrap;
let user_overrides = from_toml.unwrap;
theme.merge;
Runtime Workflow
Use from_system() to read the current OS theme at runtime, with a preset
fallback for unsupported platforms:
use ;
let theme = from_system.unwrap_or_else;
Platform behavior:
- Linux (KDE): Reads live theme from
~/.config/kdeglobals(requireskdefeature). - Linux (GNOME/other): Returns the bundled Adwaita preset. For live
portal data (accent color, dark mode preference, contrast setting), call
from_gnome().awaitdirectly -- this requires theportal-tokioorportal-async-iofeature. - macOS: Reads system appearance via NSAppearance (requires
macosfeature). - Windows: Reads accent colors and system metrics (requires
windowsfeature). - Other platforms: Returns
Error::Unsupported; use the preset fallback.
Toolkit Connectors
Official connector crates handle the full mapping from NativeTheme to
toolkit-specific theme types:
native-theme-iced-- iced toolkit connector with Catalog support for all built-in widget stylesnative-theme-gpui-- gpui + gpui-component toolkit connector
For other toolkits, map NativeTheme fields directly. All color, font,
geometry, and spacing fields are public Option<T> values:
let variant = theme.dark.as_ref.unwrap;
let bg = variant.colors.background.unwrap;
let accent = variant.colors.accent.unwrap;
let font = variant.fonts.family.as_deref.unwrap_or;
let radius = variant.geometry.radius.unwrap_or;
Custom Icon Roles
Apps can define domain-specific icons (e.g., play/pause, git-branch, thermometer)
via TOML definitions and the native-theme-build
crate. Generated icons integrate with the same loading pipeline as built-in
IconRole variants, so they work across all icon sets (Material, Lucide,
freedesktop, SF Symbols, Segoe Fluent).
Workflow:
- Define icons in a TOML file with per-set name mappings and bundled SVGs
- Add
native-theme-buildas a build dependency - Call
generate_icons()inbuild.rsto generate a Rust enum implementingIconProvider - Include the generated code and use
load_custom_icon()to load icons at runtime
// build.rs
generate_icons;
// src/lib.rs
include!;
use ;
let icon = load_custom_icon;
See the native-theme-build docs for the
full TOML schema, builder API, and DE-aware mapping support.
Feature Flags
| Feature | Enables | Platform |
|---|---|---|
kde |
from_kde() sync KDE reader |
Linux |
portal |
Base for GNOME portal reader | Linux |
portal-tokio |
from_gnome() with tokio runtime |
Linux |
portal-async-io |
from_gnome() with async-io runtime |
Linux |
windows |
from_windows() Windows reader |
Windows |
macos |
from_macos() macOS reader |
macOS |
system-icons |
Platform icon theme lookup with bundled fallback | All |
material-icons |
Bundle Material Symbols SVGs | All |
lucide-icons |
Bundle Lucide SVGs | All |
svg-rasterize |
SVG-to-RGBA rasterization via resvg | All |
By default, no features are enabled. The preset API (NativeTheme::preset(),
NativeTheme::from_toml(), NativeTheme::from_file(), NativeTheme::list_presets(),
.to_toml()) works without any features.
Available Presets
All presets are embedded at compile time via include_str!() and available
through NativeTheme::preset("name"). Each provides both light and dark variants.
Core: default, adwaita, kde-breeze
Platform: windows-11, macos-sonoma, material, ios
Community: catppuccin-latte, catppuccin-frappe, catppuccin-macchiato,
catppuccin-mocha, nord, dracula, gruvbox, solarized, tokyo-night,
one-dark
Use NativeTheme::list_presets() to get all 17 names programmatically.
TOML Format
Theme files use TOML. All fields are optional -- omit any you don't need.
See the NativeTheme::from_toml()
documentation for the full format reference.
License
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.