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