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