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 pub server_name_container: ContainerStyle,
838 pub server_name_color: Color,
839 pub server_name_size_percent: f32,
840}
841
842#[derive(Clone, Copy, Default, Deserialize, JsonSchema)]
843pub struct SelectionStyle {
844 pub cursor: Color,
845 pub selection: Color,
846}
847
848#[derive(Clone, Deserialize, Default, JsonSchema)]
849pub struct FieldEditor {
850 #[serde(flatten)]
851 pub container: ContainerStyle,
852 pub text: TextStyle,
853 #[serde(default)]
854 pub placeholder_text: Option<TextStyle>,
855 pub selection: SelectionStyle,
856}
857
858#[derive(Clone, Deserialize, Default, JsonSchema)]
859pub struct InteractiveColor {
860 pub color: Color,
861}
862
863#[derive(Clone, Deserialize, Default, JsonSchema)]
864pub struct CodeActions {
865 #[serde(default)]
866 pub indicator: Toggleable<Interactive<InteractiveColor>>,
867 pub vertical_scale: f32,
868}
869
870#[derive(Clone, Deserialize, Default, JsonSchema)]
871pub struct Folds {
872 pub indicator: Toggleable<Interactive<InteractiveColor>>,
873 pub ellipses: FoldEllipses,
874 pub fold_background: Color,
875 pub icon_margin_scale: f32,
876 pub folded_icon: String,
877 pub foldable_icon: String,
878}
879
880#[derive(Clone, Deserialize, Default, JsonSchema)]
881pub struct FoldEllipses {
882 pub text_color: Color,
883 pub background: Interactive<InteractiveColor>,
884 pub corner_radius_factor: f32,
885}
886
887#[derive(Clone, Deserialize, Default, JsonSchema)]
888pub struct DiffStyle {
889 pub inserted: Color,
890 pub modified: Color,
891 pub deleted: Color,
892 pub removed_width_em: f32,
893 pub width_em: f32,
894 pub corner_radius: f32,
895}
896
897#[derive(Debug, Default, Clone, Copy, JsonSchema)]
898pub struct Interactive<T> {
899 pub default: T,
900 pub hovered: Option<T>,
901 pub clicked: Option<T>,
902 pub disabled: Option<T>,
903}
904
905impl<T> Deref for Interactive<T> {
906 type Target = T;
907
908 fn deref(&self) -> &Self::Target {
909 &self.default
910 }
911}
912
913impl Interactive<()> {
914 pub fn new_blank() -> Self {
915 Self {
916 default: (),
917 hovered: None,
918 clicked: None,
919 disabled: None,
920 }
921 }
922}
923
924#[derive(Clone, Copy, Debug, Default, Deserialize, JsonSchema)]
925pub struct Toggleable<T> {
926 active: T,
927 inactive: T,
928}
929
930impl<T> Deref for Toggleable<T> {
931 type Target = T;
932
933 fn deref(&self) -> &Self::Target {
934 &self.inactive
935 }
936}
937
938impl Toggleable<()> {
939 pub fn new_blank() -> Self {
940 Self {
941 active: (),
942 inactive: (),
943 }
944 }
945}
946
947impl<T> Toggleable<T> {
948 pub fn new(active: T, inactive: T) -> Self {
949 Self { active, inactive }
950 }
951 pub fn in_state(&self, active: bool) -> &T {
952 if active {
953 &self.active
954 } else {
955 &self.inactive
956 }
957 }
958 pub fn active_state(&self) -> &T {
959 self.in_state(true)
960 }
961
962 pub fn inactive_state(&self) -> &T {
963 self.in_state(false)
964 }
965}
966
967impl<T> Interactive<T> {
968 pub fn style_for(&self, state: &mut MouseState) -> &T {
969 if state.clicked() == Some(platform::MouseButton::Left) && self.clicked.is_some() {
970 self.clicked.as_ref().unwrap()
971 } else if state.hovered() {
972 self.hovered.as_ref().unwrap_or(&self.default)
973 } else {
974 &self.default
975 }
976 }
977 pub fn disabled_style(&self) -> &T {
978 self.disabled.as_ref().unwrap_or(&self.default)
979 }
980}
981
982impl<T> Toggleable<Interactive<T>> {
983 pub fn style_for(&self, active: bool, state: &mut MouseState) -> &T {
984 self.in_state(active).style_for(state)
985 }
986
987 pub fn default_style(&self) -> &T {
988 &self.inactive.default
989 }
990}
991
992impl<'de, T: DeserializeOwned> Deserialize<'de> for Interactive<T> {
993 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
994 where
995 D: serde::Deserializer<'de>,
996 {
997 #[derive(Deserialize)]
998 struct Helper {
999 default: Value,
1000 hovered: Option<Value>,
1001 clicked: Option<Value>,
1002 disabled: Option<Value>,
1003 }
1004
1005 let json = Helper::deserialize(deserializer)?;
1006
1007 let deserialize_state = |state_json: Option<Value>| -> Result<Option<T>, D::Error> {
1008 if let Some(mut state_json) = state_json {
1009 if let Value::Object(state_json) = &mut state_json {
1010 if let Value::Object(default) = &json.default {
1011 for (key, value) in default {
1012 if !state_json.contains_key(key) {
1013 state_json.insert(key.clone(), value.clone());
1014 }
1015 }
1016 }
1017 }
1018 Ok(Some(
1019 serde_json::from_value::<T>(state_json).map_err(serde::de::Error::custom)?,
1020 ))
1021 } else {
1022 Ok(None)
1023 }
1024 };
1025
1026 let hovered = deserialize_state(json.hovered)?;
1027 let clicked = deserialize_state(json.clicked)?;
1028 let disabled = deserialize_state(json.disabled)?;
1029 let default = serde_json::from_value(json.default).map_err(serde::de::Error::custom)?;
1030
1031 Ok(Interactive {
1032 default,
1033 hovered,
1034 clicked,
1035 disabled,
1036 })
1037 }
1038}
1039
1040impl Editor {
1041 pub fn replica_selection_style(&self, replica_id: u16) -> &SelectionStyle {
1042 let style_ix = replica_id as usize % (self.guest_selections.len() + 1);
1043 if style_ix == 0 {
1044 &self.selection
1045 } else {
1046 &self.guest_selections[style_ix - 1]
1047 }
1048 }
1049}
1050
1051#[derive(Default, JsonSchema)]
1052pub struct SyntaxTheme {
1053 pub highlights: Vec<(String, HighlightStyle)>,
1054}
1055
1056impl SyntaxTheme {
1057 pub fn new(highlights: Vec<(String, HighlightStyle)>) -> Self {
1058 Self { highlights }
1059 }
1060}
1061
1062impl<'de> Deserialize<'de> for SyntaxTheme {
1063 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1064 where
1065 D: serde::Deserializer<'de>,
1066 {
1067 let syntax_data: HashMap<String, HighlightStyle> = Deserialize::deserialize(deserializer)?;
1068
1069 let mut result = Self::new(Vec::new());
1070 for (key, style) in syntax_data {
1071 match result
1072 .highlights
1073 .binary_search_by(|(needle, _)| needle.cmp(&key))
1074 {
1075 Ok(i) | Err(i) => {
1076 result.highlights.insert(i, (key, style));
1077 }
1078 }
1079 }
1080
1081 Ok(result)
1082 }
1083}
1084
1085#[derive(Clone, Deserialize, Default, JsonSchema)]
1086pub struct HoverPopover {
1087 pub container: ContainerStyle,
1088 pub info_container: ContainerStyle,
1089 pub warning_container: ContainerStyle,
1090 pub error_container: ContainerStyle,
1091 pub block_style: ContainerStyle,
1092 pub prose: TextStyle,
1093 pub diagnostic_source_highlight: HighlightStyle,
1094 pub highlight: Color,
1095}
1096
1097#[derive(Clone, Deserialize, Default, JsonSchema)]
1098pub struct TerminalStyle {
1099 pub black: Color,
1100 pub red: Color,
1101 pub green: Color,
1102 pub yellow: Color,
1103 pub blue: Color,
1104 pub magenta: Color,
1105 pub cyan: Color,
1106 pub white: Color,
1107 pub bright_black: Color,
1108 pub bright_red: Color,
1109 pub bright_green: Color,
1110 pub bright_yellow: Color,
1111 pub bright_blue: Color,
1112 pub bright_magenta: Color,
1113 pub bright_cyan: Color,
1114 pub bright_white: Color,
1115 pub foreground: Color,
1116 pub background: Color,
1117 pub modal_background: Color,
1118 pub cursor: Color,
1119 pub dim_black: Color,
1120 pub dim_red: Color,
1121 pub dim_green: Color,
1122 pub dim_yellow: Color,
1123 pub dim_blue: Color,
1124 pub dim_magenta: Color,
1125 pub dim_cyan: Color,
1126 pub dim_white: Color,
1127 pub bright_foreground: Color,
1128 pub dim_foreground: Color,
1129}
1130
1131#[derive(Clone, Deserialize, Default, JsonSchema)]
1132pub struct AssistantStyle {
1133 pub container: ContainerStyle,
1134 pub hamburger_button: Interactive<IconStyle>,
1135 pub split_button: Interactive<IconStyle>,
1136 pub assist_button: Interactive<IconStyle>,
1137 pub quote_button: Interactive<IconStyle>,
1138 pub zoom_in_button: Interactive<IconStyle>,
1139 pub zoom_out_button: Interactive<IconStyle>,
1140 pub plus_button: Interactive<IconStyle>,
1141 pub title: ContainedText,
1142 pub message_header: ContainerStyle,
1143 pub sent_at: ContainedText,
1144 pub user_sender: Interactive<ContainedText>,
1145 pub assistant_sender: Interactive<ContainedText>,
1146 pub system_sender: Interactive<ContainedText>,
1147 pub model: Interactive<ContainedText>,
1148 pub remaining_tokens: ContainedText,
1149 pub low_remaining_tokens: ContainedText,
1150 pub no_remaining_tokens: ContainedText,
1151 pub error_icon: Icon,
1152 pub api_key_editor: FieldEditor,
1153 pub api_key_prompt: ContainedText,
1154 pub saved_conversation: SavedConversation,
1155 pub inline: InlineAssistantStyle,
1156}
1157
1158#[derive(Clone, Deserialize, Default, JsonSchema)]
1159pub struct InlineAssistantStyle {
1160 #[serde(flatten)]
1161 pub container: ContainerStyle,
1162 pub editor: FieldEditor,
1163 pub disabled_editor: FieldEditor,
1164 pub pending_edit_background: Color,
1165 pub include_conversation: ToggleIconButtonStyle,
1166}
1167
1168#[derive(Clone, Deserialize, Default, JsonSchema)]
1169pub struct Contained<T> {
1170 container: ContainerStyle,
1171 contained: T,
1172}
1173
1174#[derive(Clone, Deserialize, Default, JsonSchema)]
1175pub struct SavedConversation {
1176 pub container: Interactive<ContainerStyle>,
1177 pub saved_at: ContainedText,
1178 pub title: ContainedText,
1179}
1180
1181#[derive(Clone, Deserialize, Default, JsonSchema)]
1182pub struct FeedbackStyle {
1183 pub submit_button: Interactive<ContainedText>,
1184 pub button_margin: f32,
1185 pub info_text_default: ContainedText,
1186 pub link_text_default: ContainedText,
1187 pub link_text_hover: ContainedText,
1188}
1189
1190#[derive(Clone, Deserialize, Default, JsonSchema)]
1191pub struct WelcomeStyle {
1192 pub page_width: f32,
1193 pub logo: SvgStyle,
1194 pub logo_subheading: ContainedText,
1195 pub usage_note: ContainedText,
1196 pub checkbox: CheckboxStyle,
1197 pub checkbox_container: ContainerStyle,
1198 pub button: Interactive<ContainedText>,
1199 pub button_group: ContainerStyle,
1200 pub heading_group: ContainerStyle,
1201 pub checkbox_group: ContainerStyle,
1202}
1203
1204#[derive(Clone, Deserialize, Default, JsonSchema)]
1205pub struct ColorScheme {
1206 pub name: String,
1207 pub is_light: bool,
1208 pub ramps: RampSet,
1209 pub lowest: Layer,
1210 pub middle: Layer,
1211 pub highest: Layer,
1212
1213 pub popover_shadow: Shadow,
1214 pub modal_shadow: Shadow,
1215
1216 pub players: Vec<Player>,
1217}
1218
1219#[derive(Clone, Deserialize, Default, JsonSchema)]
1220pub struct Player {
1221 pub cursor: Color,
1222 pub selection: Color,
1223}
1224
1225#[derive(Clone, Deserialize, Default, JsonSchema)]
1226pub struct RampSet {
1227 pub neutral: Vec<Color>,
1228 pub red: Vec<Color>,
1229 pub orange: Vec<Color>,
1230 pub yellow: Vec<Color>,
1231 pub green: Vec<Color>,
1232 pub cyan: Vec<Color>,
1233 pub blue: Vec<Color>,
1234 pub violet: Vec<Color>,
1235 pub magenta: Vec<Color>,
1236}
1237
1238#[derive(Clone, Deserialize, Default, JsonSchema)]
1239pub struct Layer {
1240 pub base: StyleSet,
1241 pub variant: StyleSet,
1242 pub on: StyleSet,
1243 pub accent: StyleSet,
1244 pub positive: StyleSet,
1245 pub warning: StyleSet,
1246 pub negative: StyleSet,
1247}
1248
1249#[derive(Clone, Deserialize, Default, JsonSchema)]
1250pub struct StyleSet {
1251 pub default: Style,
1252 pub active: Style,
1253 pub disabled: Style,
1254 pub hovered: Style,
1255 pub pressed: Style,
1256 pub inverted: Style,
1257}
1258
1259#[derive(Clone, Deserialize, Default, JsonSchema)]
1260pub struct Style {
1261 pub background: Color,
1262 pub border: Color,
1263 pub foreground: Color,
1264}