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