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