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