theme.rs

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