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