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