Rework third-party themes (#3254)

This PR reworks the way we define our third-party themes to make them
work as overlays on top of a base theme.

We introduce the concept of a `UserThemeFamily` that contains
`UserTheme`s. Rather than being an entire theme definition on their own,
a `UserTheme` just contains optional overrides for the values in a
`Theme`.

When resolving a `UserTheme`, we apply it on top of the base theme. Any
values not overridden in the `UserTheme` will fall back to the `Theme`
defaults.

Right now we are just using `UserTheme` to model third-party themes that
we distribute with the Zed binary. However, this same structure can also
be used to import arbitrary user themes (such as from a theme registry,
or even a theme blob from the settings file).

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2023-11-07 17:40:07 +01:00 committed by GitHub
parent 9582a6f317
commit 0d95410634
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 1389 additions and 6000 deletions

View file

@ -1,182 +1,51 @@
use gpui::rgba;
use crate::{
default_color_scales, Appearance, GitStatusColors, PlayerColor, PlayerColors, StatusColors,
SyntaxTheme, SystemColors, Theme, ThemeColors, ThemeFamily, ThemeStyles,
Appearance, ThemeColorsRefinement, UserTheme, UserThemeFamily, UserThemeStylesRefinement,
};
pub fn dracula() -> ThemeFamily {
ThemeFamily {
id: "0abb0e55-f034-45d9-a84d-e880dfd65711".into(),
pub fn dracula() -> UserThemeFamily {
UserThemeFamily {
name: "Dracula".into(),
author: "Zeno Rocha".into(),
themes: vec![Theme {
id: "d20497ef-85be-4ea2-9070-a182d03aac73".into(),
themes: vec![UserTheme {
name: "Dracula".into(),
appearance: Appearance::Dark,
styles: ThemeStyles {
system: SystemColors {
transparent: rgba(0x00000000).into(),
mac_os_traffic_light_red: rgba(0xec6b5fff).into(),
mac_os_traffic_light_yellow: rgba(0xf3bf4dff).into(),
mac_os_traffic_light_green: rgba(0x61c454ff).into(),
},
colors: ThemeColors {
border: rgba(0xbd93f9ff).into(),
border_variant: rgba(0xbd93f9ff).into(),
border_focused: rgba(0xbd93f9ff).into(),
border_selected: rgba(0xbd93f9ff).into(),
border_transparent: rgba(0xbd93f9ff).into(),
border_disabled: rgba(0xbd93f9ff).into(),
elevated_surface_background: rgba(0x282a35ff).into(),
surface_background: rgba(0x282a35ff).into(),
background: rgba(0x282a35ff).into(),
element_background: rgba(0x44475aff).into(),
element_hover: rgba(0x272a2dff).into(),
element_active: rgba(0x2e3135ff).into(),
element_selected: rgba(0x2e3135ff).into(),
element_disabled: rgba(0xddeaf814).into(),
element_placeholder: rgba(0xb0b4baff).into(),
element_drop_target: rgba(0x1166fb18).into(),
ghost_element_background: rgba(0x00000000).into(),
ghost_element_hover: rgba(0x272a2dff).into(),
ghost_element_active: rgba(0x2e3135ff).into(),
ghost_element_selected: rgba(0x2e3135ff).into(),
ghost_element_disabled: rgba(0xddeaf814).into(),
text: rgba(0xf8f8f2ff).into(),
text_muted: rgba(0xb0b4baff).into(),
text_placeholder: rgba(0x767a83ff).into(),
text_disabled: rgba(0x696e77ff).into(),
text_accent: rgba(0x6fb8ffff).into(),
icon: rgba(0xb0b4baff).into(),
icon_muted: rgba(0x767a83ff).into(),
icon_disabled: rgba(0x696e77ff).into(),
icon_placeholder: rgba(0x767a83ff).into(),
icon_accent: rgba(0x6fb8ffff).into(),
status_bar_background: rgba(0x18191bff).into(),
title_bar_background: rgba(0x18191bff).into(),
toolbar_background: rgba(0x111113ff).into(),
tab_bar_background: rgba(0x18191bff).into(),
tab_inactive_background: rgba(0x21222cff).into(),
tab_active_background: rgba(0x282a35ff).into(),
editor_background: rgba(0x111113ff).into(),
editor_gutter_background: rgba(0x111113ff).into(),
editor_subheader_background: rgba(0x18191bff).into(),
editor_active_line_background: rgba(0xddeaf814).into(),
editor_highlighted_line_background: rgba(0xd3edf81d).into(),
editor_line_number: rgba(0xddeaf814).into(),
editor_active_line_number: rgba(0xddeaf814).into(),
editor_invisible: rgba(0xd3edf81d).into(),
editor_wrap_guide: rgba(0xd3edf81d).into(),
editor_active_wrap_guide: rgba(0xd3edf81d).into(),
editor_document_highlight_read_background: rgba(0xd3edf81d).into(),
editor_document_highlight_write_background: rgba(0xd3edf81d).into(),
terminal_background: rgba(0x282a35ff).into(),
terminal_ansi_bright_black: rgba(0x6272a4ff).into(),
terminal_ansi_bright_red: rgba(0xff6d6dff).into(),
terminal_ansi_bright_green: rgba(0x69ff94ff).into(),
terminal_ansi_bright_yellow: rgba(0xffffa5ff).into(),
terminal_ansi_bright_blue: rgba(0xd6abfeff).into(),
terminal_ansi_bright_magenta: rgba(0xff92dfff).into(),
terminal_ansi_bright_cyan: rgba(0xa3fefeff).into(),
terminal_ansi_bright_white: rgba(0xffffffff).into(),
terminal_ansi_black: rgba(0x21222cff).into(),
terminal_ansi_red: rgba(0xff5555ff).into(),
terminal_ansi_green: rgba(0x50fa7bff).into(),
terminal_ansi_yellow: rgba(0xf1fa8cff).into(),
terminal_ansi_blue: rgba(0xbd93f9ff).into(),
terminal_ansi_magenta: rgba(0xff79c6ff).into(),
terminal_ansi_cyan: rgba(0x8be9fdff).into(),
terminal_ansi_white: rgba(0xf8f8f2ff).into(),
},
status: StatusColors {
conflict: rgba(0xff9592ff).into(),
created: rgba(0x70cf82ff).into(),
deleted: rgba(0xff9592ff).into(),
error: rgba(0xff9592ff).into(),
hidden: rgba(0xb0b4baff).into(),
ignored: rgba(0xb0b4baff).into(),
info: rgba(0x6fb8ffff).into(),
modified: rgba(0xf5e147ff).into(),
renamed: rgba(0x6fb8ffff).into(),
success: rgba(0x70cf82ff).into(),
warning: rgba(0xf5e147ff).into(),
},
git: GitStatusColors {
conflict: rgba(0xffa057ff).into(),
created: rgba(0x70cf82ff).into(),
deleted: rgba(0xff9592ff).into(),
ignored: rgba(0xb0b4baff).into(),
modified: rgba(0xf5e147ff).into(),
renamed: rgba(0x6fb8ffff).into(),
},
player: PlayerColors(vec![
PlayerColor {
cursor: rgba(0x000000ff).into(),
background: rgba(0x000000ff).into(),
selection: rgba(0x000000ff).into(),
},
PlayerColor {
cursor: rgba(0x000000ff).into(),
background: rgba(0x000000ff).into(),
selection: rgba(0x000000ff).into(),
},
PlayerColor {
cursor: rgba(0x000000ff).into(),
background: rgba(0x000000ff).into(),
selection: rgba(0x000000ff).into(),
},
PlayerColor {
cursor: rgba(0x000000ff).into(),
background: rgba(0x000000ff).into(),
selection: rgba(0x000000ff).into(),
},
]),
syntax: SyntaxTheme {
highlights: vec![
("attribute".into(), rgba(0x4ccce6ff).into()),
("boolean".into(), rgba(0xff977dff).into()),
("comment".into(), rgba(0xb0b4baff).into()),
("comment.doc".into(), rgba(0xe0dffeff).into()),
("constant".into(), rgba(0x8c323aff).into()),
("constructor".into(), rgba(0x8c323aff).into()),
("embedded".into(), rgba(0x8c323aff).into()),
("emphasis".into(), rgba(0x8c323aff).into()),
("emphasis.strong".into(), rgba(0x8c323aff).into()),
("enum".into(), rgba(0x8c323aff).into()),
("function".into(), rgba(0x8c323aff).into()),
("hint".into(), rgba(0x8c323aff).into()),
("keyword".into(), rgba(0xffa057ff).into()),
("label".into(), rgba(0x8c323aff).into()),
("link_text".into(), rgba(0x8c323aff).into()),
("link_uri".into(), rgba(0x8c323aff).into()),
("number".into(), rgba(0x8c323aff).into()),
("operator".into(), rgba(0x8c323aff).into()),
("predictive".into(), rgba(0x8c323aff).into()),
("preproc".into(), rgba(0x8c323aff).into()),
("primary".into(), rgba(0x8c323aff).into()),
("property".into(), rgba(0x8c323aff).into()),
("punctuation".into(), rgba(0xb0b4baff).into()),
("punctuation.bracket".into(), rgba(0xb0b4baff).into()),
("punctuation.delimiter".into(), rgba(0xb0b4baff).into()),
("punctuation.list_marker".into(), rgba(0x6fb8ffff).into()),
("punctuation.special".into(), rgba(0x8c323aff).into()),
("string".into(), rgba(0x1ed8a3ff).into()),
("string.escape".into(), rgba(0x8c323aff).into()),
("string.regex".into(), rgba(0xff977dff).into()),
("string.special".into(), rgba(0x8c323aff).into()),
("string.special.symbol".into(), rgba(0x8c323aff).into()),
("tag".into(), rgba(0x8c323aff).into()),
("text.literal".into(), rgba(0x8c323aff).into()),
("title".into(), rgba(0x8c323aff).into()),
("type".into(), rgba(0x8c323aff).into()),
("variable".into(), rgba(0x8c323aff).into()),
("variable.special".into(), rgba(0x8c323aff).into()),
("variant".into(), rgba(0x8c323aff).into()),
],
styles: UserThemeStylesRefinement {
colors: ThemeColorsRefinement {
border: Some(rgba(0xbd93f9ff).into()),
border_variant: Some(rgba(0xbd93f9ff).into()),
border_focused: Some(rgba(0xbd93f9ff).into()),
border_selected: Some(rgba(0xbd93f9ff).into()),
border_transparent: Some(rgba(0xbd93f9ff).into()),
border_disabled: Some(rgba(0xbd93f9ff).into()),
elevated_surface_background: Some(rgba(0x282a35ff).into()),
surface_background: Some(rgba(0x282a35ff).into()),
background: Some(rgba(0x282a35ff).into()),
element_background: Some(rgba(0x44475aff).into()),
text: Some(rgba(0xf8f8f2ff).into()),
tab_inactive_background: Some(rgba(0x21222cff).into()),
tab_active_background: Some(rgba(0x282a35ff).into()),
terminal_background: Some(rgba(0x282a35ff).into()),
terminal_ansi_bright_black: Some(rgba(0x6272a4ff).into()),
terminal_ansi_bright_red: Some(rgba(0xff6d6dff).into()),
terminal_ansi_bright_green: Some(rgba(0x69ff94ff).into()),
terminal_ansi_bright_yellow: Some(rgba(0xffffa5ff).into()),
terminal_ansi_bright_blue: Some(rgba(0xd6abfeff).into()),
terminal_ansi_bright_magenta: Some(rgba(0xff92dfff).into()),
terminal_ansi_bright_cyan: Some(rgba(0xa3fefeff).into()),
terminal_ansi_bright_white: Some(rgba(0xffffffff).into()),
terminal_ansi_black: Some(rgba(0x21222cff).into()),
terminal_ansi_red: Some(rgba(0xff5555ff).into()),
terminal_ansi_green: Some(rgba(0x50fa7bff).into()),
terminal_ansi_yellow: Some(rgba(0xf1fa8cff).into()),
terminal_ansi_blue: Some(rgba(0xbd93f9ff).into()),
terminal_ansi_magenta: Some(rgba(0xff79c6ff).into()),
terminal_ansi_cyan: Some(rgba(0x8be9fdff).into()),
terminal_ansi_white: Some(rgba(0xf8f8f2ff).into()),
..Default::default()
},
},
}],
scales: default_color_scales(),
}
}