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