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