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