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