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 dock: Dock,
  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 drop_target_overlay_color: Color,
  77}
  78
  79#[derive(Clone, Deserialize, Default)]
  80pub struct BlankPaneStyle {
  81    pub logo: SvgStyle,
  82    pub logo_shadow: SvgStyle,
  83    pub logo_container: ContainerStyle,
  84    pub keyboard_hints: ContainerStyle,
  85    pub keyboard_hint: Interactive<ContainedText>,
  86    pub keyboard_hint_width: f32,
  87}
  88
  89#[derive(Clone, Deserialize, Default)]
  90pub struct Titlebar {
  91    #[serde(flatten)]
  92    pub container: ContainerStyle,
  93    pub height: f32,
  94    pub title: TextStyle,
  95    pub highlight_color: Color,
  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 Notifications {
 300    #[serde(flatten)]
 301    pub container: ContainerStyle,
 302    pub width: f32,
 303}
 304
 305#[derive(Clone, Deserialize, Default)]
 306pub struct Search {
 307    #[serde(flatten)]
 308    pub container: ContainerStyle,
 309    pub editor: FindEditor,
 310    pub invalid_editor: ContainerStyle,
 311    pub option_button_group: ContainerStyle,
 312    pub include_exclude_editor: FindEditor,
 313    pub invalid_include_exclude_editor: ContainerStyle,
 314    pub include_exclude_inputs: ContainedText,
 315    pub option_button: Interactive<ContainedText>,
 316    pub match_background: Color,
 317    pub match_index: ContainedText,
 318    pub results_status: TextStyle,
 319    pub dismiss_button: Interactive<IconButton>,
 320}
 321
 322#[derive(Clone, Deserialize, Default)]
 323pub struct FindEditor {
 324    #[serde(flatten)]
 325    pub input: FieldEditor,
 326    pub min_width: f32,
 327    pub max_width: f32,
 328}
 329
 330#[derive(Deserialize, Default)]
 331pub struct StatusBar {
 332    #[serde(flatten)]
 333    pub container: ContainerStyle,
 334    pub height: f32,
 335    pub item_spacing: f32,
 336    pub cursor_position: TextStyle,
 337    pub active_language: Interactive<ContainedText>,
 338    pub auto_update_progress_message: TextStyle,
 339    pub auto_update_done_message: TextStyle,
 340    pub lsp_status: Interactive<StatusBarLspStatus>,
 341    pub panel_buttons: StatusBarPanelButtons,
 342    pub diagnostic_summary: Interactive<StatusBarDiagnosticSummary>,
 343    pub diagnostic_message: Interactive<ContainedText>,
 344}
 345
 346#[derive(Deserialize, Default)]
 347pub struct StatusBarPanelButtons {
 348    pub group_left: ContainerStyle,
 349    pub group_bottom: ContainerStyle,
 350    pub group_right: ContainerStyle,
 351    pub button: Interactive<PanelButton>,
 352}
 353
 354#[derive(Deserialize, Default)]
 355pub struct StatusBarDiagnosticSummary {
 356    pub container_ok: ContainerStyle,
 357    pub container_warning: ContainerStyle,
 358    pub container_error: ContainerStyle,
 359    pub text: TextStyle,
 360    pub icon_color_ok: Color,
 361    pub icon_color_warning: Color,
 362    pub icon_color_error: Color,
 363    pub height: f32,
 364    pub icon_width: f32,
 365    pub icon_spacing: f32,
 366    pub summary_spacing: f32,
 367}
 368
 369#[derive(Deserialize, Default)]
 370pub struct StatusBarLspStatus {
 371    #[serde(flatten)]
 372    pub container: ContainerStyle,
 373    pub height: f32,
 374    pub icon_spacing: f32,
 375    pub icon_color: Color,
 376    pub icon_width: f32,
 377    pub message: TextStyle,
 378}
 379
 380#[derive(Deserialize, Default)]
 381pub struct Dock {
 382    pub initial_size: f32,
 383    #[serde(flatten)]
 384    pub container: ContainerStyle,
 385}
 386
 387#[derive(Clone, Deserialize, Default)]
 388pub struct PanelButton {
 389    #[serde(flatten)]
 390    pub container: ContainerStyle,
 391    pub icon_color: Color,
 392    pub icon_size: f32,
 393    pub label: ContainedText,
 394}
 395
 396#[derive(Deserialize, Default)]
 397pub struct ProjectPanel {
 398    #[serde(flatten)]
 399    pub container: ContainerStyle,
 400    pub entry: Interactive<ProjectPanelEntry>,
 401    pub dragged_entry: ProjectPanelEntry,
 402    pub ignored_entry: Interactive<ProjectPanelEntry>,
 403    pub cut_entry: Interactive<ProjectPanelEntry>,
 404    pub filename_editor: FieldEditor,
 405    pub indent_width: f32,
 406    pub open_project_button: Interactive<ContainedText>,
 407}
 408
 409#[derive(Clone, Debug, Deserialize, Default)]
 410pub struct ProjectPanelEntry {
 411    pub height: f32,
 412    #[serde(flatten)]
 413    pub container: ContainerStyle,
 414    pub text: TextStyle,
 415    pub icon_color: Color,
 416    pub icon_size: f32,
 417    pub icon_spacing: f32,
 418}
 419
 420#[derive(Clone, Debug, Deserialize, Default)]
 421pub struct ContextMenu {
 422    #[serde(flatten)]
 423    pub container: ContainerStyle,
 424    pub item: Interactive<ContextMenuItem>,
 425    pub keystroke_margin: f32,
 426    pub separator: ContainerStyle,
 427}
 428
 429#[derive(Clone, Debug, Deserialize, Default)]
 430pub struct ContextMenuItem {
 431    #[serde(flatten)]
 432    pub container: ContainerStyle,
 433    pub label: TextStyle,
 434    pub keystroke: ContainedText,
 435    pub icon_width: f32,
 436    pub icon_spacing: f32,
 437}
 438
 439#[derive(Debug, Deserialize, Default)]
 440pub struct CommandPalette {
 441    pub key: Interactive<ContainedLabel>,
 442    pub keystroke_spacing: f32,
 443}
 444
 445#[derive(Deserialize, Default)]
 446pub struct InviteLink {
 447    #[serde(flatten)]
 448    pub container: ContainerStyle,
 449    #[serde(flatten)]
 450    pub label: LabelStyle,
 451    pub icon: Icon,
 452}
 453
 454#[derive(Deserialize, Clone, Copy, Default)]
 455pub struct Icon {
 456    #[serde(flatten)]
 457    pub container: ContainerStyle,
 458    pub color: Color,
 459    pub width: f32,
 460}
 461
 462#[derive(Deserialize, Clone, Copy, Default)]
 463pub struct IconButton {
 464    #[serde(flatten)]
 465    pub container: ContainerStyle,
 466    pub color: Color,
 467    pub icon_width: f32,
 468    pub button_width: f32,
 469}
 470
 471#[derive(Deserialize, Default)]
 472pub struct ChatMessage {
 473    #[serde(flatten)]
 474    pub container: ContainerStyle,
 475    pub body: TextStyle,
 476    pub sender: ContainedText,
 477    pub timestamp: ContainedText,
 478}
 479
 480#[derive(Deserialize, Default)]
 481pub struct ChannelSelect {
 482    #[serde(flatten)]
 483    pub container: ContainerStyle,
 484    pub header: ChannelName,
 485    pub item: ChannelName,
 486    pub active_item: ChannelName,
 487    pub hovered_item: ChannelName,
 488    pub hovered_active_item: ChannelName,
 489    pub menu: ContainerStyle,
 490}
 491
 492#[derive(Deserialize, Default)]
 493pub struct ChannelName {
 494    #[serde(flatten)]
 495    pub container: ContainerStyle,
 496    pub hash: ContainedText,
 497    pub name: TextStyle,
 498}
 499
 500#[derive(Clone, Deserialize, Default)]
 501pub struct Picker {
 502    #[serde(flatten)]
 503    pub container: ContainerStyle,
 504    pub empty_container: ContainerStyle,
 505    pub input_editor: FieldEditor,
 506    pub empty_input_editor: FieldEditor,
 507    pub no_matches: ContainedLabel,
 508    pub item: Interactive<ContainedLabel>,
 509}
 510
 511#[derive(Clone, Debug, Deserialize, Default)]
 512pub struct ContainedText {
 513    #[serde(flatten)]
 514    pub container: ContainerStyle,
 515    #[serde(flatten)]
 516    pub text: TextStyle,
 517}
 518
 519#[derive(Clone, Debug, Deserialize, Default)]
 520pub struct ContainedLabel {
 521    #[serde(flatten)]
 522    pub container: ContainerStyle,
 523    #[serde(flatten)]
 524    pub label: LabelStyle,
 525}
 526
 527#[derive(Clone, Deserialize, Default)]
 528pub struct ProjectDiagnostics {
 529    #[serde(flatten)]
 530    pub container: ContainerStyle,
 531    pub empty_message: TextStyle,
 532    pub tab_icon_width: f32,
 533    pub tab_icon_spacing: f32,
 534    pub tab_summary_spacing: f32,
 535}
 536
 537#[derive(Deserialize, Default)]
 538pub struct ContactNotification {
 539    pub header_avatar: ImageStyle,
 540    pub header_message: ContainedText,
 541    pub header_height: f32,
 542    pub body_message: ContainedText,
 543    pub button: Interactive<ContainedText>,
 544    pub dismiss_button: Interactive<IconButton>,
 545}
 546
 547#[derive(Deserialize, Default)]
 548pub struct UpdateNotification {
 549    pub message: ContainedText,
 550    pub action_message: Interactive<ContainedText>,
 551    pub dismiss_button: Interactive<IconButton>,
 552}
 553
 554#[derive(Deserialize, Default)]
 555pub struct MessageNotification {
 556    pub message: ContainedText,
 557    pub action_message: Interactive<ContainedText>,
 558    pub dismiss_button: Interactive<IconButton>,
 559}
 560
 561#[derive(Deserialize, Default)]
 562pub struct ProjectSharedNotification {
 563    pub window_height: f32,
 564    pub window_width: f32,
 565    #[serde(default)]
 566    pub background: Color,
 567    pub owner_container: ContainerStyle,
 568    pub owner_avatar: ImageStyle,
 569    pub owner_metadata: ContainerStyle,
 570    pub owner_username: ContainedText,
 571    pub message: ContainedText,
 572    pub worktree_roots: ContainedText,
 573    pub button_width: f32,
 574    pub open_button: ContainedText,
 575    pub dismiss_button: ContainedText,
 576}
 577
 578#[derive(Deserialize, Default)]
 579pub struct IncomingCallNotification {
 580    pub window_height: f32,
 581    pub window_width: f32,
 582    #[serde(default)]
 583    pub background: Color,
 584    pub caller_container: ContainerStyle,
 585    pub caller_avatar: ImageStyle,
 586    pub caller_metadata: ContainerStyle,
 587    pub caller_username: ContainedText,
 588    pub caller_message: ContainedText,
 589    pub worktree_roots: ContainedText,
 590    pub button_width: f32,
 591    pub accept_button: ContainedText,
 592    pub decline_button: ContainedText,
 593}
 594
 595#[derive(Clone, Deserialize, Default)]
 596pub struct Editor {
 597    pub text_color: Color,
 598    #[serde(default)]
 599    pub background: Color,
 600    pub selection: SelectionStyle,
 601    pub gutter_background: Color,
 602    pub gutter_padding_factor: f32,
 603    pub active_line_background: Color,
 604    pub highlighted_line_background: Color,
 605    pub rename_fade: f32,
 606    pub document_highlight_read_background: Color,
 607    pub document_highlight_write_background: Color,
 608    pub diff: DiffStyle,
 609    pub line_number: Color,
 610    pub line_number_active: Color,
 611    pub guest_selections: Vec<SelectionStyle>,
 612    pub syntax: Arc<SyntaxTheme>,
 613    pub suggestion: HighlightStyle,
 614    pub diagnostic_path_header: DiagnosticPathHeader,
 615    pub diagnostic_header: DiagnosticHeader,
 616    pub error_diagnostic: DiagnosticStyle,
 617    pub invalid_error_diagnostic: DiagnosticStyle,
 618    pub warning_diagnostic: DiagnosticStyle,
 619    pub invalid_warning_diagnostic: DiagnosticStyle,
 620    pub information_diagnostic: DiagnosticStyle,
 621    pub invalid_information_diagnostic: DiagnosticStyle,
 622    pub hint_diagnostic: DiagnosticStyle,
 623    pub invalid_hint_diagnostic: DiagnosticStyle,
 624    pub autocomplete: AutocompleteStyle,
 625    pub code_actions: CodeActions,
 626    pub folds: Folds,
 627    pub unnecessary_code_fade: f32,
 628    pub hover_popover: HoverPopover,
 629    pub link_definition: HighlightStyle,
 630    pub composition_mark: HighlightStyle,
 631    pub jump_icon: Interactive<IconButton>,
 632    pub scrollbar: Scrollbar,
 633    pub whitespace: Color,
 634}
 635
 636#[derive(Clone, Deserialize, Default)]
 637pub struct Scrollbar {
 638    pub track: ContainerStyle,
 639    pub thumb: ContainerStyle,
 640    pub width: f32,
 641    pub min_height_factor: f32,
 642}
 643
 644#[derive(Clone, Deserialize, Default)]
 645pub struct DiagnosticPathHeader {
 646    #[serde(flatten)]
 647    pub container: ContainerStyle,
 648    pub filename: ContainedText,
 649    pub path: ContainedText,
 650    pub text_scale_factor: f32,
 651}
 652
 653#[derive(Clone, Deserialize, Default)]
 654pub struct DiagnosticHeader {
 655    #[serde(flatten)]
 656    pub container: ContainerStyle,
 657    pub source: ContainedLabel,
 658    pub message: ContainedLabel,
 659    pub code: ContainedText,
 660    pub text_scale_factor: f32,
 661    pub icon_width_factor: f32,
 662}
 663
 664#[derive(Clone, Deserialize, Default)]
 665pub struct DiagnosticStyle {
 666    pub message: LabelStyle,
 667    #[serde(default)]
 668    pub header: ContainerStyle,
 669    pub text_scale_factor: f32,
 670}
 671
 672#[derive(Clone, Deserialize, Default)]
 673pub struct AutocompleteStyle {
 674    #[serde(flatten)]
 675    pub container: ContainerStyle,
 676    pub item: ContainerStyle,
 677    pub selected_item: ContainerStyle,
 678    pub hovered_item: ContainerStyle,
 679    pub match_highlight: HighlightStyle,
 680}
 681
 682#[derive(Clone, Copy, Default, Deserialize)]
 683pub struct SelectionStyle {
 684    pub cursor: Color,
 685    pub selection: Color,
 686}
 687
 688#[derive(Clone, Deserialize, Default)]
 689pub struct FieldEditor {
 690    #[serde(flatten)]
 691    pub container: ContainerStyle,
 692    pub text: TextStyle,
 693    #[serde(default)]
 694    pub placeholder_text: Option<TextStyle>,
 695    pub selection: SelectionStyle,
 696}
 697
 698#[derive(Clone, Deserialize, Default)]
 699pub struct InteractiveColor {
 700    pub color: Color,
 701}
 702
 703#[derive(Clone, Deserialize, Default)]
 704pub struct CodeActions {
 705    #[serde(default)]
 706    pub indicator: Interactive<InteractiveColor>,
 707    pub vertical_scale: f32,
 708}
 709
 710#[derive(Clone, Deserialize, Default)]
 711pub struct Folds {
 712    pub indicator: Interactive<InteractiveColor>,
 713    pub ellipses: FoldEllipses,
 714    pub fold_background: Color,
 715    pub icon_margin_scale: f32,
 716    pub folded_icon: String,
 717    pub foldable_icon: String,
 718}
 719
 720#[derive(Clone, Deserialize, Default)]
 721pub struct FoldEllipses {
 722    pub text_color: Color,
 723    pub background: Interactive<InteractiveColor>,
 724    pub corner_radius_factor: f32,
 725}
 726
 727#[derive(Clone, Deserialize, Default)]
 728pub struct DiffStyle {
 729    pub inserted: Color,
 730    pub modified: Color,
 731    pub deleted: Color,
 732    pub removed_width_em: f32,
 733    pub width_em: f32,
 734    pub corner_radius: f32,
 735}
 736
 737#[derive(Debug, Default, Clone, Copy)]
 738pub struct Interactive<T> {
 739    pub default: T,
 740    pub hover: Option<T>,
 741    pub hover_and_active: Option<T>,
 742    pub clicked: Option<T>,
 743    pub click_and_active: Option<T>,
 744    pub active: Option<T>,
 745    pub disabled: Option<T>,
 746}
 747
 748impl<T> Interactive<T> {
 749    pub fn style_for(&self, state: &mut MouseState, active: bool) -> &T {
 750        if active {
 751            if state.hovered() {
 752                self.hover_and_active
 753                    .as_ref()
 754                    .unwrap_or(self.active.as_ref().unwrap_or(&self.default))
 755            } else if state.clicked() == Some(platform::MouseButton::Left) && self.clicked.is_some()
 756            {
 757                self.click_and_active
 758                    .as_ref()
 759                    .unwrap_or(self.active.as_ref().unwrap_or(&self.default))
 760            } else {
 761                self.active.as_ref().unwrap_or(&self.default)
 762            }
 763        } else if state.clicked() == Some(platform::MouseButton::Left) && self.clicked.is_some() {
 764            self.clicked.as_ref().unwrap()
 765        } else if state.hovered() {
 766            self.hover.as_ref().unwrap_or(&self.default)
 767        } else {
 768            &self.default
 769        }
 770    }
 771
 772    pub fn disabled_style(&self) -> &T {
 773        self.disabled.as_ref().unwrap_or(&self.default)
 774    }
 775}
 776
 777impl<'de, T: DeserializeOwned> Deserialize<'de> for Interactive<T> {
 778    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
 779    where
 780        D: serde::Deserializer<'de>,
 781    {
 782        #[derive(Deserialize)]
 783        struct Helper {
 784            #[serde(flatten)]
 785            default: Value,
 786            hover: Option<Value>,
 787            hover_and_active: Option<Value>,
 788            clicked: Option<Value>,
 789            click_and_active: Option<Value>,
 790            active: Option<Value>,
 791            disabled: Option<Value>,
 792        }
 793
 794        let json = Helper::deserialize(deserializer)?;
 795
 796        let deserialize_state = |state_json: Option<Value>| -> Result<Option<T>, D::Error> {
 797            if let Some(mut state_json) = state_json {
 798                if let Value::Object(state_json) = &mut state_json {
 799                    if let Value::Object(default) = &json.default {
 800                        for (key, value) in default {
 801                            if !state_json.contains_key(key) {
 802                                state_json.insert(key.clone(), value.clone());
 803                            }
 804                        }
 805                    }
 806                }
 807                Ok(Some(
 808                    serde_json::from_value::<T>(state_json).map_err(serde::de::Error::custom)?,
 809                ))
 810            } else {
 811                Ok(None)
 812            }
 813        };
 814
 815        let hover = deserialize_state(json.hover)?;
 816        let hover_and_active = deserialize_state(json.hover_and_active)?;
 817        let clicked = deserialize_state(json.clicked)?;
 818        let click_and_active = deserialize_state(json.click_and_active)?;
 819        let active = deserialize_state(json.active)?;
 820        let disabled = deserialize_state(json.disabled)?;
 821        let default = serde_json::from_value(json.default).map_err(serde::de::Error::custom)?;
 822
 823        Ok(Interactive {
 824            default,
 825            hover,
 826            hover_and_active,
 827            clicked,
 828            click_and_active,
 829            active,
 830            disabled,
 831        })
 832    }
 833}
 834
 835impl Editor {
 836    pub fn replica_selection_style(&self, replica_id: u16) -> &SelectionStyle {
 837        let style_ix = replica_id as usize % (self.guest_selections.len() + 1);
 838        if style_ix == 0 {
 839            &self.selection
 840        } else {
 841            &self.guest_selections[style_ix - 1]
 842        }
 843    }
 844}
 845
 846#[derive(Default)]
 847pub struct SyntaxTheme {
 848    pub highlights: Vec<(String, HighlightStyle)>,
 849}
 850
 851impl SyntaxTheme {
 852    pub fn new(highlights: Vec<(String, HighlightStyle)>) -> Self {
 853        Self { highlights }
 854    }
 855}
 856
 857impl<'de> Deserialize<'de> for SyntaxTheme {
 858    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
 859    where
 860        D: serde::Deserializer<'de>,
 861    {
 862        let syntax_data: HashMap<String, HighlightStyle> = Deserialize::deserialize(deserializer)?;
 863
 864        let mut result = Self::new(Vec::new());
 865        for (key, style) in syntax_data {
 866            match result
 867                .highlights
 868                .binary_search_by(|(needle, _)| needle.cmp(&key))
 869            {
 870                Ok(i) | Err(i) => {
 871                    result.highlights.insert(i, (key, style));
 872                }
 873            }
 874        }
 875
 876        Ok(result)
 877    }
 878}
 879
 880#[derive(Clone, Deserialize, Default)]
 881pub struct HoverPopover {
 882    pub container: ContainerStyle,
 883    pub info_container: ContainerStyle,
 884    pub warning_container: ContainerStyle,
 885    pub error_container: ContainerStyle,
 886    pub block_style: ContainerStyle,
 887    pub prose: TextStyle,
 888    pub diagnostic_source_highlight: HighlightStyle,
 889    pub highlight: Color,
 890}
 891
 892#[derive(Clone, Deserialize, Default)]
 893pub struct TerminalStyle {
 894    pub black: Color,
 895    pub red: Color,
 896    pub green: Color,
 897    pub yellow: Color,
 898    pub blue: Color,
 899    pub magenta: Color,
 900    pub cyan: Color,
 901    pub white: Color,
 902    pub bright_black: Color,
 903    pub bright_red: Color,
 904    pub bright_green: Color,
 905    pub bright_yellow: Color,
 906    pub bright_blue: Color,
 907    pub bright_magenta: Color,
 908    pub bright_cyan: Color,
 909    pub bright_white: Color,
 910    pub foreground: Color,
 911    pub background: Color,
 912    pub modal_background: Color,
 913    pub cursor: Color,
 914    pub dim_black: Color,
 915    pub dim_red: Color,
 916    pub dim_green: Color,
 917    pub dim_yellow: Color,
 918    pub dim_blue: Color,
 919    pub dim_magenta: Color,
 920    pub dim_cyan: Color,
 921    pub dim_white: Color,
 922    pub bright_foreground: Color,
 923    pub dim_foreground: Color,
 924}
 925
 926#[derive(Clone, Deserialize, Default)]
 927pub struct FeedbackStyle {
 928    pub submit_button: Interactive<ContainedText>,
 929    pub button_margin: f32,
 930    pub info_text_default: ContainedText,
 931    pub link_text_default: ContainedText,
 932    pub link_text_hover: ContainedText,
 933}
 934
 935#[derive(Clone, Deserialize, Default)]
 936pub struct WelcomeStyle {
 937    pub page_width: f32,
 938    pub logo: SvgStyle,
 939    pub logo_subheading: ContainedText,
 940    pub usage_note: ContainedText,
 941    pub checkbox: CheckboxStyle,
 942    pub checkbox_container: ContainerStyle,
 943    pub button: Interactive<ContainedText>,
 944    pub button_group: ContainerStyle,
 945    pub heading_group: ContainerStyle,
 946    pub checkbox_group: ContainerStyle,
 947}
 948
 949#[derive(Clone, Deserialize, Default)]
 950pub struct ColorScheme {
 951    pub name: String,
 952    pub is_light: bool,
 953    pub ramps: RampSet,
 954    pub lowest: Layer,
 955    pub middle: Layer,
 956    pub highest: Layer,
 957
 958    pub popover_shadow: Shadow,
 959    pub modal_shadow: Shadow,
 960
 961    pub players: Vec<Player>,
 962}
 963
 964#[derive(Clone, Deserialize, Default)]
 965pub struct Player {
 966    pub cursor: Color,
 967    pub selection: Color,
 968}
 969
 970#[derive(Clone, Deserialize, Default)]
 971pub struct RampSet {
 972    pub neutral: Vec<Color>,
 973    pub red: Vec<Color>,
 974    pub orange: Vec<Color>,
 975    pub yellow: Vec<Color>,
 976    pub green: Vec<Color>,
 977    pub cyan: Vec<Color>,
 978    pub blue: Vec<Color>,
 979    pub violet: Vec<Color>,
 980    pub magenta: Vec<Color>,
 981}
 982
 983#[derive(Clone, Deserialize, Default)]
 984pub struct Layer {
 985    pub base: StyleSet,
 986    pub variant: StyleSet,
 987    pub on: StyleSet,
 988    pub accent: StyleSet,
 989    pub positive: StyleSet,
 990    pub warning: StyleSet,
 991    pub negative: StyleSet,
 992}
 993
 994#[derive(Clone, Deserialize, Default)]
 995pub struct StyleSet {
 996    pub default: Style,
 997    pub active: Style,
 998    pub disabled: Style,
 999    pub hovered: Style,
1000    pub pressed: Style,
1001    pub inverted: Style,
1002}
1003
1004#[derive(Clone, Deserialize, Default)]
1005pub struct Style {
1006    pub background: Color,
1007    pub border: Color,
1008    pub foreground: Color,
1009}