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