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    pub whitespace: Color,
 640}
 641
 642#[derive(Clone, Deserialize, Default)]
 643pub struct Scrollbar {
 644    pub track: ContainerStyle,
 645    pub thumb: ContainerStyle,
 646    pub width: f32,
 647    pub min_height_factor: f32,
 648}
 649
 650#[derive(Clone, Deserialize, Default)]
 651pub struct DiagnosticPathHeader {
 652    #[serde(flatten)]
 653    pub container: ContainerStyle,
 654    pub filename: ContainedText,
 655    pub path: ContainedText,
 656    pub text_scale_factor: f32,
 657}
 658
 659#[derive(Clone, Deserialize, Default)]
 660pub struct DiagnosticHeader {
 661    #[serde(flatten)]
 662    pub container: ContainerStyle,
 663    pub source: ContainedLabel,
 664    pub message: ContainedLabel,
 665    pub code: ContainedText,
 666    pub text_scale_factor: f32,
 667    pub icon_width_factor: f32,
 668}
 669
 670#[derive(Clone, Deserialize, Default)]
 671pub struct DiagnosticStyle {
 672    pub message: LabelStyle,
 673    #[serde(default)]
 674    pub header: ContainerStyle,
 675    pub text_scale_factor: f32,
 676}
 677
 678#[derive(Clone, Deserialize, Default)]
 679pub struct AutocompleteStyle {
 680    #[serde(flatten)]
 681    pub container: ContainerStyle,
 682    pub item: ContainerStyle,
 683    pub selected_item: ContainerStyle,
 684    pub hovered_item: ContainerStyle,
 685    pub match_highlight: HighlightStyle,
 686}
 687
 688#[derive(Clone, Copy, Default, Deserialize)]
 689pub struct SelectionStyle {
 690    pub cursor: Color,
 691    pub selection: Color,
 692}
 693
 694#[derive(Clone, Deserialize, Default)]
 695pub struct FieldEditor {
 696    #[serde(flatten)]
 697    pub container: ContainerStyle,
 698    pub text: TextStyle,
 699    #[serde(default)]
 700    pub placeholder_text: Option<TextStyle>,
 701    pub selection: SelectionStyle,
 702}
 703
 704#[derive(Clone, Deserialize, Default)]
 705pub struct InteractiveColor {
 706    pub color: Color,
 707}
 708
 709#[derive(Clone, Deserialize, Default)]
 710pub struct CodeActions {
 711    #[serde(default)]
 712    pub indicator: Interactive<InteractiveColor>,
 713    pub vertical_scale: f32,
 714}
 715
 716#[derive(Clone, Deserialize, Default)]
 717pub struct Folds {
 718    pub indicator: Interactive<InteractiveColor>,
 719    pub ellipses: FoldEllipses,
 720    pub fold_background: Color,
 721    pub icon_margin_scale: f32,
 722    pub folded_icon: String,
 723    pub foldable_icon: String,
 724}
 725
 726#[derive(Clone, Deserialize, Default)]
 727pub struct FoldEllipses {
 728    pub text_color: Color,
 729    pub background: Interactive<InteractiveColor>,
 730    pub corner_radius_factor: f32,
 731}
 732
 733#[derive(Clone, Deserialize, Default)]
 734pub struct DiffStyle {
 735    pub inserted: Color,
 736    pub modified: Color,
 737    pub deleted: Color,
 738    pub removed_width_em: f32,
 739    pub width_em: f32,
 740    pub corner_radius: f32,
 741}
 742
 743#[derive(Debug, Default, Clone, Copy)]
 744pub struct Interactive<T> {
 745    pub default: T,
 746    pub hover: Option<T>,
 747    pub hover_and_active: Option<T>,
 748    pub clicked: Option<T>,
 749    pub click_and_active: Option<T>,
 750    pub active: Option<T>,
 751    pub disabled: Option<T>,
 752}
 753
 754impl<T> Interactive<T> {
 755    pub fn style_for(&self, state: &mut MouseState, active: bool) -> &T {
 756        if active {
 757            if state.hovered() {
 758                self.hover_and_active
 759                    .as_ref()
 760                    .unwrap_or(self.active.as_ref().unwrap_or(&self.default))
 761            } else if state.clicked() == Some(platform::MouseButton::Left) && self.clicked.is_some()
 762            {
 763                self.click_and_active
 764                    .as_ref()
 765                    .unwrap_or(self.active.as_ref().unwrap_or(&self.default))
 766            } else {
 767                self.active.as_ref().unwrap_or(&self.default)
 768            }
 769        } else if state.clicked() == Some(platform::MouseButton::Left) && self.clicked.is_some() {
 770            self.clicked.as_ref().unwrap()
 771        } else if state.hovered() {
 772            self.hover.as_ref().unwrap_or(&self.default)
 773        } else {
 774            &self.default
 775        }
 776    }
 777
 778    pub fn disabled_style(&self) -> &T {
 779        self.disabled.as_ref().unwrap_or(&self.default)
 780    }
 781}
 782
 783impl<'de, T: DeserializeOwned> Deserialize<'de> for Interactive<T> {
 784    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
 785    where
 786        D: serde::Deserializer<'de>,
 787    {
 788        #[derive(Deserialize)]
 789        struct Helper {
 790            #[serde(flatten)]
 791            default: Value,
 792            hover: Option<Value>,
 793            hover_and_active: Option<Value>,
 794            clicked: Option<Value>,
 795            click_and_active: Option<Value>,
 796            active: Option<Value>,
 797            disabled: Option<Value>,
 798        }
 799
 800        let json = Helper::deserialize(deserializer)?;
 801
 802        let deserialize_state = |state_json: Option<Value>| -> Result<Option<T>, D::Error> {
 803            if let Some(mut state_json) = state_json {
 804                if let Value::Object(state_json) = &mut state_json {
 805                    if let Value::Object(default) = &json.default {
 806                        for (key, value) in default {
 807                            if !state_json.contains_key(key) {
 808                                state_json.insert(key.clone(), value.clone());
 809                            }
 810                        }
 811                    }
 812                }
 813                Ok(Some(
 814                    serde_json::from_value::<T>(state_json).map_err(serde::de::Error::custom)?,
 815                ))
 816            } else {
 817                Ok(None)
 818            }
 819        };
 820
 821        let hover = deserialize_state(json.hover)?;
 822        let hover_and_active = deserialize_state(json.hover_and_active)?;
 823        let clicked = deserialize_state(json.clicked)?;
 824        let click_and_active = deserialize_state(json.click_and_active)?;
 825        let active = deserialize_state(json.active)?;
 826        let disabled = deserialize_state(json.disabled)?;
 827        let default = serde_json::from_value(json.default).map_err(serde::de::Error::custom)?;
 828
 829        Ok(Interactive {
 830            default,
 831            hover,
 832            hover_and_active,
 833            clicked,
 834            click_and_active,
 835            active,
 836            disabled,
 837        })
 838    }
 839}
 840
 841impl Editor {
 842    pub fn replica_selection_style(&self, replica_id: u16) -> &SelectionStyle {
 843        let style_ix = replica_id as usize % (self.guest_selections.len() + 1);
 844        if style_ix == 0 {
 845            &self.selection
 846        } else {
 847            &self.guest_selections[style_ix - 1]
 848        }
 849    }
 850}
 851
 852#[derive(Default)]
 853pub struct SyntaxTheme {
 854    pub highlights: Vec<(String, HighlightStyle)>,
 855}
 856
 857impl SyntaxTheme {
 858    pub fn new(highlights: Vec<(String, HighlightStyle)>) -> Self {
 859        Self { highlights }
 860    }
 861}
 862
 863impl<'de> Deserialize<'de> for SyntaxTheme {
 864    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
 865    where
 866        D: serde::Deserializer<'de>,
 867    {
 868        let syntax_data: HashMap<String, HighlightStyle> = Deserialize::deserialize(deserializer)?;
 869
 870        let mut result = Self::new(Vec::new());
 871        for (key, style) in syntax_data {
 872            match result
 873                .highlights
 874                .binary_search_by(|(needle, _)| needle.cmp(&key))
 875            {
 876                Ok(i) | Err(i) => {
 877                    result.highlights.insert(i, (key, style));
 878                }
 879            }
 880        }
 881
 882        Ok(result)
 883    }
 884}
 885
 886#[derive(Clone, Deserialize, Default)]
 887pub struct HoverPopover {
 888    pub container: ContainerStyle,
 889    pub info_container: ContainerStyle,
 890    pub warning_container: ContainerStyle,
 891    pub error_container: ContainerStyle,
 892    pub block_style: ContainerStyle,
 893    pub prose: TextStyle,
 894    pub diagnostic_source_highlight: HighlightStyle,
 895    pub highlight: Color,
 896}
 897
 898#[derive(Clone, Deserialize, Default)]
 899pub struct TerminalStyle {
 900    pub black: Color,
 901    pub red: Color,
 902    pub green: Color,
 903    pub yellow: Color,
 904    pub blue: Color,
 905    pub magenta: Color,
 906    pub cyan: Color,
 907    pub white: Color,
 908    pub bright_black: Color,
 909    pub bright_red: Color,
 910    pub bright_green: Color,
 911    pub bright_yellow: Color,
 912    pub bright_blue: Color,
 913    pub bright_magenta: Color,
 914    pub bright_cyan: Color,
 915    pub bright_white: Color,
 916    pub foreground: Color,
 917    pub background: Color,
 918    pub modal_background: Color,
 919    pub cursor: Color,
 920    pub dim_black: Color,
 921    pub dim_red: Color,
 922    pub dim_green: Color,
 923    pub dim_yellow: Color,
 924    pub dim_blue: Color,
 925    pub dim_magenta: Color,
 926    pub dim_cyan: Color,
 927    pub dim_white: Color,
 928    pub bright_foreground: Color,
 929    pub dim_foreground: Color,
 930}
 931
 932#[derive(Clone, Deserialize, Default)]
 933pub struct FeedbackStyle {
 934    pub submit_button: Interactive<ContainedText>,
 935    pub button_margin: f32,
 936    pub info_text_default: ContainedText,
 937    pub link_text_default: ContainedText,
 938    pub link_text_hover: ContainedText,
 939}
 940
 941#[derive(Clone, Deserialize, Default)]
 942pub struct WelcomeStyle {
 943    pub page_width: f32,
 944    pub logo: SvgStyle,
 945    pub logo_subheading: ContainedText,
 946    pub usage_note: ContainedText,
 947    pub checkbox: CheckboxStyle,
 948    pub checkbox_container: ContainerStyle,
 949    pub button: Interactive<ContainedText>,
 950    pub button_group: ContainerStyle,
 951    pub heading_group: ContainerStyle,
 952    pub checkbox_group: ContainerStyle,
 953}
 954
 955#[derive(Clone, Deserialize, Default)]
 956pub struct ColorScheme {
 957    pub name: String,
 958    pub is_light: bool,
 959    pub ramps: RampSet,
 960    pub lowest: Layer,
 961    pub middle: Layer,
 962    pub highest: Layer,
 963
 964    pub popover_shadow: Shadow,
 965    pub modal_shadow: Shadow,
 966
 967    pub players: Vec<Player>,
 968}
 969
 970#[derive(Clone, Deserialize, Default)]
 971pub struct Player {
 972    pub cursor: Color,
 973    pub selection: Color,
 974}
 975
 976#[derive(Clone, Deserialize, Default)]
 977pub struct RampSet {
 978    pub neutral: Vec<Color>,
 979    pub red: Vec<Color>,
 980    pub orange: Vec<Color>,
 981    pub yellow: Vec<Color>,
 982    pub green: Vec<Color>,
 983    pub cyan: Vec<Color>,
 984    pub blue: Vec<Color>,
 985    pub violet: Vec<Color>,
 986    pub magenta: Vec<Color>,
 987}
 988
 989#[derive(Clone, Deserialize, Default)]
 990pub struct Layer {
 991    pub base: StyleSet,
 992    pub variant: StyleSet,
 993    pub on: StyleSet,
 994    pub accent: StyleSet,
 995    pub positive: StyleSet,
 996    pub warning: StyleSet,
 997    pub negative: StyleSet,
 998}
 999
1000#[derive(Clone, Deserialize, Default)]
1001pub struct StyleSet {
1002    pub default: Style,
1003    pub active: Style,
1004    pub disabled: Style,
1005    pub hovered: Style,
1006    pub pressed: Style,
1007    pub inverted: Style,
1008}
1009
1010#[derive(Clone, Deserialize, Default)]
1011pub struct Style {
1012    pub background: Color,
1013    pub border: Color,
1014    pub foreground: Color,
1015}