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