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