Skip to main content

to_theme

Function to_theme 

Source
pub fn to_theme(
    resolved: &ResolvedThemeVariant,
    name: &str,
    is_dark: bool,
) -> Theme
Expand description

Convert a ResolvedThemeVariant into a gpui-component Theme.

Builds a complete Theme by:

  1. Mapping all 108 ThemeColor fields via colors::to_theme_color
  2. Setting font, geometry, and mode fields directly on the Theme
  3. Storing a ThemeConfig in light_theme/dark_theme Rc for gpui-component switching

All Theme fields are set explicitly – no apply_config call is used. This avoids the fragile apply-then-restore pattern where apply_config would overwrite all 108 color fields with defaults.

The is_dark parameter is required rather than auto-derived because several presets (e.g. solarized, gruvbox) have borderline lightness values where auto-detection would disagree with the user’s intent. To auto-derive: let is_dark = resolved.defaults.background_color lightness < 0.5 via is_dark_resolved().

Note: is_dark is an explicit parameter here, unlike the iced connector which derives it from background luminance. Planned for unification in v0.6.0.