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