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