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