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