hyuskui

Theming

One global struct controls every color and radius.

Components never hardcode colors. They read them from the Theme global through cx.theme(). Change a token and every component follows.

Tokens

background / foregroundThe window surface and default text.
card / card_foregroundRaised surfaces such as Card and Alert.
primary / primary_foregroundThe main action color, used by the default Button.
secondary / secondary_foregroundLower-emphasis actions.
muted / muted_foregroundSubtle fills and secondary text.
accent / accent_foregroundHover fills for ghost and outline controls.
destructive / destructive_foregroundDangerous actions and errors.
border / input / ringOutlines, form borders and the focus ring.
radiusThe base corner radius. Cards use radius × 1.5.

Light and dark

Theme::light() and Theme::dark() ship by default. Swap the global and refresh to change modes at runtime:

use gpui::App;
use crate::theme::{ActiveTheme, Theme};

fn toggle_dark_mode(cx: &mut App) {
    let dark = cx.theme().background.l < 0.5;
    cx.set_global(if dark { Theme::light() } else { Theme::dark() });
    cx.refresh_windows();
}

Your own theme

Start from a built-in theme and override only what you need:

impl Theme {
    pub fn ember() -> Self {
        Self {
            primary: c(18.0, 88.0, 54.0),
            primary_foreground: c(0.0, 0.0, 100.0),
            radius: px(12.0),
            ..Self::light()
        }
    }
}