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