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