Rework theme2
with new theme structure (#3194)
This PR reworks the theme definition in the `theme2` crate to be based off of the new theme work that @iamnbutler has been working on. We're still developing the new theme system, but it is complete enough that we can now load the default theme and use it to theme the storybook (albeit with some further refining of the color palette required). --------- Co-authored-by: Nate Butler <iamnbutler@gmail.com> Co-authored-by: Marshall Bowers <marshall@zed.dev>
This commit is contained in:
parent
ed5f1d3bdd
commit
18431051d9
51 changed files with 1615 additions and 494 deletions
143
crates/theme2/src/colors.rs
Normal file
143
crates/theme2/src/colors.rs
Normal file
|
@ -0,0 +1,143 @@
|
|||
use gpui2::Hsla;
|
||||
use refineable::Refineable;
|
||||
|
||||
use crate::{generate_struct_with_overrides, SyntaxStyles};
|
||||
|
||||
pub struct SystemColors {
|
||||
pub transparent: Hsla,
|
||||
pub mac_os_traffic_light_red: Hsla,
|
||||
pub mac_os_traffic_light_yellow: Hsla,
|
||||
pub mac_os_traffic_light_green: Hsla,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct PlayerColor {
|
||||
pub cursor: Hsla,
|
||||
pub background: Hsla,
|
||||
pub selection: Hsla,
|
||||
}
|
||||
|
||||
pub struct PlayerColors(pub Vec<PlayerColor>);
|
||||
|
||||
#[derive(Refineable, Clone, Debug)]
|
||||
#[refineable(debug)]
|
||||
pub struct StatusColors {
|
||||
pub conflict: Hsla,
|
||||
pub created: Hsla,
|
||||
pub deleted: Hsla,
|
||||
pub error: Hsla,
|
||||
pub hidden: Hsla,
|
||||
pub ignored: Hsla,
|
||||
pub info: Hsla,
|
||||
pub modified: Hsla,
|
||||
pub renamed: Hsla,
|
||||
pub success: Hsla,
|
||||
pub warning: Hsla,
|
||||
}
|
||||
|
||||
#[derive(Refineable, Clone, Debug)]
|
||||
#[refineable(debug)]
|
||||
pub struct GitStatusColors {
|
||||
pub conflict: Hsla,
|
||||
pub created: Hsla,
|
||||
pub deleted: Hsla,
|
||||
pub ignored: Hsla,
|
||||
pub modified: Hsla,
|
||||
pub renamed: Hsla,
|
||||
}
|
||||
|
||||
#[derive(Refineable, Clone, Debug)]
|
||||
#[refineable(debug)]
|
||||
pub struct ThemeColors {
|
||||
pub border: Hsla,
|
||||
pub border_variant: Hsla,
|
||||
pub border_focused: Hsla,
|
||||
pub border_transparent: Hsla,
|
||||
pub elevated_surface: Hsla,
|
||||
pub surface: Hsla,
|
||||
pub background: Hsla,
|
||||
pub element: Hsla,
|
||||
pub element_hover: Hsla,
|
||||
pub element_active: Hsla,
|
||||
pub element_selected: Hsla,
|
||||
pub element_disabled: Hsla,
|
||||
pub element_placeholder: Hsla,
|
||||
pub ghost_element: Hsla,
|
||||
pub ghost_element_hover: Hsla,
|
||||
pub ghost_element_active: Hsla,
|
||||
pub ghost_element_selected: Hsla,
|
||||
pub ghost_element_disabled: Hsla,
|
||||
pub text: Hsla,
|
||||
pub text_muted: Hsla,
|
||||
pub text_placeholder: Hsla,
|
||||
pub text_disabled: Hsla,
|
||||
pub text_accent: Hsla,
|
||||
pub icon: Hsla,
|
||||
pub icon_muted: Hsla,
|
||||
pub icon_disabled: Hsla,
|
||||
pub icon_placeholder: Hsla,
|
||||
pub icon_accent: Hsla,
|
||||
pub status_bar: Hsla,
|
||||
pub title_bar: Hsla,
|
||||
pub toolbar: Hsla,
|
||||
pub tab_bar: Hsla,
|
||||
pub editor: Hsla,
|
||||
pub editor_subheader: Hsla,
|
||||
pub editor_active_line: Hsla,
|
||||
}
|
||||
|
||||
generate_struct_with_overrides! {
|
||||
ThemeStyle,
|
||||
ThemeStyleOverrides,
|
||||
system: SystemColors,
|
||||
colors: ThemeColors,
|
||||
status: StatusColors,
|
||||
git: GitStatusColors,
|
||||
player: PlayerColors,
|
||||
syntax: SyntaxStyles
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn override_a_single_theme_color() {
|
||||
let mut colors = ThemeColors::default_light();
|
||||
|
||||
let magenta: Hsla = gpui2::rgb(0xff00ff);
|
||||
|
||||
assert_ne!(colors.text, magenta);
|
||||
|
||||
let overrides = ThemeColorsRefinement {
|
||||
text: Some(magenta),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
colors.refine(&overrides);
|
||||
|
||||
assert_eq!(colors.text, magenta);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn override_multiple_theme_colors() {
|
||||
let mut colors = ThemeColors::default_light();
|
||||
|
||||
let magenta: Hsla = gpui2::rgb(0xff00ff);
|
||||
let green: Hsla = gpui2::rgb(0x00ff00);
|
||||
|
||||
assert_ne!(colors.text, magenta);
|
||||
assert_ne!(colors.background, green);
|
||||
|
||||
let overrides = ThemeColorsRefinement {
|
||||
text: Some(magenta),
|
||||
background: Some(green),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
colors.refine(&overrides);
|
||||
|
||||
assert_eq!(colors.text, magenta);
|
||||
assert_eq!(colors.background, green);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue