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