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