theme.rs

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