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