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