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