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