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