diff --git a/crates/ui/src/theme.rs b/crates/ui/src/theme.rs index 6d7f7da7..a2f054e4 100644 --- a/crates/ui/src/theme.rs +++ b/crates/ui/src/theme.rs @@ -140,130 +140,204 @@ impl Colorize for Hsla { } } } - -#[derive(Debug, Clone, Copy)] -struct Colors { - pub title_bar: Hsla, - pub title_bar_border: Hsla, +#[derive(Debug, Clone, Copy, Default)] +pub struct ThemeColor { + pub accent: Hsla, + pub accent_foreground: Hsla, + pub accordion: Hsla, + pub accordion_active: Hsla, + pub accordion_hover: Hsla, pub background: Hsla, - pub foreground: Hsla, + pub border: Hsla, pub card: Hsla, pub card_foreground: Hsla, + pub destructive: Hsla, + pub destructive_active: Hsla, + pub destructive_foreground: Hsla, + pub destructive_hover: Hsla, + pub drag_border: Hsla, + pub drop_target: Hsla, + pub foreground: Hsla, + pub input: Hsla, + pub link: Hsla, + pub link_active: Hsla, + pub link_hover: Hsla, + pub list: Hsla, + pub list_active: Hsla, + pub list_active_border: Hsla, + pub list_even: Hsla, + pub list_head: Hsla, + pub list_hover: Hsla, + pub muted: Hsla, + pub muted_foreground: Hsla, + pub panel: Hsla, pub popover: Hsla, pub popover_foreground: Hsla, pub primary: Hsla, - pub primary_hover: Hsla, pub primary_active: Hsla, pub primary_foreground: Hsla, - pub secondary: Hsla, - pub secondary_hover: Hsla, - pub secondary_active: Hsla, - pub secondary_foreground: Hsla, - pub destructive: Hsla, - pub destructive_hover: Hsla, - pub destructive_active: Hsla, - pub destructive_foreground: Hsla, - pub muted: Hsla, - pub muted_foreground: Hsla, - pub accent: Hsla, - pub accent_foreground: Hsla, - pub border: Hsla, - pub input: Hsla, + pub primary_hover: Hsla, + pub progress_bar: Hsla, pub ring: Hsla, - pub selection: Hsla, pub scrollbar: Hsla, pub scrollbar_thumb: Hsla, - pub panel: Hsla, + pub secondary: Hsla, + pub secondary_active: Hsla, + pub secondary_foreground: Hsla, + pub secondary_hover: Hsla, + pub selection: Hsla, + pub skeleton: Hsla, + pub slider_bar: Hsla, + pub slider_thumb: Hsla, + pub tab: Hsla, + pub tab_active: Hsla, + pub tab_active_foreground: Hsla, pub tab_bar: Hsla, - pub list: Hsla, - pub list_even: Hsla, - pub list_head: Hsla, - pub link: Hsla, - pub drop_target: Hsla, + pub tab_foreground: Hsla, + pub table: Hsla, + pub table_active: Hsla, + pub table_active_border: Hsla, + pub table_even: Hsla, + pub table_head: Hsla, + pub table_head_foreground: Hsla, + pub table_hover: Hsla, + pub table_row_border: Hsla, + pub title_bar: Hsla, + pub title_bar_border: Hsla, } -impl Colors { - fn light() -> Colors { - Colors { - title_bar: hsl(0.0, 0.0, 100.), - title_bar_border: hsl(240.0, 5.9, 90.0), +impl ThemeColor { + pub fn light() -> Self { + Self { + accent: hsl(240.0, 5.0, 96.0), + accent_foreground: hsl(240.0, 5.9, 10.0), + accordion: hsl(0.0, 0.0, 100.0), + accordion_active: hsl(240.0, 5.9, 90.0), + accordion_hover: hsl(240.0, 4.8, 95.9).opacity(0.7), background: hsl(0.0, 0.0, 100.), - foreground: hsl(240.0, 10., 3.9), + border: hsl(240.0, 5.9, 90.0), card: hsl(0.0, 0.0, 100.0), card_foreground: hsl(240.0, 10.0, 3.9), + destructive: hsl(0.0, 84.2, 60.2), + destructive_active: hsl(0.0, 84.2, 47.0), + destructive_foreground: hsl(0.0, 0.0, 98.0), + destructive_hover: hsl(0.0, 84.2, 65.0), + drag_border: crate::blue_500(), + drop_target: hsl(235.0, 30., 44.0).opacity(0.25), + foreground: hsl(240.0, 10., 3.9), + input: hsl(240.0, 5.9, 90.0), + link: hsl(221.0, 83.0, 53.0), + link_active: hsl(221.0, 83.0, 53.0).darken(0.2), + link_hover: hsl(221.0, 83.0, 53.0).lighten(0.2), + list: hsl(0.0, 0.0, 100.), + list_active: hsl(211.0, 97.0, 85.0).opacity(0.2), + list_active_border: hsl(211.0, 97.0, 85.0), + list_even: hsl(240.0, 5.0, 96.0), + list_head: hsl(0.0, 0.0, 100.), + list_hover: hsl(211.0, 97.0, 85.0).opacity(0.2), + muted: hsl(240.0, 4.8, 95.9), + muted_foreground: hsl(240.0, 3.8, 46.1), + panel: hsl(0.0, 0.0, 100.0), popover: hsl(0.0, 0.0, 100.0), popover_foreground: hsl(240.0, 10.0, 3.9), primary: hsl(223.0, 5.9, 10.0), - primary_hover: hsl(223.0, 5.9, 15.0), primary_active: hsl(223.0, 1.9, 25.0), primary_foreground: hsl(223.0, 0.0, 98.0), - secondary: hsl(240.0, 5.9, 96.9), - secondary_hover: hsl(240.0, 5.9, 98.), - secondary_active: hsl(240.0, 5.9, 93.), - secondary_foreground: hsl(240.0, 59.0, 10.), - destructive: hsl(0.0, 84.2, 60.2), - destructive_hover: hsl(0.0, 84.2, 65.0), - destructive_active: hsl(0.0, 84.2, 47.0), - destructive_foreground: hsl(0.0, 0.0, 98.0), - muted: hsl(240.0, 4.8, 95.9), - muted_foreground: hsl(240.0, 3.8, 46.1), - accent: hsl(240.0, 5.0, 96.0), - accent_foreground: hsl(240.0, 5.9, 10.0), - border: hsl(240.0, 5.9, 90.0), - input: hsl(240.0, 5.9, 90.0), + primary_hover: hsl(223.0, 5.9, 15.0), + progress_bar: hsl(223.0, 5.9, 10.0), ring: hsl(240.0, 5.9, 65.0), - selection: hsl(211.0, 97.0, 85.0), scrollbar: hsl(0., 0., 97.).opacity(0.3), scrollbar_thumb: hsl(0., 0., 69.), - panel: hsl(0.0, 0.0, 100.0), + secondary: hsl(240.0, 5.9, 96.9), + secondary_active: hsl(240.0, 5.9, 93.), + secondary_foreground: hsl(240.0, 59.0, 10.), + secondary_hover: hsl(240.0, 5.9, 98.), + selection: hsl(211.0, 97.0, 85.0), + skeleton: hsla(223.0, 5.9, 10.0, 0.1), + slider_bar: hsl(223.0, 5.9, 10.0), + slider_thumb: hsl(0.0, 0.0, 100.0), + tab: gpui::transparent_black(), + tab_active: hsl(0.0, 0.0, 100.0), + tab_active_foreground: hsl(240.0, 10., 3.9), tab_bar: hsl(240.0, 4.8, 95.9), - list: hsl(0.0, 0.0, 100.), - list_even: hsl(240.0, 5.0, 96.0), - list_head: hsl(0.0, 0.0, 100.), - link: hsl(221.0, 83.0, 53.0), - drop_target: hsl(235.0, 30., 44.0).opacity(0.25), + tab_foreground: hsl(240.0, 10., 3.9), + table: hsl(0.0, 0.0, 100.), + table_active: hsl(211.0, 97.0, 85.0).opacity(0.2), + table_active_border: hsl(211.0, 97.0, 85.0), + table_even: hsl(240.0, 5.0, 96.0), + table_head: hsl(0.0, 0.0, 100.), + table_head_foreground: hsl(240.0, 10., 3.9).opacity(0.7), + table_hover: hsl(211.0, 97.0, 85.0).opacity(0.2), + table_row_border: hsl(240.0, 5.9, 90.0).opacity(0.5), + title_bar: hsl(0.0, 0.0, 100.), + title_bar_border: hsl(240.0, 5.9, 90.0), } } - fn dark() -> Colors { - Colors { - title_bar: hsl(0., 0., 9.7), - title_bar_border: hsl(240.0, 3.7, 15.9), + pub fn dark() -> Self { + Self { + accent: hsl(240.0, 3.7, 15.9), + accent_foreground: hsl(0.0, 0.0, 78.0), + accordion: hsl(299.0, 2., 11.), + accordion_active: hsl(240.0, 3.7, 16.9), + accordion_hover: hsl(240.0, 3.7, 15.9).opacity(0.7), background: hsl(0.0, 0.0, 8.0), - foreground: hsl(0., 0., 78.), + border: hsl(240.0, 3.7, 16.9), card: hsl(299.0, 2., 11.), card_foreground: hsl(0.0, 0.0, 78.0), + destructive: hsl(0.0, 62.8, 30.6), + destructive_active: hsl(0.0, 62.8, 20.6), + destructive_foreground: hsl(0.0, 0.0, 78.0), + destructive_hover: hsl(0.0, 62.8, 35.6), + drag_border: crate::blue_500(), + drop_target: hsl(235.0, 30., 44.0).opacity(0.1), + foreground: hsl(0., 0., 78.), + input: hsl(240.0, 3.7, 15.9), + link: hsl(221.0, 83.0, 53.0), + link_active: hsl(221.0, 83.0, 53.0).darken(0.2), + link_hover: hsl(221.0, 83.0, 53.0).lighten(0.2), + list: hsl(0.0, 0.0, 8.0), + list_active: hsl(211.0, 97.0, 22.0).opacity(0.2), + list_active_border: hsl(211.0, 97.0, 22.0), + list_even: hsl(240.0, 3.7, 10.0), + list_head: hsl(0.0, 0.0, 8.0), + list_hover: hsl(211.0, 97.0, 22.0).opacity(0.2), + muted: hsl(240.0, 3.7, 15.9), + muted_foreground: hsl(240.0, 5.0, 64.9), + panel: hsl(299.0, 2., 11.), popover: hsl(0.0, 0.0, 10.), popover_foreground: hsl(0.0, 0.0, 78.0), primary: hsl(223.0, 0.0, 98.0), - primary_hover: hsl(223.0, 0.0, 90.0), primary_active: hsl(223.0, 0.0, 80.0), primary_foreground: hsl(223.0, 5.9, 10.0), - secondary: hsl(240.0, 0., 13.0), - secondary_hover: hsl(240.0, 0., 15.), - secondary_active: hsl(240.0, 0., 10.), - secondary_foreground: hsl(0.0, 0.0, 78.0), - destructive: hsl(0.0, 62.8, 30.6), - destructive_hover: hsl(0.0, 62.8, 35.6), - destructive_active: hsl(0.0, 62.8, 20.6), - destructive_foreground: hsl(0.0, 0.0, 78.0), - muted: hsl(240.0, 3.7, 15.9), - muted_foreground: hsl(240.0, 5.0, 64.9), - accent: hsl(240.0, 3.7, 15.9), - accent_foreground: hsl(0.0, 0.0, 78.0), - border: hsl(240.0, 3.7, 16.9), - input: hsl(240.0, 3.7, 15.9), + primary_hover: hsl(223.0, 0.0, 90.0), + progress_bar: hsl(223.0, 0.0, 98.0), ring: hsl(240.0, 4.9, 83.9), - selection: hsl(211.0, 97.0, 22.0), scrollbar: hsl(240., 1., 15.).opacity(0.3), scrollbar_thumb: hsl(0., 0., 68.), - panel: hsl(299.0, 2., 11.), + secondary: hsl(240.0, 0., 13.0), + secondary_active: hsl(240.0, 0., 10.), + secondary_foreground: hsl(0.0, 0.0, 78.0), + secondary_hover: hsl(240.0, 0., 15.), + selection: hsl(211.0, 97.0, 22.0), + skeleton: hsla(223.0, 0.0, 98.0, 0.1), + slider_bar: hsl(223.0, 0.0, 98.0), + slider_thumb: hsl(0.0, 0.0, 8.0), + tab: gpui::transparent_black(), + tab_active: hsl(0.0, 0.0, 8.0), + tab_active_foreground: hsl(0., 0., 78.), tab_bar: hsl(299.0, 0., 5.5), - list: hsl(0.0, 0.0, 8.0), - list_even: hsl(240.0, 3.7, 10.0), - list_head: hsl(0.0, 0.0, 8.0), - link: hsl(221.0, 83.0, 53.0), - drop_target: hsl(235.0, 30., 44.0).opacity(0.1), + tab_foreground: hsl(0., 0., 78.), + table: hsl(0.0, 0.0, 8.0), + table_active: hsl(211.0, 97.0, 22.0).opacity(0.2), + table_active_border: hsl(211.0, 97.0, 22.0), + table_even: hsl(240.0, 3.7, 10.0), + table_head: hsl(0.0, 0.0, 8.0), + table_head_foreground: hsl(0., 0., 78.).opacity(0.7), + table_hover: hsl(211.0, 97.0, 22.0).opacity(0.2), + table_row_border: hsl(240.0, 3.7, 16.9).opacity(0.5), + title_bar: hsl(0., 0., 9.7), + title_bar_border: hsl(240.0, 3.7, 15.9), } } } @@ -271,75 +345,73 @@ impl Colors { #[derive(Debug, Clone)] pub struct Theme { pub mode: ThemeMode, - pub transparent: Hsla, - pub title_bar: Hsla, - pub title_bar_border: Hsla, - /// Basic font size - pub font_size: f32, - pub font_family: SharedString, + pub accent: Hsla, + pub accent_foreground: Hsla, + pub accordion: Hsla, + pub accordion_active: Hsla, + pub accordion_hover: Hsla, pub background: Hsla, - pub foreground: Hsla, + pub border: Hsla, pub card: Hsla, pub card_foreground: Hsla, + pub destructive: Hsla, + pub destructive_active: Hsla, + pub destructive_foreground: Hsla, + pub destructive_hover: Hsla, + pub drag_border: Hsla, + pub drop_target: Hsla, + pub font_family: SharedString, + pub font_size: f32, + pub foreground: Hsla, + pub input: Hsla, + pub link: Hsla, + pub link_active: Hsla, + pub link_hover: Hsla, + pub list: Hsla, + pub list_active: Hsla, + pub list_active_border: Hsla, + pub list_even: Hsla, + pub list_head: Hsla, + pub list_hover: Hsla, + pub muted: Hsla, + pub muted_foreground: Hsla, + pub panel: Hsla, pub popover: Hsla, pub popover_foreground: Hsla, pub primary: Hsla, - pub primary_hover: Hsla, pub primary_active: Hsla, pub primary_foreground: Hsla, - pub secondary: Hsla, - pub secondary_hover: Hsla, - pub secondary_active: Hsla, - pub secondary_foreground: Hsla, - pub destructive: Hsla, - pub destructive_hover: Hsla, - pub destructive_active: Hsla, - pub destructive_foreground: Hsla, - pub muted: Hsla, - pub muted_foreground: Hsla, - pub accent: Hsla, - pub accent_foreground: Hsla, - pub border: Hsla, - pub input: Hsla, + pub primary_hover: Hsla, + pub progress_bar: Hsla, + pub radius: f32, pub ring: Hsla, - /// Set to true to enable shadow for Button, Input, Dropdown, DatePicker ... - pub shadow: bool, - pub selection: Hsla, pub scrollbar: Hsla, pub scrollbar_thumb: Hsla, - pub panel: Hsla, - pub drag_border: Hsla, - pub drop_target: Hsla, - pub radius: f32, - pub tab_bar: Hsla, - pub tab: Hsla, - pub tab_active: Hsla, - pub tab_foreground: Hsla, - pub tab_active_foreground: Hsla, - pub progress_bar: Hsla, + pub secondary: Hsla, + pub secondary_active: Hsla, + pub secondary_foreground: Hsla, + pub secondary_hover: Hsla, + pub selection: Hsla, + pub shadow: bool, + pub skeleton: Hsla, pub slider_bar: Hsla, pub slider_thumb: Hsla, - pub list: Hsla, - pub list_even: Hsla, - pub list_head: Hsla, - pub list_active: Hsla, - pub list_active_border: Hsla, - pub list_hover: Hsla, + pub tab: Hsla, + pub tab_active: Hsla, + pub tab_active_foreground: Hsla, + pub tab_bar: Hsla, + pub tab_foreground: Hsla, pub table: Hsla, + pub table_active: Hsla, + pub table_active_border: Hsla, pub table_even: Hsla, pub table_head: Hsla, pub table_head_foreground: Hsla, - pub table_row_border: Hsla, - pub table_active: Hsla, - pub table_active_border: Hsla, pub table_hover: Hsla, - pub link: Hsla, - pub link_hover: Hsla, - pub link_active: Hsla, - pub skeleton: Hsla, - pub accordion: Hsla, - pub accordion_hover: Hsla, - pub accordion_active: Hsla, + pub table_row_border: Hsla, + pub title_bar: Hsla, + pub title_bar_border: Hsla, + pub transparent: Hsla, } impl Global for Theme {} @@ -349,6 +421,7 @@ impl Theme { cx.global::() } + /// Apply a mask color to the theme. pub fn apply_color(&mut self, mask_color: Hsla) { self.title_bar = self.title_bar.apply(mask_color); self.title_bar_border = self.title_bar_border.apply(mask_color); @@ -415,8 +488,8 @@ impl Theme { } } -impl From for Theme { - fn from(colors: Colors) -> Self { +impl From for Theme { + fn from(colors: ThemeColor) -> Self { Theme { mode: ThemeMode::default(), transparent: Hsla::transparent_black(), @@ -430,68 +503,68 @@ impl From for Theme { }, radius: 4.0, shadow: true, - title_bar: colors.title_bar, - title_bar_border: colors.title_bar_border, + accent: colors.accent, + accent_foreground: colors.accent_foreground, + accordion: colors.accordion, + accordion_active: colors.accordion_active, + accordion_hover: colors.accordion_hover, background: colors.background, - foreground: colors.foreground, + border: colors.border, card: colors.card, card_foreground: colors.card_foreground, + destructive: colors.destructive, + destructive_active: colors.destructive_active, + destructive_foreground: colors.destructive_foreground, + destructive_hover: colors.destructive_hover, + drag_border: colors.drag_border, + drop_target: colors.drop_target, + foreground: colors.foreground, + input: colors.input, + link: colors.link, + link_active: colors.link_active, + link_hover: colors.link_hover, + list: colors.list, + list_active: colors.list_active, + list_active_border: colors.list_active_border, + list_even: colors.list_even, + list_head: colors.list_head, + list_hover: colors.list_hover, + muted: colors.muted, + muted_foreground: colors.muted_foreground, + panel: colors.panel, popover: colors.popover, popover_foreground: colors.popover_foreground, primary: colors.primary, - primary_hover: colors.primary_hover, primary_active: colors.primary_active, primary_foreground: colors.primary_foreground, - secondary: colors.secondary, - secondary_hover: colors.secondary_hover, - secondary_active: colors.secondary_active, - secondary_foreground: colors.secondary_foreground, - destructive: colors.destructive, - destructive_hover: colors.destructive_hover, - destructive_active: colors.destructive_active, - destructive_foreground: colors.destructive_foreground, - muted: colors.muted, - muted_foreground: colors.muted_foreground, - accent: colors.accent, - accent_foreground: colors.accent_foreground, - border: colors.border, - input: colors.input, + primary_hover: colors.primary_hover, + progress_bar: colors.progress_bar, ring: colors.ring, scrollbar: colors.scrollbar, scrollbar_thumb: colors.scrollbar_thumb, - panel: colors.panel, + secondary: colors.secondary, + secondary_active: colors.secondary_active, + secondary_foreground: colors.secondary_foreground, + secondary_hover: colors.secondary_hover, selection: colors.selection, - drag_border: crate::blue_500(), - drop_target: colors.drop_target, + skeleton: colors.skeleton, + slider_bar: colors.slider_bar, + slider_thumb: colors.slider_thumb, + tab: colors.tab, + tab_active: colors.tab_active, + tab_active_foreground: colors.tab_active_foreground, tab_bar: colors.tab_bar, - tab: gpui::transparent_black(), - tab_active: colors.background, - tab_foreground: colors.foreground, - tab_active_foreground: colors.foreground, - progress_bar: colors.primary, - slider_bar: colors.primary, - slider_thumb: colors.background, - list: colors.list, - list_even: colors.list_even, - list_head: colors.list_head, - list_active: colors.selection.opacity(0.2), - list_active_border: colors.selection, - list_hover: colors.selection.opacity(0.2), - table_head: colors.list_head, - table: colors.list, - table_even: colors.list_even, - table_active: colors.selection.opacity(0.2), - table_active_border: colors.selection, - table_hover: colors.selection.opacity(0.2), - table_row_border: colors.border.opacity(0.5), - table_head_foreground: colors.foreground.opacity(0.7), - link: colors.link, - link_hover: colors.link.lighten(0.2), - link_active: colors.link.darken(0.2), - skeleton: hsla(colors.primary.h, colors.primary.s, colors.primary.l, 0.1), - accordion: colors.background, - accordion_hover: colors.tab_bar.opacity(0.7), - accordion_active: colors.tab_bar, + tab_foreground: colors.tab_foreground, + table: colors.table, + table_active: colors.table_active, + table_active_border: colors.table_active_border, + table_even: colors.table_even, + table_head: colors.table_head, + table_head_foreground: colors.table_head_foreground, + table_hover: colors.table_hover, + table_row_border: colors.table_row_border, + title_bar: colors.title_bar, + title_bar_border: colors.title_bar_border, } } } @@ -524,8 +597,8 @@ impl Theme { pub fn change(mode: ThemeMode, cx: &mut AppContext) { let colors = match mode { - ThemeMode::Light => Colors::light(), - ThemeMode::Dark => Colors::dark(), + ThemeMode::Light => ThemeColor::light(), + ThemeMode::Dark => ThemeColor::dark(), }; let mut theme = Theme::from(colors);