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