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