1mod theme_registry;
2mod theme_settings;
3pub mod ui;
4
5use gpui::{
6 color::Color,
7 elements::{ContainerStyle, ImageStyle, LabelStyle, Shadow, SvgStyle, TooltipStyle},
8 fonts::{HighlightStyle, TextStyle},
9 platform, AppContext, AssetSource, Border, MouseState,
10};
11use schemars::JsonSchema;
12use serde::{de::DeserializeOwned, Deserialize};
13use serde_json::Value;
14use settings::SettingsStore;
15use std::{collections::HashMap, sync::Arc};
16use ui::{ButtonStyle, CheckboxStyle, IconStyle, ModalStyle};
17
18pub use theme_registry::*;
19pub use theme_settings::*;
20
21pub fn current(cx: &AppContext) -> Arc<Theme> {
22 settings::get::<ThemeSettings>(cx).theme.clone()
23}
24
25pub fn init(source: impl AssetSource, cx: &mut AppContext) {
26 cx.set_global(ThemeRegistry::new(source, cx.font_cache().clone()));
27 settings::register::<ThemeSettings>(cx);
28
29 let mut prev_buffer_font_size = settings::get::<ThemeSettings>(cx).buffer_font_size;
30 cx.observe_global::<SettingsStore, _>(move |cx| {
31 let buffer_font_size = settings::get::<ThemeSettings>(cx).buffer_font_size;
32 if buffer_font_size != prev_buffer_font_size {
33 prev_buffer_font_size = buffer_font_size;
34 reset_font_size(cx);
35 }
36 })
37 .detach();
38}
39
40#[derive(Deserialize, Default, JsonSchema)]
41pub struct Theme {
42 #[serde(default)]
43 pub meta: ThemeMeta,
44 pub workspace: Workspace,
45 pub context_menu: ContextMenu,
46 pub toolbar_dropdown_menu: DropdownMenu,
47 pub copilot: Copilot,
48 pub collab_panel: CollabPanel,
49 pub project_panel: ProjectPanel,
50 pub command_palette: CommandPalette,
51 pub picker: Picker,
52 pub editor: Editor,
53 pub search: Search,
54 pub project_diagnostics: ProjectDiagnostics,
55 pub shared_screen: ContainerStyle,
56 pub contact_notification: ContactNotification,
57 pub update_notification: UpdateNotification,
58 pub simple_message_notification: MessageNotification,
59 pub project_shared_notification: ProjectSharedNotification,
60 pub incoming_call_notification: IncomingCallNotification,
61 pub tooltip: TooltipStyle,
62 pub terminal: TerminalStyle,
63 pub assistant: AssistantStyle,
64 pub feedback: FeedbackStyle,
65 pub welcome: WelcomeStyle,
66 pub titlebar: Titlebar,
67}
68
69#[derive(Deserialize, Default, Clone, JsonSchema)]
70pub struct ThemeMeta {
71 #[serde(skip_deserializing)]
72 pub id: usize,
73 pub name: String,
74 pub is_light: bool,
75}
76
77#[derive(Deserialize, Default, JsonSchema)]
78pub struct Workspace {
79 pub background: Color,
80 pub blank_pane: BlankPaneStyle,
81 pub tab_bar: TabBar,
82 pub pane_divider: Border,
83 pub leader_border_opacity: f32,
84 pub leader_border_width: f32,
85 pub dock: Dock,
86 pub status_bar: StatusBar,
87 pub toolbar: Toolbar,
88 pub breadcrumb_height: f32,
89 pub breadcrumbs: Interactive<ContainedText>,
90 pub disconnected_overlay: ContainedText,
91 pub modal: ContainerStyle,
92 pub zoomed_panel_foreground: ContainerStyle,
93 pub zoomed_pane_foreground: ContainerStyle,
94 pub zoomed_background: ContainerStyle,
95 pub notification: ContainerStyle,
96 pub notifications: Notifications,
97 pub joining_project_avatar: ImageStyle,
98 pub joining_project_message: ContainedText,
99 pub external_location_message: ContainedText,
100 pub drop_target_overlay_color: Color,
101}
102
103#[derive(Clone, Deserialize, Default, JsonSchema)]
104pub struct BlankPaneStyle {
105 pub logo: SvgStyle,
106 pub logo_shadow: SvgStyle,
107 pub logo_container: ContainerStyle,
108 pub keyboard_hints: ContainerStyle,
109 pub keyboard_hint: Interactive<ContainedText>,
110 pub keyboard_hint_width: f32,
111}
112
113#[derive(Clone, Deserialize, Default, JsonSchema)]
114pub struct Titlebar {
115 #[serde(flatten)]
116 pub container: ContainerStyle,
117 pub height: f32,
118 pub menu: TitlebarMenu,
119 pub project_menu_button: Toggleable<Interactive<ContainedText>>,
120 pub project_name_divider: ContainedText,
121 pub git_menu_button: Toggleable<Interactive<ContainedText>>,
122 pub item_spacing: f32,
123 pub face_pile_spacing: f32,
124 pub avatar_ribbon: AvatarRibbon,
125 pub follower_avatar_overlap: f32,
126 pub leader_selection: ContainerStyle,
127 pub offline_icon: OfflineIcon,
128 pub leader_avatar: AvatarStyle,
129 pub follower_avatar: AvatarStyle,
130 pub inactive_avatar_grayscale: bool,
131 pub sign_in_button: Toggleable<Interactive<ContainedText>>,
132 pub outdated_warning: ContainedText,
133 pub share_button: Toggleable<Interactive<ContainedText>>,
134 pub muted: Color,
135 pub speaking: Color,
136 pub screen_share_button: Toggleable<Interactive<IconButton>>,
137 pub toggle_contacts_button: Toggleable<Interactive<IconButton>>,
138 pub toggle_microphone_button: Toggleable<Interactive<IconButton>>,
139 pub toggle_speakers_button: Toggleable<Interactive<IconButton>>,
140 pub leave_call_button: Interactive<IconButton>,
141 pub toggle_contacts_badge: ContainerStyle,
142 pub user_menu: UserMenu,
143}
144
145#[derive(Clone, Deserialize, Default, JsonSchema)]
146pub struct TitlebarMenu {
147 pub width: f32,
148 pub height: f32,
149}
150
151#[derive(Clone, Deserialize, Default, JsonSchema)]
152pub struct UserMenu {
153 pub user_menu_button_online: UserMenuButton,
154 pub user_menu_button_offline: UserMenuButton,
155}
156
157#[derive(Clone, Deserialize, Default, JsonSchema)]
158pub struct UserMenuButton {
159 pub user_menu: Toggleable<Interactive<Icon>>,
160 pub avatar: AvatarStyle,
161 pub icon: Icon,
162}
163
164#[derive(Copy, Clone, Deserialize, Default, JsonSchema)]
165pub struct AvatarStyle {
166 #[serde(flatten)]
167 pub image: ImageStyle,
168 pub outer_width: f32,
169 pub outer_corner_radius: f32,
170}
171
172#[derive(Deserialize, Default, Clone, JsonSchema)]
173pub struct Copilot {
174 pub out_link_icon: Interactive<IconStyle>,
175 pub modal: ModalStyle,
176 pub auth: CopilotAuth,
177}
178
179#[derive(Deserialize, Default, Clone, JsonSchema)]
180pub struct CopilotAuth {
181 pub content_width: f32,
182 pub prompting: CopilotAuthPrompting,
183 pub not_authorized: CopilotAuthNotAuthorized,
184 pub authorized: CopilotAuthAuthorized,
185 pub cta_button: ButtonStyle,
186 pub header: IconStyle,
187}
188
189#[derive(Deserialize, Default, Clone, JsonSchema)]
190pub struct CopilotAuthPrompting {
191 pub subheading: ContainedText,
192 pub hint: ContainedText,
193 pub device_code: DeviceCode,
194}
195
196#[derive(Deserialize, Default, Clone, JsonSchema)]
197pub struct DeviceCode {
198 pub text: TextStyle,
199 pub cta: ButtonStyle,
200 pub left: f32,
201 pub left_container: ContainerStyle,
202 pub right: f32,
203 pub right_container: Interactive<ContainerStyle>,
204}
205
206#[derive(Deserialize, Default, Clone, JsonSchema)]
207pub struct CopilotAuthNotAuthorized {
208 pub subheading: ContainedText,
209 pub warning: ContainedText,
210}
211
212#[derive(Deserialize, Default, Clone, JsonSchema)]
213pub struct CopilotAuthAuthorized {
214 pub subheading: ContainedText,
215 pub hint: ContainedText,
216}
217
218#[derive(Deserialize, Default, JsonSchema)]
219pub struct CollabPanel {
220 #[serde(flatten)]
221 pub container: ContainerStyle,
222 pub list_empty_state: Toggleable<Interactive<ContainedText>>,
223 pub list_empty_icon: Icon,
224 pub list_empty_label_container: ContainerStyle,
225 pub log_in_button: Interactive<ContainedText>,
226 pub channel_editor: ContainerStyle,
227 pub channel_hash: Icon,
228 pub tabbed_modal: TabbedModal,
229 pub contact_finder: ContactFinder,
230 pub channel_modal: ChannelModal,
231 pub user_query_editor: FieldEditor,
232 pub user_query_editor_height: f32,
233 pub leave_call_button: Toggleable<Interactive<IconButton>>,
234 pub add_contact_button: Toggleable<Interactive<IconButton>>,
235 pub add_channel_button: Toggleable<Interactive<IconButton>>,
236 pub header_row: ContainedText,
237 pub subheader_row: Toggleable<Interactive<ContainedText>>,
238 pub leave_call: Interactive<ContainedText>,
239 pub contact_row: Toggleable<Interactive<ContainerStyle>>,
240 pub channel_row: Toggleable<Interactive<ContainerStyle>>,
241 pub channel_name: ContainedText,
242 pub row_height: f32,
243 pub project_row: Toggleable<Interactive<ProjectRow>>,
244 pub tree_branch: Toggleable<Interactive<TreeBranch>>,
245 pub contact_avatar: ImageStyle,
246 pub channel_avatar: ImageStyle,
247 pub extra_participant_label: ContainedText,
248 pub contact_status_free: ContainerStyle,
249 pub contact_status_busy: ContainerStyle,
250 pub contact_username: ContainedText,
251 pub contact_button: Interactive<IconButton>,
252 pub contact_button_spacing: f32,
253 pub channel_indent: f32,
254 pub disabled_button: IconButton,
255 pub section_icon_size: f32,
256 pub calling_indicator: ContainedText,
257 pub face_overlap: f32,
258}
259
260#[derive(Deserialize, Default, JsonSchema)]
261pub struct TabbedModal {
262 pub tab_button: Toggleable<Interactive<ContainedText>>,
263 pub modal: ContainerStyle,
264 pub header: ContainerStyle,
265 pub body: ContainerStyle,
266 pub title: ContainedText,
267 pub picker: Picker,
268 pub max_height: f32,
269 pub max_width: f32,
270 pub row_height: f32,
271}
272
273#[derive(Deserialize, Default, JsonSchema)]
274pub struct ChannelModal {
275 pub contact_avatar: ImageStyle,
276 pub contact_username: ContainerStyle,
277 pub remove_member_button: ContainedText,
278 pub cancel_invite_button: ContainedText,
279 pub member_icon: IconButton,
280 pub invitee_icon: IconButton,
281 pub member_tag: ContainedText,
282}
283
284#[derive(Deserialize, Default, JsonSchema)]
285pub struct ProjectRow {
286 #[serde(flatten)]
287 pub container: ContainerStyle,
288 pub icon: Icon,
289 pub name: ContainedText,
290}
291
292#[derive(Deserialize, Default, Clone, Copy, JsonSchema)]
293pub struct TreeBranch {
294 pub width: f32,
295 pub color: Color,
296}
297
298#[derive(Deserialize, Default, JsonSchema)]
299pub struct ContactFinder {
300 pub contact_avatar: ImageStyle,
301 pub contact_username: ContainerStyle,
302 pub contact_button: IconButton,
303 pub disabled_contact_button: IconButton,
304}
305
306#[derive(Deserialize, Default, JsonSchema)]
307pub struct DropdownMenu {
308 #[serde(flatten)]
309 pub container: ContainerStyle,
310 pub header: Interactive<DropdownMenuItem>,
311 pub section_header: ContainedText,
312 pub item: Toggleable<Interactive<DropdownMenuItem>>,
313 pub row_height: f32,
314}
315
316#[derive(Deserialize, Default, JsonSchema)]
317pub struct DropdownMenuItem {
318 #[serde(flatten)]
319 pub container: ContainerStyle,
320 #[serde(flatten)]
321 pub text: TextStyle,
322 pub secondary_text: Option<TextStyle>,
323 #[serde(default)]
324 pub secondary_text_spacing: f32,
325}
326
327#[derive(Clone, Deserialize, Default, JsonSchema)]
328pub struct TabBar {
329 #[serde(flatten)]
330 pub container: ContainerStyle,
331 pub pane_button: Toggleable<Interactive<IconButton>>,
332 pub pane_button_container: ContainerStyle,
333 pub active_pane: TabStyles,
334 pub inactive_pane: TabStyles,
335 pub dragged_tab: Tab,
336 pub height: f32,
337}
338
339impl TabBar {
340 pub fn tab_style(&self, pane_active: bool, tab_active: bool) -> &Tab {
341 let tabs = if pane_active {
342 &self.active_pane
343 } else {
344 &self.inactive_pane
345 };
346
347 if tab_active {
348 &tabs.active_tab
349 } else {
350 &tabs.inactive_tab
351 }
352 }
353}
354
355#[derive(Clone, Deserialize, Default, JsonSchema)]
356pub struct TabStyles {
357 pub active_tab: Tab,
358 pub inactive_tab: Tab,
359}
360
361#[derive(Clone, Deserialize, Default, JsonSchema)]
362pub struct AvatarRibbon {
363 #[serde(flatten)]
364 pub container: ContainerStyle,
365 pub width: f32,
366 pub height: f32,
367}
368
369#[derive(Clone, Deserialize, Default, JsonSchema)]
370pub struct OfflineIcon {
371 #[serde(flatten)]
372 pub container: ContainerStyle,
373 pub width: f32,
374 pub color: Color,
375}
376
377#[derive(Clone, Deserialize, Default, JsonSchema)]
378pub struct Tab {
379 pub height: f32,
380 #[serde(flatten)]
381 pub container: ContainerStyle,
382 #[serde(flatten)]
383 pub label: LabelStyle,
384 pub description: ContainedText,
385 pub spacing: f32,
386 pub close_icon_width: f32,
387 pub type_icon_width: f32,
388 pub icon_close: Color,
389 pub icon_close_active: Color,
390 pub icon_dirty: Color,
391 pub icon_conflict: Color,
392 pub git: GitProjectStatus,
393}
394
395#[derive(Clone, Deserialize, Default, JsonSchema)]
396pub struct Toolbar {
397 #[serde(flatten)]
398 pub container: ContainerStyle,
399 pub height: f32,
400 pub item_spacing: f32,
401 pub nav_button: Interactive<IconButton>,
402}
403
404#[derive(Clone, Deserialize, Default, JsonSchema)]
405pub struct Notifications {
406 #[serde(flatten)]
407 pub container: ContainerStyle,
408 pub width: f32,
409}
410
411#[derive(Clone, Deserialize, Default, JsonSchema)]
412pub struct Search {
413 #[serde(flatten)]
414 pub container: ContainerStyle,
415 pub editor: FindEditor,
416 pub invalid_editor: ContainerStyle,
417 pub option_button_group: ContainerStyle,
418 pub include_exclude_editor: FindEditor,
419 pub invalid_include_exclude_editor: ContainerStyle,
420 pub include_exclude_inputs: ContainedText,
421 pub option_button: Toggleable<Interactive<ContainedText>>,
422 pub action_button: Interactive<ContainedText>,
423 pub match_background: Color,
424 pub match_index: ContainedText,
425 pub results_status: TextStyle,
426 pub dismiss_button: Interactive<IconButton>,
427}
428
429#[derive(Clone, Deserialize, Default, JsonSchema)]
430pub struct FindEditor {
431 #[serde(flatten)]
432 pub input: FieldEditor,
433 pub min_width: f32,
434 pub max_width: f32,
435}
436
437#[derive(Deserialize, Default, JsonSchema)]
438pub struct StatusBar {
439 #[serde(flatten)]
440 pub container: ContainerStyle,
441 pub height: f32,
442 pub item_spacing: f32,
443 pub cursor_position: TextStyle,
444 pub vim_mode_indicator: ContainedText,
445 pub active_language: Interactive<ContainedText>,
446 pub auto_update_progress_message: TextStyle,
447 pub auto_update_done_message: TextStyle,
448 pub lsp_status: Interactive<StatusBarLspStatus>,
449 pub panel_buttons: StatusBarPanelButtons,
450 pub diagnostic_summary: Interactive<StatusBarDiagnosticSummary>,
451 pub diagnostic_message: Interactive<ContainedText>,
452}
453
454#[derive(Deserialize, Default, JsonSchema)]
455pub struct StatusBarPanelButtons {
456 pub group_left: ContainerStyle,
457 pub group_bottom: ContainerStyle,
458 pub group_right: ContainerStyle,
459 pub button: Toggleable<Interactive<PanelButton>>,
460}
461
462#[derive(Deserialize, Default, JsonSchema)]
463pub struct StatusBarDiagnosticSummary {
464 pub container_ok: ContainerStyle,
465 pub container_warning: ContainerStyle,
466 pub container_error: ContainerStyle,
467 pub text: TextStyle,
468 pub icon_color_ok: Color,
469 pub icon_color_warning: Color,
470 pub icon_color_error: Color,
471 pub height: f32,
472 pub icon_width: f32,
473 pub icon_spacing: f32,
474 pub summary_spacing: f32,
475}
476
477#[derive(Deserialize, Default, JsonSchema)]
478pub struct StatusBarLspStatus {
479 #[serde(flatten)]
480 pub container: ContainerStyle,
481 pub height: f32,
482 pub icon_spacing: f32,
483 pub icon_color: Color,
484 pub icon_width: f32,
485 pub message: TextStyle,
486}
487
488#[derive(Deserialize, Default, JsonSchema)]
489pub struct Dock {
490 pub left: ContainerStyle,
491 pub bottom: ContainerStyle,
492 pub right: ContainerStyle,
493}
494
495#[derive(Clone, Deserialize, Default, JsonSchema)]
496pub struct PanelButton {
497 #[serde(flatten)]
498 pub container: ContainerStyle,
499 pub icon_color: Color,
500 pub icon_size: f32,
501 pub label: ContainedText,
502}
503
504#[derive(Deserialize, Default, JsonSchema)]
505pub struct ProjectPanel {
506 #[serde(flatten)]
507 pub container: ContainerStyle,
508 pub entry: Toggleable<Interactive<ProjectPanelEntry>>,
509 pub dragged_entry: ProjectPanelEntry,
510 pub ignored_entry: Toggleable<Interactive<ProjectPanelEntry>>,
511 pub cut_entry: Toggleable<Interactive<ProjectPanelEntry>>,
512 pub filename_editor: FieldEditor,
513 pub indent_width: f32,
514 pub open_project_button: Interactive<ContainedText>,
515}
516
517#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
518pub struct ProjectPanelEntry {
519 pub height: f32,
520 #[serde(flatten)]
521 pub container: ContainerStyle,
522 pub text: TextStyle,
523 pub icon_size: f32,
524 pub icon_color: Color,
525 pub chevron_color: Color,
526 pub chevron_size: f32,
527 pub icon_spacing: f32,
528 pub status: EntryStatus,
529}
530
531#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
532pub struct EntryStatus {
533 pub git: GitProjectStatus,
534}
535
536#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
537pub struct GitProjectStatus {
538 pub modified: Color,
539 pub inserted: Color,
540 pub conflict: Color,
541}
542
543#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
544pub struct ContextMenu {
545 #[serde(flatten)]
546 pub container: ContainerStyle,
547 pub item: Toggleable<Interactive<ContextMenuItem>>,
548 pub keystroke_margin: f32,
549 pub separator: ContainerStyle,
550}
551
552#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
553pub struct ContextMenuItem {
554 #[serde(flatten)]
555 pub container: ContainerStyle,
556 pub label: TextStyle,
557 pub keystroke: ContainedText,
558 pub icon_width: f32,
559 pub icon_spacing: f32,
560}
561
562#[derive(Debug, Deserialize, Default, JsonSchema)]
563pub struct CommandPalette {
564 pub key: Toggleable<ContainedLabel>,
565 pub keystroke_spacing: f32,
566}
567
568#[derive(Deserialize, Default, JsonSchema)]
569pub struct InviteLink {
570 #[serde(flatten)]
571 pub container: ContainerStyle,
572 #[serde(flatten)]
573 pub label: LabelStyle,
574 pub icon: Icon,
575}
576
577#[derive(Deserialize, Clone, Copy, Default, JsonSchema)]
578pub struct Icon {
579 #[serde(flatten)]
580 pub container: ContainerStyle,
581 pub color: Color,
582 pub width: f32,
583}
584
585#[derive(Deserialize, Clone, Copy, Default, JsonSchema)]
586pub struct IconButton {
587 #[serde(flatten)]
588 pub container: ContainerStyle,
589 pub color: Color,
590 pub icon_width: f32,
591 pub button_width: f32,
592}
593
594#[derive(Deserialize, Default, JsonSchema)]
595pub struct ChatMessage {
596 #[serde(flatten)]
597 pub container: ContainerStyle,
598 pub body: TextStyle,
599 pub sender: ContainedText,
600 pub timestamp: ContainedText,
601}
602
603#[derive(Deserialize, Default, JsonSchema)]
604pub struct ChannelSelect {
605 #[serde(flatten)]
606 pub container: ContainerStyle,
607 pub header: ChannelName,
608 pub item: ChannelName,
609 pub active_item: ChannelName,
610 pub hovered_item: ChannelName,
611 pub hovered_active_item: ChannelName,
612 pub menu: ContainerStyle,
613}
614
615#[derive(Deserialize, Default, JsonSchema)]
616pub struct ChannelName {
617 #[serde(flatten)]
618 pub container: ContainerStyle,
619 pub hash: ContainedText,
620 pub name: TextStyle,
621}
622
623#[derive(Clone, Deserialize, Default, JsonSchema)]
624pub struct Picker {
625 #[serde(flatten)]
626 pub container: ContainerStyle,
627 pub empty_container: ContainerStyle,
628 pub input_editor: FieldEditor,
629 pub empty_input_editor: FieldEditor,
630 pub no_matches: ContainedLabel,
631 pub item: Toggleable<Interactive<ContainedLabel>>,
632 pub header: ContainedLabel,
633 pub footer: Interactive<ContainedLabel>,
634}
635
636#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
637pub struct ContainedText {
638 #[serde(flatten)]
639 pub container: ContainerStyle,
640 #[serde(flatten)]
641 pub text: TextStyle,
642}
643
644#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
645pub struct ContainedLabel {
646 #[serde(flatten)]
647 pub container: ContainerStyle,
648 #[serde(flatten)]
649 pub label: LabelStyle,
650}
651
652#[derive(Clone, Deserialize, Default, JsonSchema)]
653pub struct ProjectDiagnostics {
654 #[serde(flatten)]
655 pub container: ContainerStyle,
656 pub empty_message: TextStyle,
657 pub tab_icon_width: f32,
658 pub tab_icon_spacing: f32,
659 pub tab_summary_spacing: f32,
660}
661
662#[derive(Deserialize, Default, JsonSchema)]
663pub struct ContactNotification {
664 pub header_avatar: ImageStyle,
665 pub header_message: ContainedText,
666 pub header_height: f32,
667 pub body_message: ContainedText,
668 pub button: Interactive<ContainedText>,
669 pub dismiss_button: Interactive<IconButton>,
670}
671
672#[derive(Deserialize, Default, JsonSchema)]
673pub struct UpdateNotification {
674 pub message: ContainedText,
675 pub action_message: Interactive<ContainedText>,
676 pub dismiss_button: Interactive<IconButton>,
677}
678
679#[derive(Deserialize, Default, JsonSchema)]
680pub struct MessageNotification {
681 pub message: ContainedText,
682 pub action_message: Interactive<ContainedText>,
683 pub dismiss_button: Interactive<IconButton>,
684}
685
686#[derive(Deserialize, Default, JsonSchema)]
687pub struct ProjectSharedNotification {
688 pub window_height: f32,
689 pub window_width: f32,
690 #[serde(default)]
691 pub background: Color,
692 pub owner_container: ContainerStyle,
693 pub owner_avatar: ImageStyle,
694 pub owner_metadata: ContainerStyle,
695 pub owner_username: ContainedText,
696 pub message: ContainedText,
697 pub worktree_roots: ContainedText,
698 pub button_width: f32,
699 pub open_button: ContainedText,
700 pub dismiss_button: ContainedText,
701}
702
703#[derive(Deserialize, Default, JsonSchema)]
704pub struct IncomingCallNotification {
705 pub window_height: f32,
706 pub window_width: f32,
707 #[serde(default)]
708 pub background: Color,
709 pub caller_container: ContainerStyle,
710 pub caller_avatar: ImageStyle,
711 pub caller_metadata: ContainerStyle,
712 pub caller_username: ContainedText,
713 pub caller_message: ContainedText,
714 pub worktree_roots: ContainedText,
715 pub button_width: f32,
716 pub accept_button: ContainedText,
717 pub decline_button: ContainedText,
718}
719
720#[derive(Clone, Deserialize, Default, JsonSchema)]
721pub struct Editor {
722 pub text_color: Color,
723 #[serde(default)]
724 pub background: Color,
725 pub selection: SelectionStyle,
726 pub gutter_background: Color,
727 pub gutter_padding_factor: f32,
728 pub active_line_background: Color,
729 pub highlighted_line_background: Color,
730 pub rename_fade: f32,
731 pub document_highlight_read_background: Color,
732 pub document_highlight_write_background: Color,
733 pub diff: DiffStyle,
734 pub wrap_guide: Color,
735 pub active_wrap_guide: Color,
736 pub line_number: Color,
737 pub line_number_active: Color,
738 pub guest_selections: Vec<SelectionStyle>,
739 pub syntax: Arc<SyntaxTheme>,
740 pub hint: HighlightStyle,
741 pub suggestion: HighlightStyle,
742 pub diagnostic_path_header: DiagnosticPathHeader,
743 pub diagnostic_header: DiagnosticHeader,
744 pub error_diagnostic: DiagnosticStyle,
745 pub invalid_error_diagnostic: DiagnosticStyle,
746 pub warning_diagnostic: DiagnosticStyle,
747 pub invalid_warning_diagnostic: DiagnosticStyle,
748 pub information_diagnostic: DiagnosticStyle,
749 pub invalid_information_diagnostic: DiagnosticStyle,
750 pub hint_diagnostic: DiagnosticStyle,
751 pub invalid_hint_diagnostic: DiagnosticStyle,
752 pub autocomplete: AutocompleteStyle,
753 pub code_actions: CodeActions,
754 pub folds: Folds,
755 pub unnecessary_code_fade: f32,
756 pub hover_popover: HoverPopover,
757 pub link_definition: HighlightStyle,
758 pub composition_mark: HighlightStyle,
759 pub jump_icon: Interactive<IconButton>,
760 pub scrollbar: Scrollbar,
761 pub whitespace: Color,
762}
763
764#[derive(Clone, Deserialize, Default, JsonSchema)]
765pub struct Scrollbar {
766 pub track: ContainerStyle,
767 pub thumb: ContainerStyle,
768 pub width: f32,
769 pub min_height_factor: f32,
770 pub git: BufferGitDiffColors,
771 pub selections: Color,
772}
773
774#[derive(Clone, Deserialize, Default, JsonSchema)]
775pub struct BufferGitDiffColors {
776 pub inserted: Color,
777 pub modified: Color,
778 pub deleted: Color,
779}
780
781#[derive(Clone, Deserialize, Default, JsonSchema)]
782pub struct DiagnosticPathHeader {
783 #[serde(flatten)]
784 pub container: ContainerStyle,
785 pub filename: ContainedText,
786 pub path: ContainedText,
787 pub text_scale_factor: f32,
788}
789
790#[derive(Clone, Deserialize, Default, JsonSchema)]
791pub struct DiagnosticHeader {
792 #[serde(flatten)]
793 pub container: ContainerStyle,
794 pub source: ContainedLabel,
795 pub message: ContainedLabel,
796 pub code: ContainedText,
797 pub text_scale_factor: f32,
798 pub icon_width_factor: f32,
799}
800
801#[derive(Clone, Deserialize, Default, JsonSchema)]
802pub struct DiagnosticStyle {
803 pub message: LabelStyle,
804 #[serde(default)]
805 pub header: ContainerStyle,
806 pub text_scale_factor: f32,
807}
808
809#[derive(Clone, Deserialize, Default, JsonSchema)]
810pub struct AutocompleteStyle {
811 #[serde(flatten)]
812 pub container: ContainerStyle,
813 pub item: ContainerStyle,
814 pub selected_item: ContainerStyle,
815 pub hovered_item: ContainerStyle,
816 pub match_highlight: HighlightStyle,
817}
818
819#[derive(Clone, Copy, Default, Deserialize, JsonSchema)]
820pub struct SelectionStyle {
821 pub cursor: Color,
822 pub selection: Color,
823}
824
825#[derive(Clone, Deserialize, Default, JsonSchema)]
826pub struct FieldEditor {
827 #[serde(flatten)]
828 pub container: ContainerStyle,
829 pub text: TextStyle,
830 #[serde(default)]
831 pub placeholder_text: Option<TextStyle>,
832 pub selection: SelectionStyle,
833}
834
835#[derive(Clone, Deserialize, Default, JsonSchema)]
836pub struct InteractiveColor {
837 pub color: Color,
838}
839
840#[derive(Clone, Deserialize, Default, JsonSchema)]
841pub struct CodeActions {
842 #[serde(default)]
843 pub indicator: Toggleable<Interactive<InteractiveColor>>,
844 pub vertical_scale: f32,
845}
846
847#[derive(Clone, Deserialize, Default, JsonSchema)]
848pub struct Folds {
849 pub indicator: Toggleable<Interactive<InteractiveColor>>,
850 pub ellipses: FoldEllipses,
851 pub fold_background: Color,
852 pub icon_margin_scale: f32,
853 pub folded_icon: String,
854 pub foldable_icon: String,
855}
856
857#[derive(Clone, Deserialize, Default, JsonSchema)]
858pub struct FoldEllipses {
859 pub text_color: Color,
860 pub background: Interactive<InteractiveColor>,
861 pub corner_radius_factor: f32,
862}
863
864#[derive(Clone, Deserialize, Default, JsonSchema)]
865pub struct DiffStyle {
866 pub inserted: Color,
867 pub modified: Color,
868 pub deleted: Color,
869 pub removed_width_em: f32,
870 pub width_em: f32,
871 pub corner_radius: f32,
872}
873
874#[derive(Debug, Default, Clone, Copy, JsonSchema)]
875pub struct Interactive<T> {
876 pub default: T,
877 pub hovered: Option<T>,
878 pub clicked: Option<T>,
879 pub disabled: Option<T>,
880}
881
882#[derive(Clone, Copy, Debug, Default, Deserialize, JsonSchema)]
883pub struct Toggleable<T> {
884 active: T,
885 inactive: T,
886}
887
888impl<T> Toggleable<T> {
889 pub fn new(active: T, inactive: T) -> Self {
890 Self { active, inactive }
891 }
892 pub fn in_state(&self, active: bool) -> &T {
893 if active {
894 &self.active
895 } else {
896 &self.inactive
897 }
898 }
899 pub fn active_state(&self) -> &T {
900 self.in_state(true)
901 }
902
903 pub fn inactive_state(&self) -> &T {
904 self.in_state(false)
905 }
906}
907
908impl<T> Interactive<T> {
909 pub fn style_for(&self, state: &mut MouseState) -> &T {
910 if state.clicked() == Some(platform::MouseButton::Left) && self.clicked.is_some() {
911 self.clicked.as_ref().unwrap()
912 } else if state.hovered() {
913 self.hovered.as_ref().unwrap_or(&self.default)
914 } else {
915 &self.default
916 }
917 }
918 pub fn disabled_style(&self) -> &T {
919 self.disabled.as_ref().unwrap_or(&self.default)
920 }
921}
922
923impl<T> Toggleable<Interactive<T>> {
924 pub fn style_for(&self, active: bool, state: &mut MouseState) -> &T {
925 self.in_state(active).style_for(state)
926 }
927
928 pub fn default_style(&self) -> &T {
929 &self.inactive.default
930 }
931}
932
933impl<'de, T: DeserializeOwned> Deserialize<'de> for Interactive<T> {
934 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
935 where
936 D: serde::Deserializer<'de>,
937 {
938 #[derive(Deserialize)]
939 struct Helper {
940 default: Value,
941 hovered: Option<Value>,
942 clicked: Option<Value>,
943 disabled: Option<Value>,
944 }
945
946 let json = Helper::deserialize(deserializer)?;
947
948 let deserialize_state = |state_json: Option<Value>| -> Result<Option<T>, D::Error> {
949 if let Some(mut state_json) = state_json {
950 if let Value::Object(state_json) = &mut state_json {
951 if let Value::Object(default) = &json.default {
952 for (key, value) in default {
953 if !state_json.contains_key(key) {
954 state_json.insert(key.clone(), value.clone());
955 }
956 }
957 }
958 }
959 Ok(Some(
960 serde_json::from_value::<T>(state_json).map_err(serde::de::Error::custom)?,
961 ))
962 } else {
963 Ok(None)
964 }
965 };
966
967 let hovered = deserialize_state(json.hovered)?;
968 let clicked = deserialize_state(json.clicked)?;
969 let disabled = deserialize_state(json.disabled)?;
970 let default = serde_json::from_value(json.default).map_err(serde::de::Error::custom)?;
971
972 Ok(Interactive {
973 default,
974 hovered,
975 clicked,
976 disabled,
977 })
978 }
979}
980
981impl Editor {
982 pub fn replica_selection_style(&self, replica_id: u16) -> &SelectionStyle {
983 let style_ix = replica_id as usize % (self.guest_selections.len() + 1);
984 if style_ix == 0 {
985 &self.selection
986 } else {
987 &self.guest_selections[style_ix - 1]
988 }
989 }
990}
991
992#[derive(Default, JsonSchema)]
993pub struct SyntaxTheme {
994 pub highlights: Vec<(String, HighlightStyle)>,
995}
996
997impl SyntaxTheme {
998 pub fn new(highlights: Vec<(String, HighlightStyle)>) -> Self {
999 Self { highlights }
1000 }
1001}
1002
1003impl<'de> Deserialize<'de> for SyntaxTheme {
1004 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1005 where
1006 D: serde::Deserializer<'de>,
1007 {
1008 let syntax_data: HashMap<String, HighlightStyle> = Deserialize::deserialize(deserializer)?;
1009
1010 let mut result = Self::new(Vec::new());
1011 for (key, style) in syntax_data {
1012 match result
1013 .highlights
1014 .binary_search_by(|(needle, _)| needle.cmp(&key))
1015 {
1016 Ok(i) | Err(i) => {
1017 result.highlights.insert(i, (key, style));
1018 }
1019 }
1020 }
1021
1022 Ok(result)
1023 }
1024}
1025
1026#[derive(Clone, Deserialize, Default, JsonSchema)]
1027pub struct HoverPopover {
1028 pub container: ContainerStyle,
1029 pub info_container: ContainerStyle,
1030 pub warning_container: ContainerStyle,
1031 pub error_container: ContainerStyle,
1032 pub block_style: ContainerStyle,
1033 pub prose: TextStyle,
1034 pub diagnostic_source_highlight: HighlightStyle,
1035 pub highlight: Color,
1036}
1037
1038#[derive(Clone, Deserialize, Default, JsonSchema)]
1039pub struct TerminalStyle {
1040 pub black: Color,
1041 pub red: Color,
1042 pub green: Color,
1043 pub yellow: Color,
1044 pub blue: Color,
1045 pub magenta: Color,
1046 pub cyan: Color,
1047 pub white: Color,
1048 pub bright_black: Color,
1049 pub bright_red: Color,
1050 pub bright_green: Color,
1051 pub bright_yellow: Color,
1052 pub bright_blue: Color,
1053 pub bright_magenta: Color,
1054 pub bright_cyan: Color,
1055 pub bright_white: Color,
1056 pub foreground: Color,
1057 pub background: Color,
1058 pub modal_background: Color,
1059 pub cursor: Color,
1060 pub dim_black: Color,
1061 pub dim_red: Color,
1062 pub dim_green: Color,
1063 pub dim_yellow: Color,
1064 pub dim_blue: Color,
1065 pub dim_magenta: Color,
1066 pub dim_cyan: Color,
1067 pub dim_white: Color,
1068 pub bright_foreground: Color,
1069 pub dim_foreground: Color,
1070}
1071
1072#[derive(Clone, Deserialize, Default, JsonSchema)]
1073pub struct AssistantStyle {
1074 pub container: ContainerStyle,
1075 pub hamburger_button: Interactive<IconStyle>,
1076 pub split_button: Interactive<IconStyle>,
1077 pub assist_button: Interactive<IconStyle>,
1078 pub quote_button: Interactive<IconStyle>,
1079 pub zoom_in_button: Interactive<IconStyle>,
1080 pub zoom_out_button: Interactive<IconStyle>,
1081 pub plus_button: Interactive<IconStyle>,
1082 pub title: ContainedText,
1083 pub message_header: ContainerStyle,
1084 pub sent_at: ContainedText,
1085 pub user_sender: Interactive<ContainedText>,
1086 pub assistant_sender: Interactive<ContainedText>,
1087 pub system_sender: Interactive<ContainedText>,
1088 pub model: Interactive<ContainedText>,
1089 pub remaining_tokens: ContainedText,
1090 pub low_remaining_tokens: ContainedText,
1091 pub no_remaining_tokens: ContainedText,
1092 pub error_icon: Icon,
1093 pub api_key_editor: FieldEditor,
1094 pub api_key_prompt: ContainedText,
1095 pub saved_conversation: SavedConversation,
1096}
1097
1098#[derive(Clone, Deserialize, Default, JsonSchema)]
1099pub struct Contained<T> {
1100 container: ContainerStyle,
1101 contained: T,
1102}
1103
1104#[derive(Clone, Deserialize, Default, JsonSchema)]
1105pub struct SavedConversation {
1106 pub container: Interactive<ContainerStyle>,
1107 pub saved_at: ContainedText,
1108 pub title: ContainedText,
1109}
1110
1111#[derive(Clone, Deserialize, Default, JsonSchema)]
1112pub struct FeedbackStyle {
1113 pub submit_button: Interactive<ContainedText>,
1114 pub button_margin: f32,
1115 pub info_text_default: ContainedText,
1116 pub link_text_default: ContainedText,
1117 pub link_text_hover: ContainedText,
1118}
1119
1120#[derive(Clone, Deserialize, Default, JsonSchema)]
1121pub struct WelcomeStyle {
1122 pub page_width: f32,
1123 pub logo: SvgStyle,
1124 pub logo_subheading: ContainedText,
1125 pub usage_note: ContainedText,
1126 pub checkbox: CheckboxStyle,
1127 pub checkbox_container: ContainerStyle,
1128 pub button: Interactive<ContainedText>,
1129 pub button_group: ContainerStyle,
1130 pub heading_group: ContainerStyle,
1131 pub checkbox_group: ContainerStyle,
1132}
1133
1134#[derive(Clone, Deserialize, Default, JsonSchema)]
1135pub struct ColorScheme {
1136 pub name: String,
1137 pub is_light: bool,
1138 pub ramps: RampSet,
1139 pub lowest: Layer,
1140 pub middle: Layer,
1141 pub highest: Layer,
1142
1143 pub popover_shadow: Shadow,
1144 pub modal_shadow: Shadow,
1145
1146 pub players: Vec<Player>,
1147}
1148
1149#[derive(Clone, Deserialize, Default, JsonSchema)]
1150pub struct Player {
1151 pub cursor: Color,
1152 pub selection: Color,
1153}
1154
1155#[derive(Clone, Deserialize, Default, JsonSchema)]
1156pub struct RampSet {
1157 pub neutral: Vec<Color>,
1158 pub red: Vec<Color>,
1159 pub orange: Vec<Color>,
1160 pub yellow: Vec<Color>,
1161 pub green: Vec<Color>,
1162 pub cyan: Vec<Color>,
1163 pub blue: Vec<Color>,
1164 pub violet: Vec<Color>,
1165 pub magenta: Vec<Color>,
1166}
1167
1168#[derive(Clone, Deserialize, Default, JsonSchema)]
1169pub struct Layer {
1170 pub base: StyleSet,
1171 pub variant: StyleSet,
1172 pub on: StyleSet,
1173 pub accent: StyleSet,
1174 pub positive: StyleSet,
1175 pub warning: StyleSet,
1176 pub negative: StyleSet,
1177}
1178
1179#[derive(Clone, Deserialize, Default, JsonSchema)]
1180pub struct StyleSet {
1181 pub default: Style,
1182 pub active: Style,
1183 pub disabled: Style,
1184 pub hovered: Style,
1185 pub pressed: Style,
1186 pub inverted: Style,
1187}
1188
1189#[derive(Clone, Deserialize, Default, JsonSchema)]
1190pub struct Style {
1191 pub background: Color,
1192 pub border: Color,
1193 pub foreground: Color,
1194}