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 breadcrumb_height: f32,
92 pub breadcrumbs: Interactive<ContainedText>,
93 pub disconnected_overlay: ContainedText,
94 pub modal: ContainerStyle,
95 pub zoomed_panel_foreground: ContainerStyle,
96 pub zoomed_pane_foreground: ContainerStyle,
97 pub zoomed_background: ContainerStyle,
98 pub notification: ContainerStyle,
99 pub notifications: Notifications,
100 pub joining_project_avatar: ImageStyle,
101 pub joining_project_message: ContainedText,
102 pub external_location_message: ContainedText,
103 pub drop_target_overlay_color: Color,
104}
105
106#[derive(Clone, Deserialize, Default, JsonSchema)]
107pub struct BlankPaneStyle {
108 pub logo: SvgStyle,
109 pub logo_shadow: SvgStyle,
110 pub logo_container: ContainerStyle,
111 pub keyboard_hints: ContainerStyle,
112 pub keyboard_hint: Interactive<ContainedText>,
113 pub keyboard_hint_width: f32,
114}
115
116#[derive(Clone, Deserialize, Default, JsonSchema)]
117pub struct Titlebar {
118 #[serde(flatten)]
119 pub container: ContainerStyle,
120 pub height: f32,
121 pub menu: TitlebarMenu,
122 pub project_menu_button: Toggleable<Interactive<ContainedText>>,
123 pub project_name_divider: ContainedText,
124 pub git_menu_button: Toggleable<Interactive<ContainedText>>,
125 pub item_spacing: f32,
126 pub face_pile_spacing: f32,
127 pub avatar_ribbon: AvatarRibbon,
128 pub follower_avatar_overlap: f32,
129 pub leader_selection: ContainerStyle,
130 pub offline_icon: OfflineIcon,
131 pub leader_avatar: AvatarStyle,
132 pub follower_avatar: AvatarStyle,
133 pub inactive_avatar_grayscale: bool,
134 pub sign_in_button: Toggleable<Interactive<ContainedText>>,
135 pub outdated_warning: ContainedText,
136 pub share_button: Toggleable<Interactive<ContainedText>>,
137 pub muted: Color,
138 pub speaking: Color,
139 pub screen_share_button: Toggleable<Interactive<IconButton>>,
140 pub toggle_contacts_button: Toggleable<Interactive<IconButton>>,
141 pub toggle_microphone_button: Toggleable<Interactive<IconButton>>,
142 pub toggle_speakers_button: Toggleable<Interactive<IconButton>>,
143 pub leave_call_button: Interactive<IconButton>,
144 pub toggle_contacts_badge: ContainerStyle,
145 pub user_menu: UserMenu,
146}
147
148#[derive(Clone, Deserialize, Default, JsonSchema)]
149pub struct TitlebarMenu {
150 pub width: f32,
151 pub height: f32,
152}
153
154#[derive(Clone, Deserialize, Default, JsonSchema)]
155pub struct UserMenu {
156 pub user_menu_button_online: UserMenuButton,
157 pub user_menu_button_offline: UserMenuButton,
158}
159
160#[derive(Clone, Deserialize, Default, JsonSchema)]
161pub struct UserMenuButton {
162 pub user_menu: Toggleable<Interactive<Icon>>,
163 pub avatar: AvatarStyle,
164 pub icon: Icon,
165}
166
167#[derive(Copy, Clone, Deserialize, Default, JsonSchema)]
168pub struct AvatarStyle {
169 #[serde(flatten)]
170 pub image: ImageStyle,
171 pub outer_width: f32,
172 pub outer_corner_radius: f32,
173}
174
175#[derive(Deserialize, Default, Clone, JsonSchema)]
176pub struct Copilot {
177 pub out_link_icon: Interactive<IconStyle>,
178 pub modal: ModalStyle,
179 pub auth: CopilotAuth,
180}
181
182#[derive(Deserialize, Default, Clone, JsonSchema)]
183pub struct CopilotAuth {
184 pub content_width: f32,
185 pub prompting: CopilotAuthPrompting,
186 pub not_authorized: CopilotAuthNotAuthorized,
187 pub authorized: CopilotAuthAuthorized,
188 pub cta_button: CopilotCTAButton,
189 pub header: IconStyle,
190}
191
192#[derive(Deserialize, Default, Clone, JsonSchema)]
193pub struct CopilotAuthPrompting {
194 pub subheading: ContainedText,
195 pub hint: ContainedText,
196 pub device_code: DeviceCode,
197}
198
199#[derive(Deserialize, Default, Clone, JsonSchema)]
200pub struct DeviceCode {
201 pub text: TextStyle,
202 pub cta: CopilotCTAButton,
203 pub left: f32,
204 pub left_container: ContainerStyle,
205 pub right: f32,
206 pub right_container: Interactive<ContainerStyle>,
207}
208
209#[derive(Deserialize, Default, Clone, JsonSchema)]
210pub struct CopilotAuthNotAuthorized {
211 pub subheading: ContainedText,
212 pub warning: ContainedText,
213}
214
215#[derive(Deserialize, Default, Clone, JsonSchema)]
216pub struct CopilotAuthAuthorized {
217 pub subheading: ContainedText,
218 pub hint: ContainedText,
219}
220
221#[derive(Deserialize, Default, JsonSchema)]
222pub struct CollabPanel {
223 #[serde(flatten)]
224 pub container: ContainerStyle,
225 pub disclosure: DisclosureStyle<()>,
226 pub list_empty_state: Toggleable<Interactive<ContainedText>>,
227 pub list_empty_icon: Icon,
228 pub list_empty_label_container: ContainerStyle,
229 pub log_in_button: Interactive<ContainedText>,
230 pub channel_editor: ContainerStyle,
231 pub channel_hash: Icon,
232 pub tabbed_modal: TabbedModal,
233 pub contact_finder: ContactFinder,
234 pub channel_modal: ChannelModal,
235 pub user_query_editor: FieldEditor,
236 pub user_query_editor_height: f32,
237 pub leave_call_button: Toggleable<Interactive<IconButton>>,
238 pub add_contact_button: Toggleable<Interactive<IconButton>>,
239 pub add_channel_button: Toggleable<Interactive<IconButton>>,
240 pub header_row: ContainedText,
241 pub subheader_row: Toggleable<Interactive<ContainedText>>,
242 pub leave_call: Interactive<ContainedText>,
243 pub contact_row: Toggleable<Interactive<ContainerStyle>>,
244 pub channel_row: Toggleable<Interactive<ContainerStyle>>,
245 pub channel_name: ContainedText,
246 pub row_height: f32,
247 pub project_row: Toggleable<Interactive<ProjectRow>>,
248 pub tree_branch: Toggleable<Interactive<TreeBranch>>,
249 pub contact_avatar: ImageStyle,
250 pub channel_avatar: ImageStyle,
251 pub extra_participant_label: ContainedText,
252 pub contact_status_free: ContainerStyle,
253 pub contact_status_busy: ContainerStyle,
254 pub contact_username: ContainedText,
255 pub contact_button: Interactive<IconButton>,
256 pub contact_button_spacing: f32,
257 pub channel_indent: f32,
258 pub disabled_button: IconButton,
259 pub section_icon_size: f32,
260 pub calling_indicator: ContainedText,
261 pub face_overlap: f32,
262}
263
264#[derive(Deserialize, Default, JsonSchema)]
265pub struct ComponentTest {
266 pub button: Interactive<ButtonStyle<TextStyle>>,
267 pub toggle: Toggleable<Interactive<ButtonStyle<TextStyle>>>,
268 pub disclosure: DisclosureStyle<TextStyle>,
269}
270
271#[derive(Deserialize, Default, JsonSchema)]
272pub struct TabbedModal {
273 pub tab_button: Toggleable<Interactive<ContainedText>>,
274 pub modal: ContainerStyle,
275 pub header: ContainerStyle,
276 pub body: ContainerStyle,
277 pub title: ContainedText,
278 pub picker: Picker,
279 pub max_height: f32,
280 pub max_width: f32,
281 pub row_height: f32,
282}
283
284#[derive(Deserialize, Default, JsonSchema)]
285pub struct ChannelModal {
286 pub contact_avatar: ImageStyle,
287 pub contact_username: ContainerStyle,
288 pub remove_member_button: ContainedText,
289 pub cancel_invite_button: ContainedText,
290 pub member_icon: IconButton,
291 pub invitee_icon: IconButton,
292 pub member_tag: ContainedText,
293}
294
295#[derive(Deserialize, Default, JsonSchema)]
296pub struct ProjectRow {
297 #[serde(flatten)]
298 pub container: ContainerStyle,
299 pub icon: Icon,
300 pub name: ContainedText,
301}
302
303#[derive(Deserialize, Default, Clone, Copy, JsonSchema)]
304pub struct TreeBranch {
305 pub width: f32,
306 pub color: Color,
307}
308
309#[derive(Deserialize, Default, JsonSchema)]
310pub struct ContactFinder {
311 pub contact_avatar: ImageStyle,
312 pub contact_username: ContainerStyle,
313 pub contact_button: IconButton,
314 pub disabled_contact_button: IconButton,
315}
316
317#[derive(Deserialize, Default, JsonSchema)]
318pub struct DropdownMenu {
319 #[serde(flatten)]
320 pub container: ContainerStyle,
321 pub header: Interactive<DropdownMenuItem>,
322 pub section_header: ContainedText,
323 pub item: Toggleable<Interactive<DropdownMenuItem>>,
324 pub row_height: f32,
325}
326
327#[derive(Deserialize, Default, JsonSchema)]
328pub struct DropdownMenuItem {
329 #[serde(flatten)]
330 pub container: ContainerStyle,
331 #[serde(flatten)]
332 pub text: TextStyle,
333 pub secondary_text: Option<TextStyle>,
334 #[serde(default)]
335 pub secondary_text_spacing: f32,
336}
337
338#[derive(Clone, Deserialize, Default, JsonSchema)]
339pub struct TabBar {
340 #[serde(flatten)]
341 pub container: ContainerStyle,
342 pub pane_button: Toggleable<Interactive<IconButton>>,
343 pub pane_button_container: ContainerStyle,
344 pub active_pane: TabStyles,
345 pub inactive_pane: TabStyles,
346 pub dragged_tab: Tab,
347 pub height: f32,
348 pub nav_button: Interactive<IconButton>,
349}
350
351impl TabBar {
352 pub fn tab_style(&self, pane_active: bool, tab_active: bool) -> &Tab {
353 let tabs = if pane_active {
354 &self.active_pane
355 } else {
356 &self.inactive_pane
357 };
358
359 if tab_active {
360 &tabs.active_tab
361 } else {
362 &tabs.inactive_tab
363 }
364 }
365}
366
367#[derive(Clone, Deserialize, Default, JsonSchema)]
368pub struct TabStyles {
369 pub active_tab: Tab,
370 pub inactive_tab: Tab,
371}
372
373#[derive(Clone, Deserialize, Default, JsonSchema)]
374pub struct AvatarRibbon {
375 #[serde(flatten)]
376 pub container: ContainerStyle,
377 pub width: f32,
378 pub height: f32,
379}
380
381#[derive(Clone, Deserialize, Default, JsonSchema)]
382pub struct OfflineIcon {
383 #[serde(flatten)]
384 pub container: ContainerStyle,
385 pub width: f32,
386 pub color: Color,
387}
388
389#[derive(Clone, Deserialize, Default, JsonSchema)]
390pub struct Tab {
391 pub height: f32,
392 #[serde(flatten)]
393 pub container: ContainerStyle,
394 #[serde(flatten)]
395 pub label: LabelStyle,
396 pub description: ContainedText,
397 pub spacing: f32,
398 pub close_icon_width: f32,
399 pub type_icon_width: f32,
400 pub icon_close: Color,
401 pub icon_close_active: Color,
402 pub icon_dirty: Color,
403 pub icon_conflict: Color,
404 pub git: GitProjectStatus,
405}
406
407#[derive(Clone, Deserialize, Default, JsonSchema)]
408pub struct Toolbar {
409 #[serde(flatten)]
410 pub container: ContainerStyle,
411 pub height: f32,
412 pub item_spacing: f32,
413 pub toggleable_tool: Toggleable<Interactive<IconButton>>,
414}
415
416#[derive(Clone, Deserialize, Default, JsonSchema)]
417pub struct Notifications {
418 #[serde(flatten)]
419 pub container: ContainerStyle,
420 pub width: f32,
421}
422
423#[derive(Clone, Deserialize, Default, JsonSchema)]
424pub struct Search {
425 #[serde(flatten)]
426 pub container: ContainerStyle,
427 pub editor: FindEditor,
428 pub invalid_editor: ContainerStyle,
429 pub option_button_group: ContainerStyle,
430 pub include_exclude_editor: FindEditor,
431 pub invalid_include_exclude_editor: ContainerStyle,
432 pub include_exclude_inputs: ContainedText,
433 pub option_button: Toggleable<Interactive<IconButton>>,
434 pub option_button_component: ToggleIconButtonStyle,
435 pub action_button: Toggleable<Interactive<ContainedText>>,
436 pub match_background: Color,
437 pub match_index: ContainedText,
438 pub major_results_status: TextStyle,
439 pub minor_results_status: TextStyle,
440 pub editor_icon: IconStyle,
441 pub mode_button: Toggleable<Interactive<ContainedText>>,
442 pub nav_button: Toggleable<Interactive<ContainedLabel>>,
443 pub search_bar_row_height: f32,
444 pub search_row_spacing: f32,
445 pub option_button_height: f32,
446 pub modes_container: ContainerStyle,
447}
448
449#[derive(Clone, Deserialize, Default, JsonSchema)]
450pub struct FindEditor {
451 #[serde(flatten)]
452 pub input: FieldEditor,
453 pub min_width: f32,
454 pub max_width: f32,
455}
456
457#[derive(Deserialize, Default, JsonSchema)]
458pub struct StatusBar {
459 #[serde(flatten)]
460 pub container: ContainerStyle,
461 pub height: f32,
462 pub item_spacing: f32,
463 pub cursor_position: TextStyle,
464 pub vim_mode_indicator: ContainedText,
465 pub active_language: Interactive<ContainedText>,
466 pub auto_update_progress_message: TextStyle,
467 pub auto_update_done_message: TextStyle,
468 pub lsp_status: Interactive<StatusBarLspStatus>,
469 pub panel_buttons: StatusBarPanelButtons,
470 pub diagnostic_summary: Interactive<StatusBarDiagnosticSummary>,
471 pub diagnostic_message: Interactive<ContainedText>,
472}
473
474#[derive(Deserialize, Default, JsonSchema)]
475pub struct StatusBarPanelButtons {
476 pub group_left: ContainerStyle,
477 pub group_bottom: ContainerStyle,
478 pub group_right: ContainerStyle,
479 pub button: Toggleable<Interactive<PanelButton>>,
480}
481
482#[derive(Deserialize, Default, JsonSchema)]
483pub struct StatusBarDiagnosticSummary {
484 pub container_ok: ContainerStyle,
485 pub container_warning: ContainerStyle,
486 pub container_error: ContainerStyle,
487 pub text: TextStyle,
488 pub icon_color_ok: Color,
489 pub icon_color_warning: Color,
490 pub icon_color_error: Color,
491 pub height: f32,
492 pub icon_width: f32,
493 pub icon_spacing: f32,
494 pub summary_spacing: f32,
495}
496
497#[derive(Deserialize, Default, JsonSchema)]
498pub struct StatusBarLspStatus {
499 #[serde(flatten)]
500 pub container: ContainerStyle,
501 pub height: f32,
502 pub icon_spacing: f32,
503 pub icon_color: Color,
504 pub icon_width: f32,
505 pub message: TextStyle,
506}
507
508#[derive(Deserialize, Default, JsonSchema)]
509pub struct Dock {
510 pub left: ContainerStyle,
511 pub bottom: ContainerStyle,
512 pub right: ContainerStyle,
513}
514
515#[derive(Clone, Deserialize, Default, JsonSchema)]
516pub struct PanelButton {
517 #[serde(flatten)]
518 pub container: ContainerStyle,
519 pub icon_color: Color,
520 pub icon_size: f32,
521 pub label: ContainedText,
522}
523
524#[derive(Deserialize, Default, JsonSchema)]
525pub struct ProjectPanel {
526 #[serde(flatten)]
527 pub container: ContainerStyle,
528 pub entry: Toggleable<Interactive<ProjectPanelEntry>>,
529 pub dragged_entry: ProjectPanelEntry,
530 pub ignored_entry: Toggleable<Interactive<ProjectPanelEntry>>,
531 pub cut_entry: Toggleable<Interactive<ProjectPanelEntry>>,
532 pub filename_editor: FieldEditor,
533 pub indent_width: f32,
534 pub open_project_button: Interactive<ContainedText>,
535}
536
537#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
538pub struct ProjectPanelEntry {
539 pub height: f32,
540 #[serde(flatten)]
541 pub container: ContainerStyle,
542 pub text: TextStyle,
543 pub icon_size: f32,
544 pub icon_color: Color,
545 pub chevron_color: Color,
546 pub chevron_size: f32,
547 pub icon_spacing: f32,
548 pub status: EntryStatus,
549}
550
551#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
552pub struct EntryStatus {
553 pub git: GitProjectStatus,
554}
555
556#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
557pub struct GitProjectStatus {
558 pub modified: Color,
559 pub inserted: Color,
560 pub conflict: Color,
561}
562
563#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
564pub struct ContextMenu {
565 #[serde(flatten)]
566 pub container: ContainerStyle,
567 pub item: Toggleable<Interactive<ContextMenuItem>>,
568 pub keystroke_margin: f32,
569 pub separator: ContainerStyle,
570}
571
572#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
573pub struct ContextMenuItem {
574 #[serde(flatten)]
575 pub container: ContainerStyle,
576 pub label: TextStyle,
577 pub keystroke: ContainedText,
578 pub icon_width: f32,
579 pub icon_spacing: f32,
580}
581
582#[derive(Debug, Deserialize, Default, JsonSchema)]
583pub struct CommandPalette {
584 pub key: Toggleable<ContainedLabel>,
585 pub keystroke_spacing: f32,
586}
587
588#[derive(Deserialize, Default, JsonSchema)]
589pub struct InviteLink {
590 #[serde(flatten)]
591 pub container: ContainerStyle,
592 #[serde(flatten)]
593 pub label: LabelStyle,
594 pub icon: Icon,
595}
596
597#[derive(Deserialize, Clone, Copy, Default, JsonSchema)]
598pub struct Icon {
599 #[serde(flatten)]
600 pub container: ContainerStyle,
601 pub color: Color,
602 pub width: f32,
603}
604
605#[derive(Deserialize, Clone, Copy, Default, JsonSchema)]
606pub struct IconButton {
607 #[serde(flatten)]
608 pub container: ContainerStyle,
609 pub color: Color,
610 pub icon_width: f32,
611 pub button_width: f32,
612}
613
614#[derive(Deserialize, Default, JsonSchema)]
615pub struct ChatMessage {
616 #[serde(flatten)]
617 pub container: ContainerStyle,
618 pub body: TextStyle,
619 pub sender: ContainedText,
620 pub timestamp: ContainedText,
621}
622
623#[derive(Deserialize, Default, JsonSchema)]
624pub struct ChannelSelect {
625 #[serde(flatten)]
626 pub container: ContainerStyle,
627 pub header: ChannelName,
628 pub item: ChannelName,
629 pub active_item: ChannelName,
630 pub hovered_item: ChannelName,
631 pub hovered_active_item: ChannelName,
632 pub menu: ContainerStyle,
633}
634
635#[derive(Deserialize, Default, JsonSchema)]
636pub struct ChannelName {
637 #[serde(flatten)]
638 pub container: ContainerStyle,
639 pub hash: ContainedText,
640 pub name: TextStyle,
641}
642
643#[derive(Clone, Deserialize, Default, JsonSchema)]
644pub struct Picker {
645 #[serde(flatten)]
646 pub container: ContainerStyle,
647 pub empty_container: ContainerStyle,
648 pub input_editor: FieldEditor,
649 pub empty_input_editor: FieldEditor,
650 pub no_matches: ContainedLabel,
651 pub item: Toggleable<Interactive<ContainedLabel>>,
652 pub header: ContainedLabel,
653 pub footer: Interactive<ContainedLabel>,
654}
655
656#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
657pub struct ContainedText {
658 #[serde(flatten)]
659 pub container: ContainerStyle,
660 #[serde(flatten)]
661 pub text: TextStyle,
662}
663
664#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
665pub struct ContainedLabel {
666 #[serde(flatten)]
667 pub container: ContainerStyle,
668 #[serde(flatten)]
669 pub label: LabelStyle,
670}
671
672#[derive(Clone, Deserialize, Default, JsonSchema)]
673pub struct ProjectDiagnostics {
674 #[serde(flatten)]
675 pub container: ContainerStyle,
676 pub empty_message: TextStyle,
677 pub tab_icon_width: f32,
678 pub tab_icon_spacing: f32,
679 pub tab_summary_spacing: f32,
680}
681
682#[derive(Deserialize, Default, JsonSchema)]
683pub struct ContactNotification {
684 pub header_avatar: ImageStyle,
685 pub header_message: ContainedText,
686 pub header_height: f32,
687 pub body_message: ContainedText,
688 pub button: Interactive<ContainedText>,
689 pub dismiss_button: Interactive<IconButton>,
690}
691
692#[derive(Deserialize, Default, JsonSchema)]
693pub struct UpdateNotification {
694 pub message: ContainedText,
695 pub action_message: Interactive<ContainedText>,
696 pub dismiss_button: Interactive<IconButton>,
697}
698
699#[derive(Deserialize, Default, JsonSchema)]
700pub struct MessageNotification {
701 pub message: ContainedText,
702 pub action_message: Interactive<ContainedText>,
703 pub dismiss_button: Interactive<IconButton>,
704}
705
706#[derive(Deserialize, Default, JsonSchema)]
707pub struct ProjectSharedNotification {
708 pub window_height: f32,
709 pub window_width: f32,
710 #[serde(default)]
711 pub background: Color,
712 pub owner_container: ContainerStyle,
713 pub owner_avatar: ImageStyle,
714 pub owner_metadata: ContainerStyle,
715 pub owner_username: ContainedText,
716 pub message: ContainedText,
717 pub worktree_roots: ContainedText,
718 pub button_width: f32,
719 pub open_button: ContainedText,
720 pub dismiss_button: ContainedText,
721}
722
723#[derive(Deserialize, Default, JsonSchema)]
724pub struct IncomingCallNotification {
725 pub window_height: f32,
726 pub window_width: f32,
727 #[serde(default)]
728 pub background: Color,
729 pub caller_container: ContainerStyle,
730 pub caller_avatar: ImageStyle,
731 pub caller_metadata: ContainerStyle,
732 pub caller_username: ContainedText,
733 pub caller_message: ContainedText,
734 pub worktree_roots: ContainedText,
735 pub button_width: f32,
736 pub accept_button: ContainedText,
737 pub decline_button: ContainedText,
738}
739
740#[derive(Clone, Deserialize, Default, JsonSchema)]
741pub struct Editor {
742 pub text_color: Color,
743 #[serde(default)]
744 pub background: Color,
745 pub selection: SelectionStyle,
746 pub gutter_background: Color,
747 pub gutter_padding_factor: f32,
748 pub active_line_background: Color,
749 pub highlighted_line_background: Color,
750 pub rename_fade: f32,
751 pub document_highlight_read_background: Color,
752 pub document_highlight_write_background: Color,
753 pub diff: DiffStyle,
754 pub wrap_guide: Color,
755 pub active_wrap_guide: Color,
756 pub line_number: Color,
757 pub line_number_active: Color,
758 pub guest_selections: Vec<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}
1153
1154#[derive(Clone, Deserialize, Default, JsonSchema)]
1155pub struct Contained<T> {
1156 container: ContainerStyle,
1157 contained: T,
1158}
1159
1160#[derive(Clone, Deserialize, Default, JsonSchema)]
1161pub struct SavedConversation {
1162 pub container: Interactive<ContainerStyle>,
1163 pub saved_at: ContainedText,
1164 pub title: ContainedText,
1165}
1166
1167#[derive(Clone, Deserialize, Default, JsonSchema)]
1168pub struct FeedbackStyle {
1169 pub submit_button: Interactive<ContainedText>,
1170 pub button_margin: f32,
1171 pub info_text_default: ContainedText,
1172 pub link_text_default: ContainedText,
1173 pub link_text_hover: ContainedText,
1174}
1175
1176#[derive(Clone, Deserialize, Default, JsonSchema)]
1177pub struct WelcomeStyle {
1178 pub page_width: f32,
1179 pub logo: SvgStyle,
1180 pub logo_subheading: ContainedText,
1181 pub usage_note: ContainedText,
1182 pub checkbox: CheckboxStyle,
1183 pub checkbox_container: ContainerStyle,
1184 pub button: Interactive<ContainedText>,
1185 pub button_group: ContainerStyle,
1186 pub heading_group: ContainerStyle,
1187 pub checkbox_group: ContainerStyle,
1188}
1189
1190#[derive(Clone, Deserialize, Default, JsonSchema)]
1191pub struct ColorScheme {
1192 pub name: String,
1193 pub is_light: bool,
1194 pub ramps: RampSet,
1195 pub lowest: Layer,
1196 pub middle: Layer,
1197 pub highest: Layer,
1198
1199 pub popover_shadow: Shadow,
1200 pub modal_shadow: Shadow,
1201
1202 pub players: Vec<Player>,
1203}
1204
1205#[derive(Clone, Deserialize, Default, JsonSchema)]
1206pub struct Player {
1207 pub cursor: Color,
1208 pub selection: Color,
1209}
1210
1211#[derive(Clone, Deserialize, Default, JsonSchema)]
1212pub struct RampSet {
1213 pub neutral: Vec<Color>,
1214 pub red: Vec<Color>,
1215 pub orange: Vec<Color>,
1216 pub yellow: Vec<Color>,
1217 pub green: Vec<Color>,
1218 pub cyan: Vec<Color>,
1219 pub blue: Vec<Color>,
1220 pub violet: Vec<Color>,
1221 pub magenta: Vec<Color>,
1222}
1223
1224#[derive(Clone, Deserialize, Default, JsonSchema)]
1225pub struct Layer {
1226 pub base: StyleSet,
1227 pub variant: StyleSet,
1228 pub on: StyleSet,
1229 pub accent: StyleSet,
1230 pub positive: StyleSet,
1231 pub warning: StyleSet,
1232 pub negative: StyleSet,
1233}
1234
1235#[derive(Clone, Deserialize, Default, JsonSchema)]
1236pub struct StyleSet {
1237 pub default: Style,
1238 pub active: Style,
1239 pub disabled: Style,
1240 pub hovered: Style,
1241 pub pressed: Style,
1242 pub inverted: Style,
1243}
1244
1245#[derive(Clone, Deserialize, Default, JsonSchema)]
1246pub struct Style {
1247 pub background: Color,
1248 pub border: Color,
1249 pub foreground: Color,
1250}