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