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 StatusBarSidebarButtons {
304 pub group_left: ContainerStyle,
305 pub group_right: ContainerStyle,
306 pub item: Interactive<SidebarItem>,
307 pub badge: ContainerStyle,
308}
309
310#[derive(Deserialize, Default)]
311pub struct StatusBarDiagnosticSummary {
312 pub container_ok: ContainerStyle,
313 pub container_warning: ContainerStyle,
314 pub container_error: ContainerStyle,
315 pub text: TextStyle,
316 pub icon_color_ok: Color,
317 pub icon_color_warning: Color,
318 pub icon_color_error: Color,
319 pub height: f32,
320 pub icon_width: f32,
321 pub icon_spacing: f32,
322 pub summary_spacing: f32,
323}
324
325#[derive(Deserialize, Default)]
326pub struct StatusBarLspStatus {
327 #[serde(flatten)]
328 pub container: ContainerStyle,
329 pub height: f32,
330 pub icon_spacing: f32,
331 pub icon_color: Color,
332 pub icon_width: f32,
333 pub message: TextStyle,
334}
335
336#[derive(Deserialize, Default)]
337pub struct Sidebar {
338 pub initial_size: f32,
339 #[serde(flatten)]
340 pub container: ContainerStyle,
341}
342
343#[derive(Clone, Deserialize, Default)]
344pub struct SidebarItem {
345 #[serde(flatten)]
346 pub container: ContainerStyle,
347 pub icon_color: Color,
348 pub icon_size: f32,
349 pub label: ContainedText,
350}
351
352#[derive(Deserialize, Default)]
353pub struct ProjectPanel {
354 #[serde(flatten)]
355 pub container: ContainerStyle,
356 pub entry: Interactive<ProjectPanelEntry>,
357 pub dragged_entry: ProjectPanelEntry,
358 pub ignored_entry: Interactive<ProjectPanelEntry>,
359 pub cut_entry: Interactive<ProjectPanelEntry>,
360 pub filename_editor: FieldEditor,
361 pub indent_width: f32,
362 pub open_project_button: Interactive<ContainedText>,
363}
364
365#[derive(Clone, Debug, Deserialize, Default)]
366pub struct ProjectPanelEntry {
367 pub height: f32,
368 #[serde(flatten)]
369 pub container: ContainerStyle,
370 pub text: TextStyle,
371 pub icon_color: Color,
372 pub icon_size: f32,
373 pub icon_spacing: f32,
374}
375
376#[derive(Clone, Debug, Deserialize, Default)]
377pub struct ContextMenu {
378 #[serde(flatten)]
379 pub container: ContainerStyle,
380 pub item: Interactive<ContextMenuItem>,
381 pub keystroke_margin: f32,
382 pub separator: ContainerStyle,
383}
384
385#[derive(Clone, Debug, Deserialize, Default)]
386pub struct ContextMenuItem {
387 #[serde(flatten)]
388 pub container: ContainerStyle,
389 pub label: TextStyle,
390 pub keystroke: ContainedText,
391 pub icon_width: f32,
392 pub icon_spacing: f32,
393}
394
395#[derive(Debug, Deserialize, Default)]
396pub struct CommandPalette {
397 pub key: Interactive<ContainedLabel>,
398 pub keystroke_spacing: f32,
399}
400
401#[derive(Deserialize, Default)]
402pub struct InviteLink {
403 #[serde(flatten)]
404 pub container: ContainerStyle,
405 #[serde(flatten)]
406 pub label: LabelStyle,
407 pub icon: Icon,
408}
409
410#[derive(Deserialize, Clone, Copy, Default)]
411pub struct Icon {
412 #[serde(flatten)]
413 pub container: ContainerStyle,
414 pub color: Color,
415 pub width: f32,
416}
417
418#[derive(Deserialize, Clone, Copy, Default)]
419pub struct IconButton {
420 #[serde(flatten)]
421 pub container: ContainerStyle,
422 pub color: Color,
423 pub icon_width: f32,
424 pub button_width: f32,
425}
426
427#[derive(Deserialize, Default)]
428pub struct ChatMessage {
429 #[serde(flatten)]
430 pub container: ContainerStyle,
431 pub body: TextStyle,
432 pub sender: ContainedText,
433 pub timestamp: ContainedText,
434}
435
436#[derive(Deserialize, Default)]
437pub struct ChannelSelect {
438 #[serde(flatten)]
439 pub container: ContainerStyle,
440 pub header: ChannelName,
441 pub item: ChannelName,
442 pub active_item: ChannelName,
443 pub hovered_item: ChannelName,
444 pub hovered_active_item: ChannelName,
445 pub menu: ContainerStyle,
446}
447
448#[derive(Deserialize, Default)]
449pub struct ChannelName {
450 #[serde(flatten)]
451 pub container: ContainerStyle,
452 pub hash: ContainedText,
453 pub name: TextStyle,
454}
455
456#[derive(Clone, Deserialize, Default)]
457pub struct Picker {
458 #[serde(flatten)]
459 pub container: ContainerStyle,
460 pub empty_container: ContainerStyle,
461 pub input_editor: FieldEditor,
462 pub empty_input_editor: FieldEditor,
463 pub no_matches: ContainedLabel,
464 pub item: Interactive<ContainedLabel>,
465}
466
467#[derive(Clone, Debug, Deserialize, Default)]
468pub struct ContainedText {
469 #[serde(flatten)]
470 pub container: ContainerStyle,
471 #[serde(flatten)]
472 pub text: TextStyle,
473}
474
475#[derive(Clone, Debug, Deserialize, Default)]
476pub struct ContainedLabel {
477 #[serde(flatten)]
478 pub container: ContainerStyle,
479 #[serde(flatten)]
480 pub label: LabelStyle,
481}
482
483#[derive(Clone, Deserialize, Default)]
484pub struct ProjectDiagnostics {
485 #[serde(flatten)]
486 pub container: ContainerStyle,
487 pub empty_message: TextStyle,
488 pub tab_icon_width: f32,
489 pub tab_icon_spacing: f32,
490 pub tab_summary_spacing: f32,
491}
492
493#[derive(Deserialize, Default)]
494pub struct ContactNotification {
495 pub header_avatar: ImageStyle,
496 pub header_message: ContainedText,
497 pub header_height: f32,
498 pub body_message: ContainedText,
499 pub button: Interactive<ContainedText>,
500 pub dismiss_button: Interactive<IconButton>,
501}
502
503#[derive(Deserialize, Default)]
504pub struct UpdateNotification {
505 pub message: ContainedText,
506 pub action_message: Interactive<ContainedText>,
507 pub dismiss_button: Interactive<IconButton>,
508}
509
510#[derive(Deserialize, Default)]
511pub struct MessageNotification {
512 pub message: ContainedText,
513 pub action_message: Interactive<ContainedText>,
514 pub dismiss_button: Interactive<IconButton>,
515}
516
517#[derive(Deserialize, Default)]
518pub struct ProjectSharedNotification {
519 pub window_height: f32,
520 pub window_width: f32,
521 #[serde(default)]
522 pub background: Color,
523 pub owner_container: ContainerStyle,
524 pub owner_avatar: ImageStyle,
525 pub owner_metadata: ContainerStyle,
526 pub owner_username: ContainedText,
527 pub message: ContainedText,
528 pub worktree_roots: ContainedText,
529 pub button_width: f32,
530 pub open_button: ContainedText,
531 pub dismiss_button: ContainedText,
532}
533
534#[derive(Deserialize, Default)]
535pub struct IncomingCallNotification {
536 pub window_height: f32,
537 pub window_width: f32,
538 #[serde(default)]
539 pub background: Color,
540 pub caller_container: ContainerStyle,
541 pub caller_avatar: ImageStyle,
542 pub caller_metadata: ContainerStyle,
543 pub caller_username: ContainedText,
544 pub caller_message: ContainedText,
545 pub worktree_roots: ContainedText,
546 pub button_width: f32,
547 pub accept_button: ContainedText,
548 pub decline_button: ContainedText,
549}
550
551#[derive(Clone, Deserialize, Default)]
552pub struct Editor {
553 pub text_color: Color,
554 #[serde(default)]
555 pub background: Color,
556 pub selection: SelectionStyle,
557 pub gutter_background: Color,
558 pub gutter_padding_factor: f32,
559 pub active_line_background: Color,
560 pub highlighted_line_background: Color,
561 pub rename_fade: f32,
562 pub document_highlight_read_background: Color,
563 pub document_highlight_write_background: Color,
564 pub diff: DiffStyle,
565 pub line_number: Color,
566 pub line_number_active: Color,
567 pub guest_selections: Vec<SelectionStyle>,
568 pub syntax: Arc<SyntaxTheme>,
569 pub diagnostic_path_header: DiagnosticPathHeader,
570 pub diagnostic_header: DiagnosticHeader,
571 pub error_diagnostic: DiagnosticStyle,
572 pub invalid_error_diagnostic: DiagnosticStyle,
573 pub warning_diagnostic: DiagnosticStyle,
574 pub invalid_warning_diagnostic: DiagnosticStyle,
575 pub information_diagnostic: DiagnosticStyle,
576 pub invalid_information_diagnostic: DiagnosticStyle,
577 pub hint_diagnostic: DiagnosticStyle,
578 pub invalid_hint_diagnostic: DiagnosticStyle,
579 pub autocomplete: AutocompleteStyle,
580 pub code_actions: CodeActions,
581 pub folds: Folds,
582 pub unnecessary_code_fade: f32,
583 pub hover_popover: HoverPopover,
584 pub link_definition: HighlightStyle,
585 pub composition_mark: HighlightStyle,
586 pub jump_icon: Interactive<IconButton>,
587 pub scrollbar: Scrollbar,
588}
589
590#[derive(Clone, Deserialize, Default)]
591pub struct Scrollbar {
592 pub track: ContainerStyle,
593 pub thumb: ContainerStyle,
594 pub width: f32,
595 pub min_height_factor: f32,
596}
597
598#[derive(Clone, Deserialize, Default)]
599pub struct DiagnosticPathHeader {
600 #[serde(flatten)]
601 pub container: ContainerStyle,
602 pub filename: ContainedText,
603 pub path: ContainedText,
604 pub text_scale_factor: f32,
605}
606
607#[derive(Clone, Deserialize, Default)]
608pub struct DiagnosticHeader {
609 #[serde(flatten)]
610 pub container: ContainerStyle,
611 pub message: ContainedLabel,
612 pub code: ContainedText,
613 pub text_scale_factor: f32,
614 pub icon_width_factor: f32,
615}
616
617#[derive(Clone, Deserialize, Default)]
618pub struct DiagnosticStyle {
619 pub message: LabelStyle,
620 #[serde(default)]
621 pub header: ContainerStyle,
622 pub text_scale_factor: f32,
623}
624
625#[derive(Clone, Deserialize, Default)]
626pub struct AutocompleteStyle {
627 #[serde(flatten)]
628 pub container: ContainerStyle,
629 pub item: ContainerStyle,
630 pub selected_item: ContainerStyle,
631 pub hovered_item: ContainerStyle,
632 pub match_highlight: HighlightStyle,
633}
634
635#[derive(Clone, Copy, Default, Deserialize)]
636pub struct SelectionStyle {
637 pub cursor: Color,
638 pub selection: Color,
639}
640
641#[derive(Clone, Deserialize, Default)]
642pub struct FieldEditor {
643 #[serde(flatten)]
644 pub container: ContainerStyle,
645 pub text: TextStyle,
646 #[serde(default)]
647 pub placeholder_text: Option<TextStyle>,
648 pub selection: SelectionStyle,
649}
650
651#[derive(Clone, Deserialize, Default)]
652pub struct InteractiveColor {
653 pub color: Color,
654}
655
656#[derive(Clone, Deserialize, Default)]
657pub struct CodeActions {
658 #[serde(default)]
659 pub indicator: Interactive<InteractiveColor>,
660 pub vertical_scale: f32,
661}
662
663#[derive(Clone, Deserialize, Default)]
664pub struct Folds {
665 pub indicator: Interactive<InteractiveColor>,
666 pub ellipses: FoldEllipses,
667 pub fold_background: Color,
668 pub icon_margin_scale: f32,
669 pub folded_icon: String,
670 pub foldable_icon: String,
671}
672
673#[derive(Clone, Deserialize, Default)]
674pub struct FoldEllipses {
675 pub text_color: Color,
676 pub background: Interactive<InteractiveColor>,
677 pub corner_radius_factor: f32,
678}
679
680#[derive(Clone, Deserialize, Default)]
681pub struct DiffStyle {
682 pub inserted: Color,
683 pub modified: Color,
684 pub deleted: Color,
685 pub removed_width_em: f32,
686 pub width_em: f32,
687 pub corner_radius: f32,
688}
689
690#[derive(Debug, Default, Clone, Copy)]
691pub struct Interactive<T> {
692 pub default: T,
693 pub hover: Option<T>,
694 pub clicked: Option<T>,
695 pub active: Option<T>,
696 pub disabled: Option<T>,
697}
698
699impl<T> Interactive<T> {
700 pub fn style_for(&self, state: &mut MouseState, active: bool) -> &T {
701 if active {
702 self.active.as_ref().unwrap_or(&self.default)
703 } else if state.clicked() == Some(gpui::MouseButton::Left) && self.clicked.is_some() {
704 self.clicked.as_ref().unwrap()
705 } else if state.hovered() {
706 self.hover.as_ref().unwrap_or(&self.default)
707 } else {
708 &self.default
709 }
710 }
711
712 pub fn disabled_style(&self) -> &T {
713 self.disabled.as_ref().unwrap_or(&self.default)
714 }
715}
716
717impl<'de, T: DeserializeOwned> Deserialize<'de> for Interactive<T> {
718 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
719 where
720 D: serde::Deserializer<'de>,
721 {
722 #[derive(Deserialize)]
723 struct Helper {
724 #[serde(flatten)]
725 default: Value,
726 hover: Option<Value>,
727 clicked: Option<Value>,
728 active: Option<Value>,
729 disabled: Option<Value>,
730 }
731
732 let json = Helper::deserialize(deserializer)?;
733
734 let deserialize_state = |state_json: Option<Value>| -> Result<Option<T>, D::Error> {
735 if let Some(mut state_json) = state_json {
736 if let Value::Object(state_json) = &mut state_json {
737 if let Value::Object(default) = &json.default {
738 for (key, value) in default {
739 if !state_json.contains_key(key) {
740 state_json.insert(key.clone(), value.clone());
741 }
742 }
743 }
744 }
745 Ok(Some(
746 serde_json::from_value::<T>(state_json).map_err(serde::de::Error::custom)?,
747 ))
748 } else {
749 Ok(None)
750 }
751 };
752
753 let hover = deserialize_state(json.hover)?;
754 let clicked = deserialize_state(json.clicked)?;
755 let active = deserialize_state(json.active)?;
756 let disabled = deserialize_state(json.disabled)?;
757 let default = serde_json::from_value(json.default).map_err(serde::de::Error::custom)?;
758
759 Ok(Interactive {
760 default,
761 hover,
762 clicked,
763 active,
764 disabled,
765 })
766 }
767}
768
769impl Editor {
770 pub fn replica_selection_style(&self, replica_id: u16) -> &SelectionStyle {
771 let style_ix = replica_id as usize % (self.guest_selections.len() + 1);
772 if style_ix == 0 {
773 &self.selection
774 } else {
775 &self.guest_selections[style_ix - 1]
776 }
777 }
778}
779
780#[derive(Default)]
781pub struct SyntaxTheme {
782 pub highlights: Vec<(String, HighlightStyle)>,
783}
784
785impl SyntaxTheme {
786 pub fn new(highlights: Vec<(String, HighlightStyle)>) -> Self {
787 Self { highlights }
788 }
789}
790
791impl<'de> Deserialize<'de> for SyntaxTheme {
792 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
793 where
794 D: serde::Deserializer<'de>,
795 {
796 let syntax_data: HashMap<String, HighlightStyle> = Deserialize::deserialize(deserializer)?;
797
798 let mut result = Self::new(Vec::new());
799 for (key, style) in syntax_data {
800 match result
801 .highlights
802 .binary_search_by(|(needle, _)| needle.cmp(&key))
803 {
804 Ok(i) | Err(i) => {
805 result.highlights.insert(i, (key, style));
806 }
807 }
808 }
809
810 Ok(result)
811 }
812}
813
814#[derive(Clone, Deserialize, Default)]
815pub struct HoverPopover {
816 pub container: ContainerStyle,
817 pub info_container: ContainerStyle,
818 pub warning_container: ContainerStyle,
819 pub error_container: ContainerStyle,
820 pub block_style: ContainerStyle,
821 pub prose: TextStyle,
822 pub highlight: Color,
823}
824
825#[derive(Clone, Deserialize, Default)]
826pub struct TerminalStyle {
827 pub black: Color,
828 pub red: Color,
829 pub green: Color,
830 pub yellow: Color,
831 pub blue: Color,
832 pub magenta: Color,
833 pub cyan: Color,
834 pub white: Color,
835 pub bright_black: Color,
836 pub bright_red: Color,
837 pub bright_green: Color,
838 pub bright_yellow: Color,
839 pub bright_blue: Color,
840 pub bright_magenta: Color,
841 pub bright_cyan: Color,
842 pub bright_white: Color,
843 pub foreground: Color,
844 pub background: Color,
845 pub modal_background: Color,
846 pub cursor: Color,
847 pub dim_black: Color,
848 pub dim_red: Color,
849 pub dim_green: Color,
850 pub dim_yellow: Color,
851 pub dim_blue: Color,
852 pub dim_magenta: Color,
853 pub dim_cyan: Color,
854 pub dim_white: Color,
855 pub bright_foreground: Color,
856 pub dim_foreground: Color,
857}
858
859#[derive(Clone, Deserialize, Default)]
860pub struct FeedbackStyle {
861 pub submit_button: Interactive<ContainedText>,
862 pub button_margin: f32,
863 pub info_text_default: ContainedText,
864 pub link_text_default: ContainedText,
865 pub link_text_hover: ContainedText,
866}
867
868#[derive(Clone, Deserialize, Default)]
869pub struct WelcomeStyle {
870 pub page_width: f32,
871 pub logo: IconStyle,
872 pub logo_subheading: ContainedText,
873 pub usage_note: ContainedText,
874 pub checkbox: CheckboxStyle,
875 pub checkbox_container: ContainerStyle,
876 pub button: Interactive<ContainedText>,
877 pub button_group: ContainerStyle,
878 pub heading_group: ContainerStyle,
879 pub checkbox_group: ContainerStyle,
880}
881
882#[derive(Clone, Deserialize, Default)]
883pub struct ColorScheme {
884 pub name: String,
885 pub is_light: bool,
886 pub ramps: RampSet,
887 pub lowest: Layer,
888 pub middle: Layer,
889 pub highest: Layer,
890
891 pub popover_shadow: Shadow,
892 pub modal_shadow: Shadow,
893
894 pub players: Vec<Player>,
895}
896
897#[derive(Clone, Deserialize, Default)]
898pub struct Player {
899 pub cursor: Color,
900 pub selection: Color,
901}
902
903#[derive(Clone, Deserialize, Default)]
904pub struct RampSet {
905 pub neutral: Vec<Color>,
906 pub red: Vec<Color>,
907 pub orange: Vec<Color>,
908 pub yellow: Vec<Color>,
909 pub green: Vec<Color>,
910 pub cyan: Vec<Color>,
911 pub blue: Vec<Color>,
912 pub violet: Vec<Color>,
913 pub magenta: Vec<Color>,
914}
915
916#[derive(Clone, Deserialize, Default)]
917pub struct Layer {
918 pub base: StyleSet,
919 pub variant: StyleSet,
920 pub on: StyleSet,
921 pub accent: StyleSet,
922 pub positive: StyleSet,
923 pub warning: StyleSet,
924 pub negative: StyleSet,
925}
926
927#[derive(Clone, Deserialize, Default)]
928pub struct StyleSet {
929 pub default: Style,
930 pub active: Style,
931 pub disabled: Style,
932 pub hovered: Style,
933 pub pressed: Style,
934 pub inverted: Style,
935}
936
937#[derive(Clone, Deserialize, Default)]
938pub struct Style {
939 pub background: Color,
940 pub border: Color,
941 pub foreground: Color,
942}