Skip to main content

Crate native_theme_gpui

Crate native_theme_gpui 

Source
Expand description

gpui toolkit connector for native-theme.

Maps native_theme::ResolvedThemeVariant data to gpui-component’s theming system.

§Quick Start

use native_theme_gpui::from_preset;

let (theme, resolved) = from_preset("catppuccin-mocha", true)?;

Or from the OS-detected theme:

use native_theme_gpui::from_system;

let (theme, resolved, is_dark) = from_system()?;

§Manual Path

For full control over the resolve/validate/convert pipeline:

use native_theme::ThemeSpec;
use native_theme_gpui::to_theme;

let nt = ThemeSpec::preset("catppuccin-mocha")?;
let variant = nt.into_variant(true).ok_or("no dark variant")?;
let resolved = variant.into_resolved()?;
let theme = to_theme(&resolved, "Catppuccin Mocha", true);

§Single-Mode Behavior

Each call to from_preset() or to_theme() produces a theme for exactly one mode (light or dark). The is_dark parameter selects which variant to load from the preset’s TOML. Presets that only define one variant will return that variant for both is_dark=true and is_dark=false (the resolution pipeline falls back to the available variant). To support runtime light/dark switching, call from_preset() twice and swap the resulting themes.

§Theme Field Coverage

The connector maps a subset of ResolvedThemeVariant fields to gpui-component’s ThemeColor (108 color fields) and ThemeConfig (font/geometry).

CategoryMappedNotes
defaults colorsAll 20+background, foreground, accent, danger, etc.
defaults geometryradius, radius_lg, shadowFont family/size also mapped
button4 of 14primary_background/foreground, background/foreground (colors only)
tab5 of 9All colors, sizing not mapped
sidebar2 of 2background, foreground
window2 of 10title_bar_background, border
input2 of 12border, caret
scrollbar3 of 7track, thumb, thumb_hover
slider, switch2 eachfill/thumb colors
progress_bar1 of 5fill
list1 of 11alternate_row
popover2 of 4background, foreground
14 other widgets0 fieldscheckbox, menu, tooltip, dialog, etc.

Why the gap: gpui-component’s ThemeColor is a flat color bag with no per-widget geometry. The connector cannot map most sizing/spacing data because the target type has no corresponding fields. Users who need per-widget geometry can read it directly from the ResolvedThemeVariant they passed to to_theme().

Modules§

icons
Icon conversion functions for the gpui connector.

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 a gpui-component Theme.

Functions§

border_opacity
Border opacity multiplier from the resolved theme defaults.
dialog_button_order
The platform-appropriate dialog button order.
dialog_button_spacing
Dialog button gap in logical pixels.
dialog_content_padding
Dialog content padding in logical pixels.
disabled_foreground
Foreground color for disabled elements.
disabled_opacity
Disabled control opacity from the resolved theme defaults.
focus_ring_offset
Gap between element edge and focus ring.
focus_ring_width
Focus ring stroke width in logical pixels.
font_weight
Default font weight from the resolved theme.
frame_width
Frame/border width from the resolved theme defaults.
from_preset
Load a bundled preset and convert it to a gpui-component Theme in one call.
from_system
Detect the OS theme and convert it to a gpui-component Theme in one call.
icon_sizes
Access the per-context icon sizes from the resolved theme.
is_dark
Returns true if the resolved theme is considered dark.
is_dark_resolved
Derive is_dark from a ResolvedThemeVariant’s background lightness.
is_high_contrast
Whether the theme is in high-contrast mode.
is_reduced_motion
Whether the user/theme has requested reduced motion.
is_reduced_transparency
Whether the user/theme has requested reduced transparency.
line_height_multiplier
Line height multiplier from the resolved theme defaults.
mono_font_weight
Monospace font weight from the resolved theme.
scrollbar_width
Scrollbar groove width in logical pixels.
selection_foreground
Selection text color (foreground for selected content).
selection_inactive
Selection background when window is unfocused.
shadow_enabled
Whether drop shadows are enabled.
text_scale
Access the text scale entries from the resolved theme.
text_scaling_factor
Text scaling factor (1.0 = no scaling).
to_theme
Convert a ResolvedThemeVariant into a gpui-component Theme.

Type Aliases§

Result
Convenience Result type alias for this crate.