theme.rs

  1mod theme_registry;
  2
  3use gpui::{
  4    color::Color,
  5    elements::{ContainerStyle, ImageStyle, LabelStyle, Shadow, TooltipStyle},
  6    fonts::{HighlightStyle, TextStyle},
  7    Border, MouseState,
  8};
  9use serde::{de::DeserializeOwned, Deserialize};
 10use serde_json::Value;
 11use std::{collections::HashMap, sync::Arc};
 12
 13pub use theme_registry::*;
 14
 15#[derive(Deserialize, Default)]
 16pub struct Theme {
 17    #[serde(default)]
 18    pub meta: ThemeMeta,
 19    pub workspace: Workspace,
 20    pub context_menu: ContextMenu,
 21    pub contacts_popover: ContactsPopover,
 22    pub contact_list: ContactList,
 23    pub contact_finder: ContactFinder,
 24    pub project_panel: ProjectPanel,
 25    pub command_palette: CommandPalette,
 26    pub picker: Picker,
 27    pub editor: Editor,
 28    pub search: Search,
 29    pub project_diagnostics: ProjectDiagnostics,
 30    pub breadcrumbs: ContainedText,
 31    pub shared_screen: ContainerStyle,
 32    pub contact_notification: ContactNotification,
 33    pub update_notification: UpdateNotification,
 34    pub simple_message_notification: MessageNotification,
 35    pub project_shared_notification: ProjectSharedNotification,
 36    pub incoming_call_notification: IncomingCallNotification,
 37    pub tooltip: TooltipStyle,
 38    pub terminal: TerminalStyle,
 39    pub feedback: FeedbackStyle,
 40    pub welcome: WelcomeStyle,
 41    pub color_scheme: ColorScheme,
 42}
 43
 44#[derive(Deserialize, Default, Clone)]
 45pub struct ThemeMeta {
 46    pub name: String,
 47    pub is_light: bool,
 48}
 49
 50#[derive(Deserialize, Default)]
 51pub struct Workspace {
 52    pub background: Color,
 53    pub titlebar: Titlebar,
 54    pub tab_bar: TabBar,
 55    pub pane_divider: Border,
 56    pub leader_border_opacity: f32,
 57    pub leader_border_width: f32,
 58    pub sidebar: Sidebar,
 59    pub status_bar: StatusBar,
 60    pub toolbar: Toolbar,
 61    pub disconnected_overlay: ContainedText,
 62    pub modal: ContainerStyle,
 63    pub notification: ContainerStyle,
 64    pub notifications: Notifications,
 65    pub joining_project_avatar: ImageStyle,
 66    pub joining_project_message: ContainedText,
 67    pub external_location_message: ContainedText,
 68    pub dock: Dock,
 69    pub drop_target_overlay_color: Color,
 70}
 71
 72#[derive(Clone, Deserialize, Default)]
 73pub struct Titlebar {
 74    #[serde(flatten)]
 75    pub container: ContainerStyle,
 76    pub height: f32,
 77    pub title: TextStyle,
 78    pub item_spacing: f32,
 79    pub face_pile_spacing: f32,
 80    pub avatar_ribbon: AvatarRibbon,
 81    pub follower_avatar_overlap: f32,
 82    pub leader_selection: ContainerStyle,
 83    pub offline_icon: OfflineIcon,
 84    pub leader_avatar: AvatarStyle,
 85    pub follower_avatar: AvatarStyle,
 86    pub inactive_avatar_grayscale: bool,
 87    pub sign_in_prompt: Interactive<ContainedText>,
 88    pub outdated_warning: ContainedText,
 89    pub share_button: Interactive<ContainedText>,
 90    pub call_control: Interactive<IconButton>,
 91    pub toggle_contacts_button: Interactive<IconButton>,
 92    pub user_menu_button: Interactive<IconButton>,
 93    pub toggle_contacts_badge: ContainerStyle,
 94}
 95
 96#[derive(Copy, Clone, Deserialize, Default)]
 97pub struct AvatarStyle {
 98    #[serde(flatten)]
 99    pub image: ImageStyle,
100    pub outer_width: f32,
101    pub outer_corner_radius: f32,
102}
103
104#[derive(Deserialize, Default)]
105pub struct ContactsPopover {
106    #[serde(flatten)]
107    pub container: ContainerStyle,
108    pub height: f32,
109    pub width: f32,
110    pub invite_row_height: f32,
111    pub invite_row: Interactive<ContainedLabel>,
112}
113
114#[derive(Deserialize, Default)]
115pub struct ContactList {
116    pub user_query_editor: FieldEditor,
117    pub user_query_editor_height: f32,
118    pub add_contact_button: IconButton,
119    pub header_row: Interactive<ContainedText>,
120    pub leave_call: Interactive<ContainedText>,
121    pub contact_row: Interactive<ContainerStyle>,
122    pub row_height: f32,
123    pub project_row: Interactive<ProjectRow>,
124    pub tree_branch: Interactive<TreeBranch>,
125    pub contact_avatar: ImageStyle,
126    pub contact_status_free: ContainerStyle,
127    pub contact_status_busy: ContainerStyle,
128    pub contact_username: ContainedText,
129    pub contact_button: Interactive<IconButton>,
130    pub contact_button_spacing: f32,
131    pub disabled_button: IconButton,
132    pub section_icon_size: f32,
133    pub calling_indicator: ContainedText,
134}
135
136#[derive(Deserialize, Default)]
137pub struct ProjectRow {
138    #[serde(flatten)]
139    pub container: ContainerStyle,
140    pub icon: Icon,
141    pub name: ContainedText,
142}
143
144#[derive(Deserialize, Default, Clone, Copy)]
145pub struct TreeBranch {
146    pub width: f32,
147    pub color: Color,
148}
149
150#[derive(Deserialize, Default)]
151pub struct ContactFinder {
152    pub picker: Picker,
153    pub row_height: f32,
154    pub contact_avatar: ImageStyle,
155    pub contact_username: ContainerStyle,
156    pub contact_button: IconButton,
157    pub disabled_contact_button: IconButton,
158}
159
160#[derive(Clone, Deserialize, Default)]
161pub struct TabBar {
162    #[serde(flatten)]
163    pub container: ContainerStyle,
164    pub pane_button: Interactive<IconButton>,
165    pub pane_button_container: ContainerStyle,
166    pub active_pane: TabStyles,
167    pub inactive_pane: TabStyles,
168    pub dragged_tab: Tab,
169    pub height: f32,
170}
171
172impl TabBar {
173    pub fn tab_style(&self, pane_active: bool, tab_active: bool) -> &Tab {
174        let tabs = if pane_active {
175            &self.active_pane
176        } else {
177            &self.inactive_pane
178        };
179
180        if tab_active {
181            &tabs.active_tab
182        } else {
183            &tabs.inactive_tab
184        }
185    }
186}
187
188#[derive(Clone, Deserialize, Default)]
189pub struct TabStyles {
190    pub active_tab: Tab,
191    pub inactive_tab: Tab,
192}
193
194#[derive(Clone, Deserialize, Default)]
195pub struct AvatarRibbon {
196    #[serde(flatten)]
197    pub container: ContainerStyle,
198    pub width: f32,
199    pub height: f32,
200}
201
202#[derive(Clone, Deserialize, Default)]
203pub struct OfflineIcon {
204    #[serde(flatten)]
205    pub container: ContainerStyle,
206    pub width: f32,
207    pub color: Color,
208}
209
210#[derive(Clone, Deserialize, Default)]
211pub struct Tab {
212    pub height: f32,
213    #[serde(flatten)]
214    pub container: ContainerStyle,
215    #[serde(flatten)]
216    pub label: LabelStyle,
217    pub description: ContainedText,
218    pub spacing: f32,
219    pub close_icon_width: f32,
220    pub type_icon_width: f32,
221    pub icon_close: Color,
222    pub icon_close_active: Color,
223    pub icon_dirty: Color,
224    pub icon_conflict: Color,
225}
226
227#[derive(Clone, Deserialize, Default)]
228pub struct Toolbar {
229    #[serde(flatten)]
230    pub container: ContainerStyle,
231    pub height: f32,
232    pub item_spacing: f32,
233    pub nav_button: Interactive<IconButton>,
234}
235
236#[derive(Clone, Deserialize, Default)]
237pub struct Dock {
238    pub initial_size_right: f32,
239    pub initial_size_bottom: f32,
240    pub wash_color: Color,
241    pub panel: ContainerStyle,
242    pub maximized: ContainerStyle,
243}
244
245#[derive(Clone, Deserialize, Default)]
246pub struct Notifications {
247    #[serde(flatten)]
248    pub container: ContainerStyle,
249    pub width: f32,
250}
251
252#[derive(Clone, Deserialize, Default)]
253pub struct Search {
254    #[serde(flatten)]
255    pub container: ContainerStyle,
256    pub editor: FindEditor,
257    pub invalid_editor: ContainerStyle,
258    pub option_button_group: ContainerStyle,
259    pub option_button: Interactive<ContainedText>,
260    pub match_background: Color,
261    pub match_index: ContainedText,
262    pub results_status: TextStyle,
263    pub dismiss_button: Interactive<IconButton>,
264}
265
266#[derive(Clone, Deserialize, Default)]
267pub struct FindEditor {
268    #[serde(flatten)]
269    pub input: FieldEditor,
270    pub min_width: f32,
271    pub max_width: f32,
272}
273
274#[derive(Deserialize, Default)]
275pub struct StatusBar {
276    #[serde(flatten)]
277    pub container: ContainerStyle,
278    pub height: f32,
279    pub item_spacing: f32,
280    pub cursor_position: TextStyle,
281    pub auto_update_progress_message: TextStyle,
282    pub auto_update_done_message: TextStyle,
283    pub lsp_status: Interactive<StatusBarLspStatus>,
284    pub feedback: Interactive<TextStyle>,
285    pub sidebar_buttons: StatusBarSidebarButtons,
286    pub diagnostic_summary: Interactive<StatusBarDiagnosticSummary>,
287    pub diagnostic_message: Interactive<ContainedText>,
288}
289
290#[derive(Deserialize, Default)]
291pub struct StatusBarSidebarButtons {
292    pub group_left: ContainerStyle,
293    pub group_right: ContainerStyle,
294    pub item: Interactive<SidebarItem>,
295    pub badge: ContainerStyle,
296}
297
298#[derive(Deserialize, Default)]
299pub struct StatusBarDiagnosticSummary {
300    pub container_ok: ContainerStyle,
301    pub container_warning: ContainerStyle,
302    pub container_error: ContainerStyle,
303    pub text: TextStyle,
304    pub icon_color_ok: Color,
305    pub icon_color_warning: Color,
306    pub icon_color_error: Color,
307    pub height: f32,
308    pub icon_width: f32,
309    pub icon_spacing: f32,
310    pub summary_spacing: f32,
311}
312
313#[derive(Deserialize, Default)]
314pub struct StatusBarLspStatus {
315    #[serde(flatten)]
316    pub container: ContainerStyle,
317    pub height: f32,
318    pub icon_spacing: f32,
319    pub icon_color: Color,
320    pub icon_width: f32,
321    pub message: TextStyle,
322}
323
324#[derive(Deserialize, Default)]
325pub struct Sidebar {
326    pub initial_size: f32,
327    #[serde(flatten)]
328    pub container: ContainerStyle,
329}
330
331#[derive(Clone, Copy, Deserialize, Default)]
332pub struct SidebarItem {
333    #[serde(flatten)]
334    pub container: ContainerStyle,
335    pub icon_color: Color,
336    pub icon_size: f32,
337}
338
339#[derive(Deserialize, Default)]
340pub struct ProjectPanel {
341    #[serde(flatten)]
342    pub container: ContainerStyle,
343    pub entry: Interactive<ProjectPanelEntry>,
344    pub dragged_entry: ProjectPanelEntry,
345    pub ignored_entry: Interactive<ProjectPanelEntry>,
346    pub cut_entry: Interactive<ProjectPanelEntry>,
347    pub filename_editor: FieldEditor,
348    pub indent_width: f32,
349}
350
351#[derive(Clone, Debug, Deserialize, Default)]
352pub struct ProjectPanelEntry {
353    pub height: f32,
354    #[serde(flatten)]
355    pub container: ContainerStyle,
356    pub text: TextStyle,
357    pub icon_color: Color,
358    pub icon_size: f32,
359    pub icon_spacing: f32,
360}
361
362#[derive(Clone, Debug, Deserialize, Default)]
363pub struct ContextMenu {
364    #[serde(flatten)]
365    pub container: ContainerStyle,
366    pub item: Interactive<ContextMenuItem>,
367    pub keystroke_margin: f32,
368    pub separator: ContainerStyle,
369}
370
371#[derive(Clone, Debug, Deserialize, Default)]
372pub struct ContextMenuItem {
373    #[serde(flatten)]
374    pub container: ContainerStyle,
375    pub label: TextStyle,
376    pub keystroke: ContainedText,
377    pub icon_width: f32,
378    pub icon_spacing: f32,
379}
380
381#[derive(Debug, Deserialize, Default)]
382pub struct CommandPalette {
383    pub key: Interactive<ContainedLabel>,
384    pub keystroke_spacing: f32,
385}
386
387#[derive(Deserialize, Default)]
388pub struct InviteLink {
389    #[serde(flatten)]
390    pub container: ContainerStyle,
391    #[serde(flatten)]
392    pub label: LabelStyle,
393    pub icon: Icon,
394}
395
396#[derive(Deserialize, Clone, Copy, Default)]
397pub struct Icon {
398    #[serde(flatten)]
399    pub container: ContainerStyle,
400    pub color: Color,
401    pub width: f32,
402}
403
404#[derive(Deserialize, Clone, Copy, Default)]
405pub struct IconButton {
406    #[serde(flatten)]
407    pub container: ContainerStyle,
408    pub color: Color,
409    pub icon_width: f32,
410    pub button_width: f32,
411}
412
413#[derive(Deserialize, Default)]
414pub struct ChatMessage {
415    #[serde(flatten)]
416    pub container: ContainerStyle,
417    pub body: TextStyle,
418    pub sender: ContainedText,
419    pub timestamp: ContainedText,
420}
421
422#[derive(Deserialize, Default)]
423pub struct ChannelSelect {
424    #[serde(flatten)]
425    pub container: ContainerStyle,
426    pub header: ChannelName,
427    pub item: ChannelName,
428    pub active_item: ChannelName,
429    pub hovered_item: ChannelName,
430    pub hovered_active_item: ChannelName,
431    pub menu: ContainerStyle,
432}
433
434#[derive(Deserialize, Default)]
435pub struct ChannelName {
436    #[serde(flatten)]
437    pub container: ContainerStyle,
438    pub hash: ContainedText,
439    pub name: TextStyle,
440}
441
442#[derive(Clone, Deserialize, Default)]
443pub struct Picker {
444    #[serde(flatten)]
445    pub container: ContainerStyle,
446    pub empty_container: ContainerStyle,
447    pub input_editor: FieldEditor,
448    pub empty_input_editor: FieldEditor,
449    pub no_matches: ContainedLabel,
450    pub item: Interactive<ContainedLabel>,
451}
452
453#[derive(Clone, Debug, Deserialize, Default)]
454pub struct ContainedText {
455    #[serde(flatten)]
456    pub container: ContainerStyle,
457    #[serde(flatten)]
458    pub text: TextStyle,
459}
460
461#[derive(Clone, Debug, Deserialize, Default)]
462pub struct ContainedLabel {
463    #[serde(flatten)]
464    pub container: ContainerStyle,
465    #[serde(flatten)]
466    pub label: LabelStyle,
467}
468
469#[derive(Clone, Deserialize, Default)]
470pub struct ProjectDiagnostics {
471    #[serde(flatten)]
472    pub container: ContainerStyle,
473    pub empty_message: TextStyle,
474    pub tab_icon_width: f32,
475    pub tab_icon_spacing: f32,
476    pub tab_summary_spacing: f32,
477}
478
479#[derive(Deserialize, Default)]
480pub struct ContactNotification {
481    pub header_avatar: ImageStyle,
482    pub header_message: ContainedText,
483    pub header_height: f32,
484    pub body_message: ContainedText,
485    pub button: Interactive<ContainedText>,
486    pub dismiss_button: Interactive<IconButton>,
487}
488
489#[derive(Deserialize, Default)]
490pub struct UpdateNotification {
491    pub message: ContainedText,
492    pub action_message: Interactive<ContainedText>,
493    pub dismiss_button: Interactive<IconButton>,
494}
495
496#[derive(Deserialize, Default)]
497pub struct MessageNotification {
498    pub message: ContainedText,
499    pub action_message: Interactive<ContainedText>,
500    pub dismiss_button: Interactive<IconButton>,
501}
502
503#[derive(Deserialize, Default)]
504pub struct ProjectSharedNotification {
505    pub window_height: f32,
506    pub window_width: f32,
507    #[serde(default)]
508    pub background: Color,
509    pub owner_container: ContainerStyle,
510    pub owner_avatar: ImageStyle,
511    pub owner_metadata: ContainerStyle,
512    pub owner_username: ContainedText,
513    pub message: ContainedText,
514    pub worktree_roots: ContainedText,
515    pub button_width: f32,
516    pub open_button: ContainedText,
517    pub dismiss_button: ContainedText,
518}
519
520#[derive(Deserialize, Default)]
521pub struct IncomingCallNotification {
522    pub window_height: f32,
523    pub window_width: f32,
524    #[serde(default)]
525    pub background: Color,
526    pub caller_container: ContainerStyle,
527    pub caller_avatar: ImageStyle,
528    pub caller_metadata: ContainerStyle,
529    pub caller_username: ContainedText,
530    pub caller_message: ContainedText,
531    pub worktree_roots: ContainedText,
532    pub button_width: f32,
533    pub accept_button: ContainedText,
534    pub decline_button: ContainedText,
535}
536
537#[derive(Clone, Deserialize, Default)]
538pub struct Editor {
539    pub text_color: Color,
540    #[serde(default)]
541    pub background: Color,
542    pub selection: SelectionStyle,
543    pub gutter_background: Color,
544    pub gutter_padding_factor: f32,
545    pub active_line_background: Color,
546    pub highlighted_line_background: Color,
547    pub rename_fade: f32,
548    pub document_highlight_read_background: Color,
549    pub document_highlight_write_background: Color,
550    pub diff: DiffStyle,
551    pub line_number: Color,
552    pub line_number_active: Color,
553    pub guest_selections: Vec<SelectionStyle>,
554    pub syntax: Arc<SyntaxTheme>,
555    pub diagnostic_path_header: DiagnosticPathHeader,
556    pub diagnostic_header: DiagnosticHeader,
557    pub error_diagnostic: DiagnosticStyle,
558    pub invalid_error_diagnostic: DiagnosticStyle,
559    pub warning_diagnostic: DiagnosticStyle,
560    pub invalid_warning_diagnostic: DiagnosticStyle,
561    pub information_diagnostic: DiagnosticStyle,
562    pub invalid_information_diagnostic: DiagnosticStyle,
563    pub hint_diagnostic: DiagnosticStyle,
564    pub invalid_hint_diagnostic: DiagnosticStyle,
565    pub autocomplete: AutocompleteStyle,
566    pub code_actions: CodeActions,
567    pub folds: Folds,
568    pub unnecessary_code_fade: f32,
569    pub hover_popover: HoverPopover,
570    pub link_definition: HighlightStyle,
571    pub composition_mark: HighlightStyle,
572    pub jump_icon: Interactive<IconButton>,
573    pub scrollbar: Scrollbar,
574}
575
576#[derive(Clone, Deserialize, Default)]
577pub struct Scrollbar {
578    pub track: ContainerStyle,
579    pub thumb: ContainerStyle,
580    pub width: f32,
581    pub min_height_factor: f32,
582}
583
584#[derive(Clone, Deserialize, Default)]
585pub struct DiagnosticPathHeader {
586    #[serde(flatten)]
587    pub container: ContainerStyle,
588    pub filename: ContainedText,
589    pub path: ContainedText,
590    pub text_scale_factor: f32,
591}
592
593#[derive(Clone, Deserialize, Default)]
594pub struct DiagnosticHeader {
595    #[serde(flatten)]
596    pub container: ContainerStyle,
597    pub message: ContainedLabel,
598    pub code: ContainedText,
599    pub text_scale_factor: f32,
600    pub icon_width_factor: f32,
601}
602
603#[derive(Clone, Deserialize, Default)]
604pub struct DiagnosticStyle {
605    pub message: LabelStyle,
606    #[serde(default)]
607    pub header: ContainerStyle,
608    pub text_scale_factor: f32,
609}
610
611#[derive(Clone, Deserialize, Default)]
612pub struct AutocompleteStyle {
613    #[serde(flatten)]
614    pub container: ContainerStyle,
615    pub item: ContainerStyle,
616    pub selected_item: ContainerStyle,
617    pub hovered_item: ContainerStyle,
618    pub match_highlight: HighlightStyle,
619}
620
621#[derive(Clone, Copy, Default, Deserialize)]
622pub struct SelectionStyle {
623    pub cursor: Color,
624    pub selection: Color,
625}
626
627#[derive(Clone, Deserialize, Default)]
628pub struct FieldEditor {
629    #[serde(flatten)]
630    pub container: ContainerStyle,
631    pub text: TextStyle,
632    #[serde(default)]
633    pub placeholder_text: Option<TextStyle>,
634    pub selection: SelectionStyle,
635}
636
637#[derive(Clone, Deserialize, Default)]
638pub struct InteractiveColor {
639    pub color: Color,
640}
641
642#[derive(Clone, Deserialize, Default)]
643pub struct CodeActions {
644    #[serde(default)]
645    pub indicator: Interactive<InteractiveColor>,
646    pub vertical_scale: f32,
647}
648
649#[derive(Clone, Deserialize, Default)]
650pub struct Folds {
651    pub indicator: Interactive<InteractiveColor>,
652    pub ellipses: FoldEllipses,
653    pub fold_background: Color,
654    pub icon_width: f32,
655    pub folded_icon: String,
656    pub foldable_icon: String,
657}
658
659#[derive(Clone, Deserialize, Default)]
660pub struct FoldEllipses {
661    pub text_color: Color,
662    pub background: Interactive<InteractiveColor>,
663    pub corner_radius_factor: f32,
664}
665
666#[derive(Clone, Deserialize, Default)]
667pub struct DiffStyle {
668    pub inserted: Color,
669    pub modified: Color,
670    pub deleted: Color,
671    pub removed_width_em: f32,
672    pub width_em: f32,
673    pub corner_radius: f32,
674}
675
676#[derive(Debug, Default, Clone, Copy)]
677pub struct Interactive<T> {
678    pub default: T,
679    pub hover: Option<T>,
680    pub clicked: Option<T>,
681    pub active: Option<T>,
682    pub disabled: Option<T>,
683}
684
685impl<T> Interactive<T> {
686    pub fn style_for(&self, state: &mut MouseState, active: bool) -> &T {
687        if active {
688            self.active.as_ref().unwrap_or(&self.default)
689        } else if state.clicked() == Some(gpui::MouseButton::Left) && self.clicked.is_some() {
690            self.clicked.as_ref().unwrap()
691        } else if state.hovered() {
692            self.hover.as_ref().unwrap_or(&self.default)
693        } else {
694            &self.default
695        }
696    }
697
698    pub fn disabled_style(&self) -> &T {
699        self.disabled.as_ref().unwrap_or(&self.default)
700    }
701}
702
703impl<'de, T: DeserializeOwned> Deserialize<'de> for Interactive<T> {
704    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
705    where
706        D: serde::Deserializer<'de>,
707    {
708        #[derive(Deserialize)]
709        struct Helper {
710            #[serde(flatten)]
711            default: Value,
712            hover: Option<Value>,
713            clicked: Option<Value>,
714            active: Option<Value>,
715            disabled: Option<Value>,
716        }
717
718        let json = Helper::deserialize(deserializer)?;
719
720        let deserialize_state = |state_json: Option<Value>| -> Result<Option<T>, D::Error> {
721            if let Some(mut state_json) = state_json {
722                if let Value::Object(state_json) = &mut state_json {
723                    if let Value::Object(default) = &json.default {
724                        for (key, value) in default {
725                            if !state_json.contains_key(key) {
726                                state_json.insert(key.clone(), value.clone());
727                            }
728                        }
729                    }
730                }
731                Ok(Some(
732                    serde_json::from_value::<T>(state_json).map_err(serde::de::Error::custom)?,
733                ))
734            } else {
735                Ok(None)
736            }
737        };
738
739        let hover = deserialize_state(json.hover)?;
740        let clicked = deserialize_state(json.clicked)?;
741        let active = deserialize_state(json.active)?;
742        let disabled = deserialize_state(json.disabled)?;
743        let default = serde_json::from_value(json.default).map_err(serde::de::Error::custom)?;
744
745        Ok(Interactive {
746            default,
747            hover,
748            clicked,
749            active,
750            disabled,
751        })
752    }
753}
754
755impl Editor {
756    pub fn replica_selection_style(&self, replica_id: u16) -> &SelectionStyle {
757        let style_ix = replica_id as usize % (self.guest_selections.len() + 1);
758        if style_ix == 0 {
759            &self.selection
760        } else {
761            &self.guest_selections[style_ix - 1]
762        }
763    }
764}
765
766#[derive(Default)]
767pub struct SyntaxTheme {
768    pub highlights: Vec<(String, HighlightStyle)>,
769}
770
771impl SyntaxTheme {
772    pub fn new(highlights: Vec<(String, HighlightStyle)>) -> Self {
773        Self { highlights }
774    }
775}
776
777impl<'de> Deserialize<'de> for SyntaxTheme {
778    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
779    where
780        D: serde::Deserializer<'de>,
781    {
782        let syntax_data: HashMap<String, HighlightStyle> = Deserialize::deserialize(deserializer)?;
783
784        let mut result = Self::new(Vec::new());
785        for (key, style) in syntax_data {
786            match result
787                .highlights
788                .binary_search_by(|(needle, _)| needle.cmp(&key))
789            {
790                Ok(i) | Err(i) => {
791                    result.highlights.insert(i, (key, style));
792                }
793            }
794        }
795
796        Ok(result)
797    }
798}
799
800#[derive(Clone, Deserialize, Default)]
801pub struct HoverPopover {
802    pub container: ContainerStyle,
803    pub info_container: ContainerStyle,
804    pub warning_container: ContainerStyle,
805    pub error_container: ContainerStyle,
806    pub block_style: ContainerStyle,
807    pub prose: TextStyle,
808    pub highlight: Color,
809}
810
811#[derive(Clone, Deserialize, Default)]
812pub struct TerminalStyle {
813    pub black: Color,
814    pub red: Color,
815    pub green: Color,
816    pub yellow: Color,
817    pub blue: Color,
818    pub magenta: Color,
819    pub cyan: Color,
820    pub white: Color,
821    pub bright_black: Color,
822    pub bright_red: Color,
823    pub bright_green: Color,
824    pub bright_yellow: Color,
825    pub bright_blue: Color,
826    pub bright_magenta: Color,
827    pub bright_cyan: Color,
828    pub bright_white: Color,
829    pub foreground: Color,
830    pub background: Color,
831    pub modal_background: Color,
832    pub cursor: Color,
833    pub dim_black: Color,
834    pub dim_red: Color,
835    pub dim_green: Color,
836    pub dim_yellow: Color,
837    pub dim_blue: Color,
838    pub dim_magenta: Color,
839    pub dim_cyan: Color,
840    pub dim_white: Color,
841    pub bright_foreground: Color,
842    pub dim_foreground: Color,
843}
844
845#[derive(Clone, Deserialize, Default)]
846pub struct FeedbackStyle {
847    pub submit_button: Interactive<ContainedText>,
848    pub button_margin: f32,
849    pub info_text_default: ContainedText,
850    pub link_text_default: ContainedText,
851    pub link_text_hover: ContainedText,
852}
853
854#[derive(Clone, Deserialize, Default)]
855pub struct WelcomeStyle {
856    pub page_width: f32,
857    pub logo_subheading: ContainedText,
858    pub checkbox: CheckboxStyle,
859    pub button: Interactive<ContainedText>,
860}
861
862#[derive(Clone, Deserialize, Default)]
863pub struct CheckboxStyle {
864    pub check_icon: String,
865    pub check_icon_color: Color,
866    pub label: ContainedText,
867    pub container: ContainerStyle,
868    pub width: f32,
869    pub height: f32,
870    pub default: ContainerStyle,
871    pub checked: ContainerStyle,
872    pub hovered: ContainerStyle,
873    pub hovered_and_checked: ContainerStyle,
874}
875
876#[derive(Clone, Deserialize, Default)]
877pub struct ColorScheme {
878    pub name: String,
879    pub is_light: bool,
880
881    pub ramps: RampSet,
882
883    pub lowest: Layer,
884    pub middle: Layer,
885    pub highest: Layer,
886
887    pub popover_shadow: Shadow,
888    pub modal_shadow: Shadow,
889
890    pub players: Vec<Player>,
891}
892
893#[derive(Clone, Deserialize, Default)]
894pub struct Player {
895    pub cursor: Color,
896    pub selection: Color,
897}
898
899#[derive(Clone, Deserialize, Default)]
900pub struct RampSet {
901    pub neutral: Vec<Color>,
902    pub red: Vec<Color>,
903    pub orange: Vec<Color>,
904    pub yellow: Vec<Color>,
905    pub green: Vec<Color>,
906    pub cyan: Vec<Color>,
907    pub blue: Vec<Color>,
908    pub violet: Vec<Color>,
909    pub magenta: Vec<Color>,
910}
911
912#[derive(Clone, Deserialize, Default)]
913pub struct Layer {
914    pub base: StyleSet,
915    pub variant: StyleSet,
916    pub on: StyleSet,
917    pub accent: StyleSet,
918    pub positive: StyleSet,
919    pub warning: StyleSet,
920    pub negative: StyleSet,
921}
922
923#[derive(Clone, Deserialize, Default)]
924pub struct StyleSet {
925    pub default: Style,
926    pub active: Style,
927    pub disabled: Style,
928    pub hovered: Style,
929    pub pressed: Style,
930    pub inverted: Style,
931}
932
933#[derive(Clone, Deserialize, Default)]
934pub struct Style {
935    pub background: Color,
936    pub border: Color,
937    pub foreground: Color,
938}