theme.rs

  1mod theme_registry;
  2
  3use gpui::{
  4    color::Color,
  5    elements::{ContainerStyle, ImageStyle, LabelStyle, Shadow, TooltipStyle},
  6    fonts::{HighlightStyle, TextStyle},
  7    Border, MouseState,
  8};
  9use serde::{de::DeserializeOwned, Deserialize};
 10use serde_json::Value;
 11use std::{collections::HashMap, sync::Arc};
 12use ui::{ButtonStyle, CheckboxStyle, IconStyle, ModalStyle, SvgStyle};
 13
 14pub mod ui;
 15
 16pub use theme_registry::*;
 17
 18#[derive(Deserialize, Default)]
 19pub struct Theme {
 20    #[serde(default)]
 21    pub meta: ThemeMeta,
 22    pub workspace: Workspace,
 23    pub context_menu: ContextMenu,
 24    pub contacts_popover: ContactsPopover,
 25    pub contact_list: ContactList,
 26    pub copilot: Copilot,
 27    pub contact_finder: ContactFinder,
 28    pub project_panel: ProjectPanel,
 29    pub command_palette: CommandPalette,
 30    pub picker: Picker,
 31    pub editor: Editor,
 32    pub search: Search,
 33    pub project_diagnostics: ProjectDiagnostics,
 34    pub breadcrumbs: ContainedText,
 35    pub shared_screen: ContainerStyle,
 36    pub contact_notification: ContactNotification,
 37    pub update_notification: UpdateNotification,
 38    pub simple_message_notification: MessageNotification,
 39    pub project_shared_notification: ProjectSharedNotification,
 40    pub incoming_call_notification: IncomingCallNotification,
 41    pub tooltip: TooltipStyle,
 42    pub terminal: TerminalStyle,
 43    pub feedback: FeedbackStyle,
 44    pub welcome: WelcomeStyle,
 45    pub color_scheme: ColorScheme,
 46}
 47
 48#[derive(Deserialize, Default, Clone)]
 49pub struct ThemeMeta {
 50    pub name: String,
 51    pub is_light: bool,
 52}
 53
 54#[derive(Deserialize, Default)]
 55pub struct Workspace {
 56    pub background: Color,
 57    pub blank_pane: BlankPaneStyle,
 58    pub titlebar: Titlebar,
 59    pub tab_bar: TabBar,
 60    pub pane_divider: Border,
 61    pub leader_border_opacity: f32,
 62    pub leader_border_width: f32,
 63    pub sidebar: Sidebar,
 64    pub status_bar: StatusBar,
 65    pub toolbar: Toolbar,
 66    pub disconnected_overlay: ContainedText,
 67    pub modal: ContainerStyle,
 68    pub notification: ContainerStyle,
 69    pub notifications: Notifications,
 70    pub joining_project_avatar: ImageStyle,
 71    pub joining_project_message: ContainedText,
 72    pub external_location_message: ContainedText,
 73    pub dock: Dock,
 74    pub drop_target_overlay_color: Color,
 75}
 76
 77#[derive(Clone, Deserialize, Default)]
 78pub struct BlankPaneStyle {
 79    pub logo: SvgStyle,
 80    pub logo_shadow: SvgStyle,
 81    pub logo_container: ContainerStyle,
 82    pub keyboard_hints: ContainerStyle,
 83    pub keyboard_hint: Interactive<ContainedText>,
 84    pub keyboard_hint_width: f32,
 85}
 86
 87#[derive(Clone, Deserialize, Default)]
 88pub struct Titlebar {
 89    #[serde(flatten)]
 90    pub container: ContainerStyle,
 91    pub height: f32,
 92    pub title: TextStyle,
 93    pub item_spacing: f32,
 94    pub face_pile_spacing: f32,
 95    pub avatar_ribbon: AvatarRibbon,
 96    pub follower_avatar_overlap: f32,
 97    pub leader_selection: ContainerStyle,
 98    pub offline_icon: OfflineIcon,
 99    pub leader_avatar: AvatarStyle,
100    pub follower_avatar: AvatarStyle,
101    pub inactive_avatar_grayscale: bool,
102    pub sign_in_prompt: Interactive<ContainedText>,
103    pub outdated_warning: ContainedText,
104    pub share_button: Interactive<ContainedText>,
105    pub call_control: Interactive<IconButton>,
106    pub toggle_contacts_button: Interactive<IconButton>,
107    pub user_menu_button: Interactive<IconButton>,
108    pub toggle_contacts_badge: ContainerStyle,
109}
110
111#[derive(Copy, Clone, Deserialize, Default)]
112pub struct AvatarStyle {
113    #[serde(flatten)]
114    pub image: ImageStyle,
115    pub outer_width: f32,
116    pub outer_corner_radius: f32,
117}
118
119#[derive(Deserialize, Default, Clone)]
120pub struct Copilot {
121    pub modal: ModalStyle,
122    pub auth: CopilotAuth,
123}
124
125#[derive(Deserialize, Default, Clone)]
126pub struct CopilotAuth {
127    pub enable_group: ContainerStyle,
128    pub enable_text: TextStyle,
129    pub instruction_text: TextStyle,
130    pub cta_button: ButtonStyle,
131    pub content_width: f32,
132    pub copilot_icon: SvgStyle,
133    pub plus_icon: IconStyle,
134    pub zed_icon: SvgStyle,
135    pub device_code_group: ContainerStyle,
136    pub github_group: ContainerStyle,
137    pub header_group: ContainerStyle,
138    pub device_code: TextStyle,
139    pub device_code_cta: ButtonStyle,
140    pub device_code_left: f32,
141    pub device_code_left_container: ContainerStyle,
142    pub device_code_right: f32,
143    pub device_code_right_container: ContainerStyle,
144    pub device_code_seperator_height: f32,
145    pub hint: ContainedText,
146    pub enabled_hint: ContainerStyle,
147    pub not_authorized_hint: ContainerStyle,
148    pub warning: ContainedText,
149}
150
151#[derive(Deserialize, Default)]
152pub struct ContactsPopover {
153    #[serde(flatten)]
154    pub container: ContainerStyle,
155    pub height: f32,
156    pub width: f32,
157}
158
159#[derive(Deserialize, Default)]
160pub struct ContactList {
161    pub user_query_editor: FieldEditor,
162    pub user_query_editor_height: f32,
163    pub add_contact_button: IconButton,
164    pub header_row: Interactive<ContainedText>,
165    pub leave_call: Interactive<ContainedText>,
166    pub contact_row: Interactive<ContainerStyle>,
167    pub row_height: f32,
168    pub project_row: Interactive<ProjectRow>,
169    pub tree_branch: Interactive<TreeBranch>,
170    pub contact_avatar: ImageStyle,
171    pub contact_status_free: ContainerStyle,
172    pub contact_status_busy: ContainerStyle,
173    pub contact_username: ContainedText,
174    pub contact_button: Interactive<IconButton>,
175    pub contact_button_spacing: f32,
176    pub disabled_button: IconButton,
177    pub section_icon_size: f32,
178    pub calling_indicator: ContainedText,
179}
180
181#[derive(Deserialize, Default)]
182pub struct ProjectRow {
183    #[serde(flatten)]
184    pub container: ContainerStyle,
185    pub icon: Icon,
186    pub name: ContainedText,
187}
188
189#[derive(Deserialize, Default, Clone, Copy)]
190pub struct TreeBranch {
191    pub width: f32,
192    pub color: Color,
193}
194
195#[derive(Deserialize, Default)]
196pub struct ContactFinder {
197    pub picker: Picker,
198    pub row_height: f32,
199    pub contact_avatar: ImageStyle,
200    pub contact_username: ContainerStyle,
201    pub contact_button: IconButton,
202    pub disabled_contact_button: IconButton,
203}
204
205#[derive(Clone, Deserialize, Default)]
206pub struct TabBar {
207    #[serde(flatten)]
208    pub container: ContainerStyle,
209    pub pane_button: Interactive<IconButton>,
210    pub pane_button_container: ContainerStyle,
211    pub active_pane: TabStyles,
212    pub inactive_pane: TabStyles,
213    pub dragged_tab: Tab,
214    pub height: f32,
215}
216
217impl TabBar {
218    pub fn tab_style(&self, pane_active: bool, tab_active: bool) -> &Tab {
219        let tabs = if pane_active {
220            &self.active_pane
221        } else {
222            &self.inactive_pane
223        };
224
225        if tab_active {
226            &tabs.active_tab
227        } else {
228            &tabs.inactive_tab
229        }
230    }
231}
232
233#[derive(Clone, Deserialize, Default)]
234pub struct TabStyles {
235    pub active_tab: Tab,
236    pub inactive_tab: Tab,
237}
238
239#[derive(Clone, Deserialize, Default)]
240pub struct AvatarRibbon {
241    #[serde(flatten)]
242    pub container: ContainerStyle,
243    pub width: f32,
244    pub height: f32,
245}
246
247#[derive(Clone, Deserialize, Default)]
248pub struct OfflineIcon {
249    #[serde(flatten)]
250    pub container: ContainerStyle,
251    pub width: f32,
252    pub color: Color,
253}
254
255#[derive(Clone, Deserialize, Default)]
256pub struct Tab {
257    pub height: f32,
258    #[serde(flatten)]
259    pub container: ContainerStyle,
260    #[serde(flatten)]
261    pub label: LabelStyle,
262    pub description: ContainedText,
263    pub spacing: f32,
264    pub close_icon_width: f32,
265    pub type_icon_width: f32,
266    pub icon_close: Color,
267    pub icon_close_active: Color,
268    pub icon_dirty: Color,
269    pub icon_conflict: Color,
270}
271
272#[derive(Clone, Deserialize, Default)]
273pub struct Toolbar {
274    #[serde(flatten)]
275    pub container: ContainerStyle,
276    pub height: f32,
277    pub item_spacing: f32,
278    pub nav_button: Interactive<IconButton>,
279}
280
281#[derive(Clone, Deserialize, Default)]
282pub struct Dock {
283    pub initial_size_right: f32,
284    pub initial_size_bottom: f32,
285    pub wash_color: Color,
286    pub panel: ContainerStyle,
287    pub maximized: ContainerStyle,
288}
289
290#[derive(Clone, Deserialize, Default)]
291pub struct Notifications {
292    #[serde(flatten)]
293    pub container: ContainerStyle,
294    pub width: f32,
295}
296
297#[derive(Clone, Deserialize, Default)]
298pub struct Search {
299    #[serde(flatten)]
300    pub container: ContainerStyle,
301    pub editor: FindEditor,
302    pub invalid_editor: ContainerStyle,
303    pub option_button_group: ContainerStyle,
304    pub option_button: Interactive<ContainedText>,
305    pub match_background: Color,
306    pub match_index: ContainedText,
307    pub results_status: TextStyle,
308    pub dismiss_button: Interactive<IconButton>,
309}
310
311#[derive(Clone, Deserialize, Default)]
312pub struct FindEditor {
313    #[serde(flatten)]
314    pub input: FieldEditor,
315    pub min_width: f32,
316    pub max_width: f32,
317}
318
319#[derive(Deserialize, Default)]
320pub struct StatusBar {
321    #[serde(flatten)]
322    pub container: ContainerStyle,
323    pub height: f32,
324    pub item_spacing: f32,
325    pub cursor_position: TextStyle,
326    pub active_language: Interactive<ContainedText>,
327    pub auto_update_progress_message: TextStyle,
328    pub auto_update_done_message: TextStyle,
329    pub lsp_status: Interactive<StatusBarLspStatus>,
330    pub sidebar_buttons: StatusBarSidebarButtons,
331    pub diagnostic_summary: Interactive<StatusBarDiagnosticSummary>,
332    pub diagnostic_message: Interactive<ContainedText>,
333}
334
335#[derive(Deserialize, Default)]
336pub struct StatusBarSidebarButtons {
337    pub group_left: ContainerStyle,
338    pub group_right: ContainerStyle,
339    pub item: Interactive<SidebarItem>,
340    pub badge: ContainerStyle,
341}
342
343#[derive(Deserialize, Default)]
344pub struct StatusBarDiagnosticSummary {
345    pub container_ok: ContainerStyle,
346    pub container_warning: ContainerStyle,
347    pub container_error: ContainerStyle,
348    pub text: TextStyle,
349    pub icon_color_ok: Color,
350    pub icon_color_warning: Color,
351    pub icon_color_error: Color,
352    pub height: f32,
353    pub icon_width: f32,
354    pub icon_spacing: f32,
355    pub summary_spacing: f32,
356}
357
358#[derive(Deserialize, Default)]
359pub struct StatusBarLspStatus {
360    #[serde(flatten)]
361    pub container: ContainerStyle,
362    pub height: f32,
363    pub icon_spacing: f32,
364    pub icon_color: Color,
365    pub icon_width: f32,
366    pub message: TextStyle,
367}
368
369#[derive(Deserialize, Default)]
370pub struct Sidebar {
371    pub initial_size: f32,
372    #[serde(flatten)]
373    pub container: ContainerStyle,
374}
375
376#[derive(Clone, Deserialize, Default)]
377pub struct SidebarItem {
378    #[serde(flatten)]
379    pub container: ContainerStyle,
380    pub icon_color: Color,
381    pub icon_size: f32,
382    pub label: ContainedText,
383}
384
385#[derive(Deserialize, Default)]
386pub struct ProjectPanel {
387    #[serde(flatten)]
388    pub container: ContainerStyle,
389    pub entry: Interactive<ProjectPanelEntry>,
390    pub dragged_entry: ProjectPanelEntry,
391    pub ignored_entry: Interactive<ProjectPanelEntry>,
392    pub cut_entry: Interactive<ProjectPanelEntry>,
393    pub filename_editor: FieldEditor,
394    pub indent_width: f32,
395    pub open_project_button: Interactive<ContainedText>,
396}
397
398#[derive(Clone, Debug, Deserialize, Default)]
399pub struct ProjectPanelEntry {
400    pub height: f32,
401    #[serde(flatten)]
402    pub container: ContainerStyle,
403    pub text: TextStyle,
404    pub icon_color: Color,
405    pub icon_size: f32,
406    pub icon_spacing: f32,
407}
408
409#[derive(Clone, Debug, Deserialize, Default)]
410pub struct ContextMenu {
411    #[serde(flatten)]
412    pub container: ContainerStyle,
413    pub item: Interactive<ContextMenuItem>,
414    pub keystroke_margin: f32,
415    pub separator: ContainerStyle,
416}
417
418#[derive(Clone, Debug, Deserialize, Default)]
419pub struct ContextMenuItem {
420    #[serde(flatten)]
421    pub container: ContainerStyle,
422    pub label: TextStyle,
423    pub keystroke: ContainedText,
424    pub icon_width: f32,
425    pub icon_spacing: f32,
426}
427
428#[derive(Debug, Deserialize, Default)]
429pub struct CommandPalette {
430    pub key: Interactive<ContainedLabel>,
431    pub keystroke_spacing: f32,
432}
433
434#[derive(Deserialize, Default)]
435pub struct InviteLink {
436    #[serde(flatten)]
437    pub container: ContainerStyle,
438    #[serde(flatten)]
439    pub label: LabelStyle,
440    pub icon: Icon,
441}
442
443#[derive(Deserialize, Clone, Copy, Default)]
444pub struct Icon {
445    #[serde(flatten)]
446    pub container: ContainerStyle,
447    pub color: Color,
448    pub width: f32,
449}
450
451#[derive(Deserialize, Clone, Copy, Default)]
452pub struct IconButton {
453    #[serde(flatten)]
454    pub container: ContainerStyle,
455    pub color: Color,
456    pub icon_width: f32,
457    pub button_width: f32,
458}
459
460#[derive(Deserialize, Default)]
461pub struct ChatMessage {
462    #[serde(flatten)]
463    pub container: ContainerStyle,
464    pub body: TextStyle,
465    pub sender: ContainedText,
466    pub timestamp: ContainedText,
467}
468
469#[derive(Deserialize, Default)]
470pub struct ChannelSelect {
471    #[serde(flatten)]
472    pub container: ContainerStyle,
473    pub header: ChannelName,
474    pub item: ChannelName,
475    pub active_item: ChannelName,
476    pub hovered_item: ChannelName,
477    pub hovered_active_item: ChannelName,
478    pub menu: ContainerStyle,
479}
480
481#[derive(Deserialize, Default)]
482pub struct ChannelName {
483    #[serde(flatten)]
484    pub container: ContainerStyle,
485    pub hash: ContainedText,
486    pub name: TextStyle,
487}
488
489#[derive(Clone, Deserialize, Default)]
490pub struct Picker {
491    #[serde(flatten)]
492    pub container: ContainerStyle,
493    pub empty_container: ContainerStyle,
494    pub input_editor: FieldEditor,
495    pub empty_input_editor: FieldEditor,
496    pub no_matches: ContainedLabel,
497    pub item: Interactive<ContainedLabel>,
498}
499
500#[derive(Clone, Debug, Deserialize, Default)]
501pub struct ContainedText {
502    #[serde(flatten)]
503    pub container: ContainerStyle,
504    #[serde(flatten)]
505    pub text: TextStyle,
506}
507
508#[derive(Clone, Debug, Deserialize, Default)]
509pub struct ContainedLabel {
510    #[serde(flatten)]
511    pub container: ContainerStyle,
512    #[serde(flatten)]
513    pub label: LabelStyle,
514}
515
516#[derive(Clone, Deserialize, Default)]
517pub struct ProjectDiagnostics {
518    #[serde(flatten)]
519    pub container: ContainerStyle,
520    pub empty_message: TextStyle,
521    pub tab_icon_width: f32,
522    pub tab_icon_spacing: f32,
523    pub tab_summary_spacing: f32,
524}
525
526#[derive(Deserialize, Default)]
527pub struct ContactNotification {
528    pub header_avatar: ImageStyle,
529    pub header_message: ContainedText,
530    pub header_height: f32,
531    pub body_message: ContainedText,
532    pub button: Interactive<ContainedText>,
533    pub dismiss_button: Interactive<IconButton>,
534}
535
536#[derive(Deserialize, Default)]
537pub struct UpdateNotification {
538    pub message: ContainedText,
539    pub action_message: Interactive<ContainedText>,
540    pub dismiss_button: Interactive<IconButton>,
541}
542
543#[derive(Deserialize, Default)]
544pub struct MessageNotification {
545    pub message: ContainedText,
546    pub action_message: Interactive<ContainedText>,
547    pub dismiss_button: Interactive<IconButton>,
548}
549
550#[derive(Deserialize, Default)]
551pub struct ProjectSharedNotification {
552    pub window_height: f32,
553    pub window_width: f32,
554    #[serde(default)]
555    pub background: Color,
556    pub owner_container: ContainerStyle,
557    pub owner_avatar: ImageStyle,
558    pub owner_metadata: ContainerStyle,
559    pub owner_username: ContainedText,
560    pub message: ContainedText,
561    pub worktree_roots: ContainedText,
562    pub button_width: f32,
563    pub open_button: ContainedText,
564    pub dismiss_button: ContainedText,
565}
566
567#[derive(Deserialize, Default)]
568pub struct IncomingCallNotification {
569    pub window_height: f32,
570    pub window_width: f32,
571    #[serde(default)]
572    pub background: Color,
573    pub caller_container: ContainerStyle,
574    pub caller_avatar: ImageStyle,
575    pub caller_metadata: ContainerStyle,
576    pub caller_username: ContainedText,
577    pub caller_message: ContainedText,
578    pub worktree_roots: ContainedText,
579    pub button_width: f32,
580    pub accept_button: ContainedText,
581    pub decline_button: ContainedText,
582}
583
584#[derive(Clone, Deserialize, Default)]
585pub struct Editor {
586    pub text_color: Color,
587    #[serde(default)]
588    pub background: Color,
589    pub selection: SelectionStyle,
590    pub gutter_background: Color,
591    pub gutter_padding_factor: f32,
592    pub active_line_background: Color,
593    pub highlighted_line_background: Color,
594    pub rename_fade: f32,
595    pub document_highlight_read_background: Color,
596    pub document_highlight_write_background: Color,
597    pub diff: DiffStyle,
598    pub line_number: Color,
599    pub line_number_active: Color,
600    pub guest_selections: Vec<SelectionStyle>,
601    pub syntax: Arc<SyntaxTheme>,
602    pub suggestion: HighlightStyle,
603    pub diagnostic_path_header: DiagnosticPathHeader,
604    pub diagnostic_header: DiagnosticHeader,
605    pub error_diagnostic: DiagnosticStyle,
606    pub invalid_error_diagnostic: DiagnosticStyle,
607    pub warning_diagnostic: DiagnosticStyle,
608    pub invalid_warning_diagnostic: DiagnosticStyle,
609    pub information_diagnostic: DiagnosticStyle,
610    pub invalid_information_diagnostic: DiagnosticStyle,
611    pub hint_diagnostic: DiagnosticStyle,
612    pub invalid_hint_diagnostic: DiagnosticStyle,
613    pub autocomplete: AutocompleteStyle,
614    pub code_actions: CodeActions,
615    pub folds: Folds,
616    pub unnecessary_code_fade: f32,
617    pub hover_popover: HoverPopover,
618    pub link_definition: HighlightStyle,
619    pub composition_mark: HighlightStyle,
620    pub jump_icon: Interactive<IconButton>,
621    pub scrollbar: Scrollbar,
622}
623
624#[derive(Clone, Deserialize, Default)]
625pub struct Scrollbar {
626    pub track: ContainerStyle,
627    pub thumb: ContainerStyle,
628    pub width: f32,
629    pub min_height_factor: f32,
630}
631
632#[derive(Clone, Deserialize, Default)]
633pub struct DiagnosticPathHeader {
634    #[serde(flatten)]
635    pub container: ContainerStyle,
636    pub filename: ContainedText,
637    pub path: ContainedText,
638    pub text_scale_factor: f32,
639}
640
641#[derive(Clone, Deserialize, Default)]
642pub struct DiagnosticHeader {
643    #[serde(flatten)]
644    pub container: ContainerStyle,
645    pub message: ContainedLabel,
646    pub code: ContainedText,
647    pub text_scale_factor: f32,
648    pub icon_width_factor: f32,
649}
650
651#[derive(Clone, Deserialize, Default)]
652pub struct DiagnosticStyle {
653    pub message: LabelStyle,
654    #[serde(default)]
655    pub header: ContainerStyle,
656    pub text_scale_factor: f32,
657}
658
659#[derive(Clone, Deserialize, Default)]
660pub struct AutocompleteStyle {
661    #[serde(flatten)]
662    pub container: ContainerStyle,
663    pub item: ContainerStyle,
664    pub selected_item: ContainerStyle,
665    pub hovered_item: ContainerStyle,
666    pub match_highlight: HighlightStyle,
667}
668
669#[derive(Clone, Copy, Default, Deserialize)]
670pub struct SelectionStyle {
671    pub cursor: Color,
672    pub selection: Color,
673}
674
675#[derive(Clone, Deserialize, Default)]
676pub struct FieldEditor {
677    #[serde(flatten)]
678    pub container: ContainerStyle,
679    pub text: TextStyle,
680    #[serde(default)]
681    pub placeholder_text: Option<TextStyle>,
682    pub selection: SelectionStyle,
683}
684
685#[derive(Clone, Deserialize, Default)]
686pub struct InteractiveColor {
687    pub color: Color,
688}
689
690#[derive(Clone, Deserialize, Default)]
691pub struct CodeActions {
692    #[serde(default)]
693    pub indicator: Interactive<InteractiveColor>,
694    pub vertical_scale: f32,
695}
696
697#[derive(Clone, Deserialize, Default)]
698pub struct Folds {
699    pub indicator: Interactive<InteractiveColor>,
700    pub ellipses: FoldEllipses,
701    pub fold_background: Color,
702    pub icon_margin_scale: f32,
703    pub folded_icon: String,
704    pub foldable_icon: String,
705}
706
707#[derive(Clone, Deserialize, Default)]
708pub struct FoldEllipses {
709    pub text_color: Color,
710    pub background: Interactive<InteractiveColor>,
711    pub corner_radius_factor: f32,
712}
713
714#[derive(Clone, Deserialize, Default)]
715pub struct DiffStyle {
716    pub inserted: Color,
717    pub modified: Color,
718    pub deleted: Color,
719    pub removed_width_em: f32,
720    pub width_em: f32,
721    pub corner_radius: f32,
722}
723
724#[derive(Debug, Default, Clone, Copy)]
725pub struct Interactive<T> {
726    pub default: T,
727    pub hover: Option<T>,
728    pub hover_and_active: Option<T>,
729    pub clicked: Option<T>,
730    pub click_and_active: Option<T>,
731    pub active: Option<T>,
732    pub disabled: Option<T>,
733}
734
735impl<T> Interactive<T> {
736    pub fn style_for(&self, state: &mut MouseState, active: bool) -> &T {
737        if active {
738            if state.hovered() {
739                self.hover_and_active
740                    .as_ref()
741                    .unwrap_or(self.active.as_ref().unwrap_or(&self.default))
742            } else if state.clicked() == Some(gpui::MouseButton::Left) && self.clicked.is_some() {
743                self.click_and_active
744                    .as_ref()
745                    .unwrap_or(self.active.as_ref().unwrap_or(&self.default))
746            } else {
747                self.active.as_ref().unwrap_or(&self.default)
748            }
749        } else if state.clicked() == Some(gpui::MouseButton::Left) && self.clicked.is_some() {
750            self.clicked.as_ref().unwrap()
751        } else if state.hovered() {
752            self.hover.as_ref().unwrap_or(&self.default)
753        } else {
754            &self.default
755        }
756    }
757
758    pub fn disabled_style(&self) -> &T {
759        self.disabled.as_ref().unwrap_or(&self.default)
760    }
761}
762
763impl<'de, T: DeserializeOwned> Deserialize<'de> for Interactive<T> {
764    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
765    where
766        D: serde::Deserializer<'de>,
767    {
768        #[derive(Deserialize)]
769        struct Helper {
770            #[serde(flatten)]
771            default: Value,
772            hover: Option<Value>,
773            hover_and_active: Option<Value>,
774            clicked: Option<Value>,
775            click_and_active: Option<Value>,
776            active: Option<Value>,
777            disabled: Option<Value>,
778        }
779
780        let json = Helper::deserialize(deserializer)?;
781
782        let deserialize_state = |state_json: Option<Value>| -> Result<Option<T>, D::Error> {
783            if let Some(mut state_json) = state_json {
784                if let Value::Object(state_json) = &mut state_json {
785                    if let Value::Object(default) = &json.default {
786                        for (key, value) in default {
787                            if !state_json.contains_key(key) {
788                                state_json.insert(key.clone(), value.clone());
789                            }
790                        }
791                    }
792                }
793                Ok(Some(
794                    serde_json::from_value::<T>(state_json).map_err(serde::de::Error::custom)?,
795                ))
796            } else {
797                Ok(None)
798            }
799        };
800
801        let hover = deserialize_state(json.hover)?;
802        let hover_and_active = deserialize_state(json.hover_and_active)?;
803        let clicked = deserialize_state(json.clicked)?;
804        let click_and_active = deserialize_state(json.click_and_active)?;
805        let active = deserialize_state(json.active)?;
806        let disabled = deserialize_state(json.disabled)?;
807        let default = serde_json::from_value(json.default).map_err(serde::de::Error::custom)?;
808
809        Ok(Interactive {
810            default,
811            hover,
812            hover_and_active,
813            clicked,
814            click_and_active,
815            active,
816            disabled,
817        })
818    }
819}
820
821impl Editor {
822    pub fn replica_selection_style(&self, replica_id: u16) -> &SelectionStyle {
823        let style_ix = replica_id as usize % (self.guest_selections.len() + 1);
824        if style_ix == 0 {
825            &self.selection
826        } else {
827            &self.guest_selections[style_ix - 1]
828        }
829    }
830}
831
832#[derive(Default)]
833pub struct SyntaxTheme {
834    pub highlights: Vec<(String, HighlightStyle)>,
835}
836
837impl SyntaxTheme {
838    pub fn new(highlights: Vec<(String, HighlightStyle)>) -> Self {
839        Self { highlights }
840    }
841}
842
843impl<'de> Deserialize<'de> for SyntaxTheme {
844    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
845    where
846        D: serde::Deserializer<'de>,
847    {
848        let syntax_data: HashMap<String, HighlightStyle> = Deserialize::deserialize(deserializer)?;
849
850        let mut result = Self::new(Vec::new());
851        for (key, style) in syntax_data {
852            match result
853                .highlights
854                .binary_search_by(|(needle, _)| needle.cmp(&key))
855            {
856                Ok(i) | Err(i) => {
857                    result.highlights.insert(i, (key, style));
858                }
859            }
860        }
861
862        Ok(result)
863    }
864}
865
866#[derive(Clone, Deserialize, Default)]
867pub struct HoverPopover {
868    pub container: ContainerStyle,
869    pub info_container: ContainerStyle,
870    pub warning_container: ContainerStyle,
871    pub error_container: ContainerStyle,
872    pub block_style: ContainerStyle,
873    pub prose: TextStyle,
874    pub highlight: Color,
875}
876
877#[derive(Clone, Deserialize, Default)]
878pub struct TerminalStyle {
879    pub black: Color,
880    pub red: Color,
881    pub green: Color,
882    pub yellow: Color,
883    pub blue: Color,
884    pub magenta: Color,
885    pub cyan: Color,
886    pub white: Color,
887    pub bright_black: Color,
888    pub bright_red: Color,
889    pub bright_green: Color,
890    pub bright_yellow: Color,
891    pub bright_blue: Color,
892    pub bright_magenta: Color,
893    pub bright_cyan: Color,
894    pub bright_white: Color,
895    pub foreground: Color,
896    pub background: Color,
897    pub modal_background: Color,
898    pub cursor: Color,
899    pub dim_black: Color,
900    pub dim_red: Color,
901    pub dim_green: Color,
902    pub dim_yellow: Color,
903    pub dim_blue: Color,
904    pub dim_magenta: Color,
905    pub dim_cyan: Color,
906    pub dim_white: Color,
907    pub bright_foreground: Color,
908    pub dim_foreground: Color,
909}
910
911#[derive(Clone, Deserialize, Default)]
912pub struct FeedbackStyle {
913    pub submit_button: Interactive<ContainedText>,
914    pub button_margin: f32,
915    pub info_text_default: ContainedText,
916    pub link_text_default: ContainedText,
917    pub link_text_hover: ContainedText,
918}
919
920#[derive(Clone, Deserialize, Default)]
921pub struct WelcomeStyle {
922    pub page_width: f32,
923    pub logo: SvgStyle,
924    pub logo_subheading: ContainedText,
925    pub usage_note: ContainedText,
926    pub checkbox: CheckboxStyle,
927    pub checkbox_container: ContainerStyle,
928    pub button: Interactive<ContainedText>,
929    pub button_group: ContainerStyle,
930    pub heading_group: ContainerStyle,
931    pub checkbox_group: ContainerStyle,
932}
933
934#[derive(Clone, Deserialize, Default)]
935pub struct ColorScheme {
936    pub name: String,
937    pub is_light: bool,
938    pub ramps: RampSet,
939    pub lowest: Layer,
940    pub middle: Layer,
941    pub highest: Layer,
942
943    pub popover_shadow: Shadow,
944    pub modal_shadow: Shadow,
945
946    pub players: Vec<Player>,
947}
948
949#[derive(Clone, Deserialize, Default)]
950pub struct Player {
951    pub cursor: Color,
952    pub selection: Color,
953}
954
955#[derive(Clone, Deserialize, Default)]
956pub struct RampSet {
957    pub neutral: Vec<Color>,
958    pub red: Vec<Color>,
959    pub orange: Vec<Color>,
960    pub yellow: Vec<Color>,
961    pub green: Vec<Color>,
962    pub cyan: Vec<Color>,
963    pub blue: Vec<Color>,
964    pub violet: Vec<Color>,
965    pub magenta: Vec<Color>,
966}
967
968#[derive(Clone, Deserialize, Default)]
969pub struct Layer {
970    pub base: StyleSet,
971    pub variant: StyleSet,
972    pub on: StyleSet,
973    pub accent: StyleSet,
974    pub positive: StyleSet,
975    pub warning: StyleSet,
976    pub negative: StyleSet,
977}
978
979#[derive(Clone, Deserialize, Default)]
980pub struct StyleSet {
981    pub default: Style,
982    pub active: Style,
983    pub disabled: Style,
984    pub hovered: Style,
985    pub pressed: Style,
986    pub inverted: Style,
987}
988
989#[derive(Clone, Deserialize, Default)]
990pub struct Style {
991    pub background: Color,
992    pub border: Color,
993    pub foreground: Color,
994}