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