theme.rs

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