remove the multi-theme system

This commit is contained in:
2026-10-09 15:58:26 +07:00
parent 8e34ddabcb
commit 7dcc8033c9
25 changed files with 214 additions and 2718 deletions
+9 -89
View File
@@ -1,7 +1,5 @@
use std::ops::{Deref, DerefMut};
use std::rc::Rc;
use appearance::AppearanceMode;
use gpui::{App, Global, Pixels, SharedString, Window, px};
mod brand;
@@ -13,14 +11,13 @@ mod notification;
mod paint;
mod palette;
mod platform_kind;
mod registry;
mod scale;
mod scrollbar_mode;
mod syntax;
mod theme;
pub mod appearance;
pub use appearance::AppearanceMode;
pub use brand::{BASE_COLORS, Brand, Ink, TextInk, Tint};
pub use color::{
contrast_ratio, flatten, grey, hsl_to_rgb, lightness, mix, neutral, oklch, oklch_to_srgb,
@@ -38,8 +35,6 @@ pub use paint::{
plate_active, plate_hover, scrim, set_current_appearance, surface_shadows, wash,
};
pub use platform_kind::PlatformKind;
pub use registry::*;
pub use scale::*;
pub use scrollbar_mode::*;
pub use syntax::{HighlightKind, SyntaxPalette};
pub use theme::*;
@@ -67,13 +62,11 @@ pub const TABBAR_HEIGHT: Pixels = px(36.0);
pub const SIDEBAR_WIDTH: Pixels = px(240.);
pub fn init(cx: &mut App) {
registry::init(cx);
appearance::init(AppearanceMode::System, cx);
Theme::sync_scrollbar_appearance(cx);
}
/// An alternative palette source. Runs first on every appearance install, so
/// an override survives a light/dark switch.
/// An alternative palette source.
pub type PaletteBuilder = fn(ThemeMode) -> ThemeColors;
struct GlobalPaletteBuilder(Option<PaletteBuilder>);
@@ -82,13 +75,8 @@ impl Global for GlobalPaletteBuilder {}
/// Install a brand or an alternative palette on the app.
pub trait AppExt {
/// Install a brand and repaint. Call before [`appearance::init`] to have
/// the first frame already branded.
fn set_brand(&mut self, brand: Brand);
/// Install an alternative palette builder and repaint. The builder runs
/// first on every appearance install.
fn set_palette(&mut self, build: PaletteBuilder);
/// Change the appearance preference (`System`, `Light` or `Dark`).
fn set_appearance_mode(&mut self, mode: AppearanceMode);
}
@@ -119,13 +107,6 @@ fn reinstall(cx: &mut App) {
}
/// Mirror the active coop theme into the `gpui-base` global theme.
///
/// Base paints a few things from its own tokens -- the focus ring, the wash
/// behind selected text, scrollbars, and overlay backdrops -- so the two
/// globals have to agree or those details drift away from the palette.
///
/// This is a no-op before the coop theme global exists; [`Theme::change`] is
/// the authoritative hook that keeps the projection current.
pub fn sync_base(cx: &mut App) {
let Some(theme) = cx.try_global::<Theme>() else {
return;
@@ -163,8 +144,6 @@ pub fn sync_base(cx: &mut App) {
tokens.accent = colors.element_hover;
tokens.accent_foreground = colors.text;
tokens.destructive = colors.danger_strong;
// Bezel's destructive pairing: white ink on the red plate in both
// appearances.
tokens.destructive_foreground = gpui::white();
tokens.border = colors.border;
tokens.input = colors.border;
@@ -185,41 +164,14 @@ impl ActiveTheme for App {
#[derive(Debug, Clone)]
pub struct Theme {
/// Theme colors
pub colors: ThemeColors,
/// Theme family
pub theme: Rc<ThemeFamily>,
/// The appearance of the theme (light or dark).
pub mode: ThemeMode,
/// The font family for the application.
pub font_family: SharedString,
/// The family prose is set in — what markdown shapes a document's body
/// with. Defaults to `font_family`.
pub font_body: SharedString,
/// Monospace family for code and terminal.
pub font_mono: SharedString,
/// The root font size for the application, default is 15px.
pub font_size: Pixels,
/// Radius for the general elements.
pub radius: Pixels,
/// Radius for the large elements, e.g.: dialog, notification.
pub radius_lg: Pixels,
/// Enable shadow for the general elements. default is true
pub shadow: bool,
/// Show the scrollbar mode, default: scrolling
pub scrollbar_mode: ScrollbarMode,
/// Notification settings
pub notification: NotificationSettings,
}
@@ -269,26 +221,13 @@ impl Theme {
};
}
/// Apply a new theme to the application.
pub fn apply_theme(new_theme: Rc<ThemeFamily>, window: Option<&mut Window>, cx: &mut App) {
let theme = cx.global_mut::<Theme>();
let mode = theme.mode;
// Update the theme
theme.theme = new_theme;
// Emit a theme change event
Self::change(mode, window, cx);
}
/// Change the app's appearance
pub fn change<M>(mode: M, window: Option<&mut Window>, cx: &mut App)
where
M: Into<ThemeMode>,
{
if !cx.has_global::<Theme>() {
let default_theme = ThemeFamily::default();
let theme = Theme::from(default_theme);
cx.set_global(theme);
cx.set_global(Theme::default());
}
let mode = mode.into();
@@ -297,23 +236,13 @@ impl Theme {
.and_then(|builder| builder.0);
let mut colors = match builder {
Some(build) => build(mode),
None => {
let family = Theme::global_mut(cx).theme.clone();
if mode.is_dark() {
*family.dark()
} else {
*family.light()
}
}
None => ThemeColors::for_appearance(mode),
};
// A default brand changes nothing, so a JSON theme's own colors are
// left alone; anything else rotates the tokens and re-derives the
// legacy fields from them.
// A default brand changes nothing; anything else rotates the tokens.
let installed_brand = brand::installed(cx);
if !installed_brand.is_default() {
installed_brand.apply(mode, &mut colors);
colors.sync_legacy(mode);
}
let theme = Theme::global_mut(cx);
@@ -338,8 +267,8 @@ impl Theme {
}
}
impl From<ThemeFamily> for Theme {
fn from(family: ThemeFamily) -> Self {
impl Default for Theme {
fn default() -> Self {
let platform = PlatformKind::platform();
let mode = ThemeMode::default();
@@ -349,25 +278,16 @@ impl From<ThemeFamily> for Theme {
_ => ".SystemUIFont",
};
// Define the theme colors based on the appearance
let colors = match mode {
ThemeMode::Light => family.light(),
ThemeMode::Dark => family.dark(),
};
Theme {
Self {
font_size: px(15.),
font_family: font_family.into(),
font_body: font_family.into(),
font_mono: system_mono().into(),
radius: px(layout::button_radius()),
radius_lg: px(layout::surface_radius()),
shadow: true,
scrollbar_mode: ScrollbarMode::default(),
notification: NotificationSettings::default(),
mode,
colors: *colors,
theme: Rc::new(family),
colors: ThemeColors::for_appearance(mode),
}
}
}