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