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 left: ContainerStyle,
 406    pub bottom: ContainerStyle,
 407    pub right: 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    pub status: EntryStatus,
 442}
 443
 444#[derive(Clone, Debug, Deserialize, Default)]
 445pub struct EntryStatus {
 446    pub git: GitProjectStatus,
 447}
 448
 449#[derive(Clone, Debug, Deserialize, Default)]
 450pub struct GitProjectStatus {
 451    pub modified: Color,
 452    pub inserted: Color,
 453    pub conflict: Color,
 454}
 455
 456#[derive(Clone, Debug, Deserialize, Default)]
 457pub struct ContextMenu {
 458    #[serde(flatten)]
 459    pub container: ContainerStyle,
 460    pub item: Interactive<ContextMenuItem>,
 461    pub keystroke_margin: f32,
 462    pub separator: ContainerStyle,
 463}
 464
 465#[derive(Clone, Debug, Deserialize, Default)]
 466pub struct ContextMenuItem {
 467    #[serde(flatten)]
 468    pub container: ContainerStyle,
 469    pub label: TextStyle,
 470    pub keystroke: ContainedText,
 471    pub icon_width: f32,
 472    pub icon_spacing: f32,
 473}
 474
 475#[derive(Debug, Deserialize, Default)]
 476pub struct CommandPalette {
 477    pub key: Interactive<ContainedLabel>,
 478    pub keystroke_spacing: f32,
 479}
 480
 481#[derive(Deserialize, Default)]
 482pub struct InviteLink {
 483    #[serde(flatten)]
 484    pub container: ContainerStyle,
 485    #[serde(flatten)]
 486    pub label: LabelStyle,
 487    pub icon: Icon,
 488}
 489
 490#[derive(Deserialize, Clone, Copy, Default)]
 491pub struct Icon {
 492    #[serde(flatten)]
 493    pub container: ContainerStyle,
 494    pub color: Color,
 495    pub width: f32,
 496}
 497
 498#[derive(Deserialize, Clone, Copy, Default)]
 499pub struct IconButton {
 500    #[serde(flatten)]
 501    pub container: ContainerStyle,
 502    pub color: Color,
 503    pub icon_width: f32,
 504    pub button_width: f32,
 505}
 506
 507#[derive(Deserialize, Default)]
 508pub struct ChatMessage {
 509    #[serde(flatten)]
 510    pub container: ContainerStyle,
 511    pub body: TextStyle,
 512    pub sender: ContainedText,
 513    pub timestamp: ContainedText,
 514}
 515
 516#[derive(Deserialize, Default)]
 517pub struct ChannelSelect {
 518    #[serde(flatten)]
 519    pub container: ContainerStyle,
 520    pub header: ChannelName,
 521    pub item: ChannelName,
 522    pub active_item: ChannelName,
 523    pub hovered_item: ChannelName,
 524    pub hovered_active_item: ChannelName,
 525    pub menu: ContainerStyle,
 526}
 527
 528#[derive(Deserialize, Default)]
 529pub struct ChannelName {
 530    #[serde(flatten)]
 531    pub container: ContainerStyle,
 532    pub hash: ContainedText,
 533    pub name: TextStyle,
 534}
 535
 536#[derive(Clone, Deserialize, Default)]
 537pub struct Picker {
 538    #[serde(flatten)]
 539    pub container: ContainerStyle,
 540    pub empty_container: ContainerStyle,
 541    pub input_editor: FieldEditor,
 542    pub empty_input_editor: FieldEditor,
 543    pub no_matches: ContainedLabel,
 544    pub item: Interactive<ContainedLabel>,
 545}
 546
 547#[derive(Clone, Debug, Deserialize, Default)]
 548pub struct ContainedText {
 549    #[serde(flatten)]
 550    pub container: ContainerStyle,
 551    #[serde(flatten)]
 552    pub text: TextStyle,
 553}
 554
 555#[derive(Clone, Debug, Deserialize, Default)]
 556pub struct ContainedLabel {
 557    #[serde(flatten)]
 558    pub container: ContainerStyle,
 559    #[serde(flatten)]
 560    pub label: LabelStyle,
 561}
 562
 563#[derive(Clone, Deserialize, Default)]
 564pub struct ProjectDiagnostics {
 565    #[serde(flatten)]
 566    pub container: ContainerStyle,
 567    pub empty_message: TextStyle,
 568    pub tab_icon_width: f32,
 569    pub tab_icon_spacing: f32,
 570    pub tab_summary_spacing: f32,
 571}
 572
 573#[derive(Deserialize, Default)]
 574pub struct ContactNotification {
 575    pub header_avatar: ImageStyle,
 576    pub header_message: ContainedText,
 577    pub header_height: f32,
 578    pub body_message: ContainedText,
 579    pub button: Interactive<ContainedText>,
 580    pub dismiss_button: Interactive<IconButton>,
 581}
 582
 583#[derive(Deserialize, Default)]
 584pub struct UpdateNotification {
 585    pub message: ContainedText,
 586    pub action_message: Interactive<ContainedText>,
 587    pub dismiss_button: Interactive<IconButton>,
 588}
 589
 590#[derive(Deserialize, Default)]
 591pub struct MessageNotification {
 592    pub message: ContainedText,
 593    pub action_message: Interactive<ContainedText>,
 594    pub dismiss_button: Interactive<IconButton>,
 595}
 596
 597#[derive(Deserialize, Default)]
 598pub struct ProjectSharedNotification {
 599    pub window_height: f32,
 600    pub window_width: f32,
 601    #[serde(default)]
 602    pub background: Color,
 603    pub owner_container: ContainerStyle,
 604    pub owner_avatar: ImageStyle,
 605    pub owner_metadata: ContainerStyle,
 606    pub owner_username: ContainedText,
 607    pub message: ContainedText,
 608    pub worktree_roots: ContainedText,
 609    pub button_width: f32,
 610    pub open_button: ContainedText,
 611    pub dismiss_button: ContainedText,
 612}
 613
 614#[derive(Deserialize, Default)]
 615pub struct IncomingCallNotification {
 616    pub window_height: f32,
 617    pub window_width: f32,
 618    #[serde(default)]
 619    pub background: Color,
 620    pub caller_container: ContainerStyle,
 621    pub caller_avatar: ImageStyle,
 622    pub caller_metadata: ContainerStyle,
 623    pub caller_username: ContainedText,
 624    pub caller_message: ContainedText,
 625    pub worktree_roots: ContainedText,
 626    pub button_width: f32,
 627    pub accept_button: ContainedText,
 628    pub decline_button: ContainedText,
 629}
 630
 631#[derive(Clone, Deserialize, Default)]
 632pub struct Editor {
 633    pub text_color: Color,
 634    #[serde(default)]
 635    pub background: Color,
 636    pub selection: SelectionStyle,
 637    pub gutter_background: Color,
 638    pub gutter_padding_factor: f32,
 639    pub active_line_background: Color,
 640    pub highlighted_line_background: Color,
 641    pub rename_fade: f32,
 642    pub document_highlight_read_background: Color,
 643    pub document_highlight_write_background: Color,
 644    pub diff: DiffStyle,
 645    pub line_number: Color,
 646    pub line_number_active: Color,
 647    pub guest_selections: Vec<SelectionStyle>,
 648    pub syntax: Arc<SyntaxTheme>,
 649    pub suggestion: HighlightStyle,
 650    pub diagnostic_path_header: DiagnosticPathHeader,
 651    pub diagnostic_header: DiagnosticHeader,
 652    pub error_diagnostic: DiagnosticStyle,
 653    pub invalid_error_diagnostic: DiagnosticStyle,
 654    pub warning_diagnostic: DiagnosticStyle,
 655    pub invalid_warning_diagnostic: DiagnosticStyle,
 656    pub information_diagnostic: DiagnosticStyle,
 657    pub invalid_information_diagnostic: DiagnosticStyle,
 658    pub hint_diagnostic: DiagnosticStyle,
 659    pub invalid_hint_diagnostic: DiagnosticStyle,
 660    pub autocomplete: AutocompleteStyle,
 661    pub code_actions: CodeActions,
 662    pub folds: Folds,
 663    pub unnecessary_code_fade: f32,
 664    pub hover_popover: HoverPopover,
 665    pub link_definition: HighlightStyle,
 666    pub composition_mark: HighlightStyle,
 667    pub jump_icon: Interactive<IconButton>,
 668    pub scrollbar: Scrollbar,
 669    pub whitespace: Color,
 670}
 671
 672#[derive(Clone, Deserialize, Default)]
 673pub struct Scrollbar {
 674    pub track: ContainerStyle,
 675    pub thumb: ContainerStyle,
 676    pub width: f32,
 677    pub min_height_factor: f32,
 678    pub git: GitDiffColors,
 679}
 680
 681#[derive(Clone, Deserialize, Default)]
 682pub struct GitDiffColors {
 683    pub inserted: Color,
 684    pub modified: Color,
 685    pub deleted: Color,
 686}
 687
 688#[derive(Clone, Deserialize, Default)]
 689pub struct DiagnosticPathHeader {
 690    #[serde(flatten)]
 691    pub container: ContainerStyle,
 692    pub filename: ContainedText,
 693    pub path: ContainedText,
 694    pub text_scale_factor: f32,
 695}
 696
 697#[derive(Clone, Deserialize, Default)]
 698pub struct DiagnosticHeader {
 699    #[serde(flatten)]
 700    pub container: ContainerStyle,
 701    pub source: ContainedLabel,
 702    pub message: ContainedLabel,
 703    pub code: ContainedText,
 704    pub text_scale_factor: f32,
 705    pub icon_width_factor: f32,
 706}
 707
 708#[derive(Clone, Deserialize, Default)]
 709pub struct DiagnosticStyle {
 710    pub message: LabelStyle,
 711    #[serde(default)]
 712    pub header: ContainerStyle,
 713    pub text_scale_factor: f32,
 714}
 715
 716#[derive(Clone, Deserialize, Default)]
 717pub struct AutocompleteStyle {
 718    #[serde(flatten)]
 719    pub container: ContainerStyle,
 720    pub item: ContainerStyle,
 721    pub selected_item: ContainerStyle,
 722    pub hovered_item: ContainerStyle,
 723    pub match_highlight: HighlightStyle,
 724}
 725
 726#[derive(Clone, Copy, Default, Deserialize)]
 727pub struct SelectionStyle {
 728    pub cursor: Color,
 729    pub selection: Color,
 730}
 731
 732#[derive(Clone, Deserialize, Default)]
 733pub struct FieldEditor {
 734    #[serde(flatten)]
 735    pub container: ContainerStyle,
 736    pub text: TextStyle,
 737    #[serde(default)]
 738    pub placeholder_text: Option<TextStyle>,
 739    pub selection: SelectionStyle,
 740}
 741
 742#[derive(Clone, Deserialize, Default)]
 743pub struct InteractiveColor {
 744    pub color: Color,
 745}
 746
 747#[derive(Clone, Deserialize, Default)]
 748pub struct CodeActions {
 749    #[serde(default)]
 750    pub indicator: Interactive<InteractiveColor>,
 751    pub vertical_scale: f32,
 752}
 753
 754#[derive(Clone, Deserialize, Default)]
 755pub struct Folds {
 756    pub indicator: Interactive<InteractiveColor>,
 757    pub ellipses: FoldEllipses,
 758    pub fold_background: Color,
 759    pub icon_margin_scale: f32,
 760    pub folded_icon: String,
 761    pub foldable_icon: String,
 762}
 763
 764#[derive(Clone, Deserialize, Default)]
 765pub struct FoldEllipses {
 766    pub text_color: Color,
 767    pub background: Interactive<InteractiveColor>,
 768    pub corner_radius_factor: f32,
 769}
 770
 771#[derive(Clone, Deserialize, Default)]
 772pub struct DiffStyle {
 773    pub inserted: Color,
 774    pub modified: Color,
 775    pub deleted: Color,
 776    pub removed_width_em: f32,
 777    pub width_em: f32,
 778    pub corner_radius: f32,
 779}
 780
 781#[derive(Debug, Default, Clone, Copy)]
 782pub struct Interactive<T> {
 783    pub default: T,
 784    pub hover: Option<T>,
 785    pub hover_and_active: Option<T>,
 786    pub clicked: Option<T>,
 787    pub click_and_active: Option<T>,
 788    pub active: Option<T>,
 789    pub disabled: Option<T>,
 790}
 791
 792impl<T> Interactive<T> {
 793    pub fn style_for(&self, state: &mut MouseState, active: bool) -> &T {
 794        if active {
 795            if state.hovered() {
 796                self.hover_and_active
 797                    .as_ref()
 798                    .unwrap_or(self.active.as_ref().unwrap_or(&self.default))
 799            } else if state.clicked() == Some(platform::MouseButton::Left) && self.clicked.is_some()
 800            {
 801                self.click_and_active
 802                    .as_ref()
 803                    .unwrap_or(self.active.as_ref().unwrap_or(&self.default))
 804            } else {
 805                self.active.as_ref().unwrap_or(&self.default)
 806            }
 807        } else if state.clicked() == Some(platform::MouseButton::Left) && self.clicked.is_some() {
 808            self.clicked.as_ref().unwrap()
 809        } else if state.hovered() {
 810            self.hover.as_ref().unwrap_or(&self.default)
 811        } else {
 812            &self.default
 813        }
 814    }
 815
 816    pub fn disabled_style(&self) -> &T {
 817        self.disabled.as_ref().unwrap_or(&self.default)
 818    }
 819}
 820
 821impl<'de, T: DeserializeOwned> Deserialize<'de> for Interactive<T> {
 822    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
 823    where
 824        D: serde::Deserializer<'de>,
 825    {
 826        #[derive(Deserialize)]
 827        struct Helper {
 828            #[serde(flatten)]
 829            default: Value,
 830            hover: Option<Value>,
 831            hover_and_active: Option<Value>,
 832            clicked: Option<Value>,
 833            click_and_active: Option<Value>,
 834            active: Option<Value>,
 835            disabled: Option<Value>,
 836        }
 837
 838        let json = Helper::deserialize(deserializer)?;
 839
 840        let deserialize_state = |state_json: Option<Value>| -> Result<Option<T>, D::Error> {
 841            if let Some(mut state_json) = state_json {
 842                if let Value::Object(state_json) = &mut state_json {
 843                    if let Value::Object(default) = &json.default {
 844                        for (key, value) in default {
 845                            if !state_json.contains_key(key) {
 846                                state_json.insert(key.clone(), value.clone());
 847                            }
 848                        }
 849                    }
 850                }
 851                Ok(Some(
 852                    serde_json::from_value::<T>(state_json).map_err(serde::de::Error::custom)?,
 853                ))
 854            } else {
 855                Ok(None)
 856            }
 857        };
 858
 859        let hover = deserialize_state(json.hover)?;
 860        let hover_and_active = deserialize_state(json.hover_and_active)?;
 861        let clicked = deserialize_state(json.clicked)?;
 862        let click_and_active = deserialize_state(json.click_and_active)?;
 863        let active = deserialize_state(json.active)?;
 864        let disabled = deserialize_state(json.disabled)?;
 865        let default = serde_json::from_value(json.default).map_err(serde::de::Error::custom)?;
 866
 867        Ok(Interactive {
 868            default,
 869            hover,
 870            hover_and_active,
 871            clicked,
 872            click_and_active,
 873            active,
 874            disabled,
 875        })
 876    }
 877}
 878
 879impl Editor {
 880    pub fn replica_selection_style(&self, replica_id: u16) -> &SelectionStyle {
 881        let style_ix = replica_id as usize % (self.guest_selections.len() + 1);
 882        if style_ix == 0 {
 883            &self.selection
 884        } else {
 885            &self.guest_selections[style_ix - 1]
 886        }
 887    }
 888}
 889
 890#[derive(Default)]
 891pub struct SyntaxTheme {
 892    pub highlights: Vec<(String, HighlightStyle)>,
 893}
 894
 895impl SyntaxTheme {
 896    pub fn new(highlights: Vec<(String, HighlightStyle)>) -> Self {
 897        Self { highlights }
 898    }
 899}
 900
 901impl<'de> Deserialize<'de> for SyntaxTheme {
 902    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
 903    where
 904        D: serde::Deserializer<'de>,
 905    {
 906        let syntax_data: HashMap<String, HighlightStyle> = Deserialize::deserialize(deserializer)?;
 907
 908        let mut result = Self::new(Vec::new());
 909        for (key, style) in syntax_data {
 910            match result
 911                .highlights
 912                .binary_search_by(|(needle, _)| needle.cmp(&key))
 913            {
 914                Ok(i) | Err(i) => {
 915                    result.highlights.insert(i, (key, style));
 916                }
 917            }
 918        }
 919
 920        Ok(result)
 921    }
 922}
 923
 924#[derive(Clone, Deserialize, Default)]
 925pub struct HoverPopover {
 926    pub container: ContainerStyle,
 927    pub info_container: ContainerStyle,
 928    pub warning_container: ContainerStyle,
 929    pub error_container: ContainerStyle,
 930    pub block_style: ContainerStyle,
 931    pub prose: TextStyle,
 932    pub diagnostic_source_highlight: HighlightStyle,
 933    pub highlight: Color,
 934}
 935
 936#[derive(Clone, Deserialize, Default)]
 937pub struct TerminalStyle {
 938    pub black: Color,
 939    pub red: Color,
 940    pub green: Color,
 941    pub yellow: Color,
 942    pub blue: Color,
 943    pub magenta: Color,
 944    pub cyan: Color,
 945    pub white: Color,
 946    pub bright_black: Color,
 947    pub bright_red: Color,
 948    pub bright_green: Color,
 949    pub bright_yellow: Color,
 950    pub bright_blue: Color,
 951    pub bright_magenta: Color,
 952    pub bright_cyan: Color,
 953    pub bright_white: Color,
 954    pub foreground: Color,
 955    pub background: Color,
 956    pub modal_background: Color,
 957    pub cursor: Color,
 958    pub dim_black: Color,
 959    pub dim_red: Color,
 960    pub dim_green: Color,
 961    pub dim_yellow: Color,
 962    pub dim_blue: Color,
 963    pub dim_magenta: Color,
 964    pub dim_cyan: Color,
 965    pub dim_white: Color,
 966    pub bright_foreground: Color,
 967    pub dim_foreground: Color,
 968}
 969
 970#[derive(Clone, Deserialize, Default)]
 971pub struct FeedbackStyle {
 972    pub submit_button: Interactive<ContainedText>,
 973    pub button_margin: f32,
 974    pub info_text_default: ContainedText,
 975    pub link_text_default: ContainedText,
 976    pub link_text_hover: ContainedText,
 977}
 978
 979#[derive(Clone, Deserialize, Default)]
 980pub struct WelcomeStyle {
 981    pub page_width: f32,
 982    pub logo: SvgStyle,
 983    pub logo_subheading: ContainedText,
 984    pub usage_note: ContainedText,
 985    pub checkbox: CheckboxStyle,
 986    pub checkbox_container: ContainerStyle,
 987    pub button: Interactive<ContainedText>,
 988    pub button_group: ContainerStyle,
 989    pub heading_group: ContainerStyle,
 990    pub checkbox_group: ContainerStyle,
 991}
 992
 993#[derive(Clone, Deserialize, Default)]
 994pub struct ColorScheme {
 995    pub name: String,
 996    pub is_light: bool,
 997    pub ramps: RampSet,
 998    pub lowest: Layer,
 999    pub middle: Layer,
1000    pub highest: Layer,
1001
1002    pub popover_shadow: Shadow,
1003    pub modal_shadow: Shadow,
1004
1005    pub players: Vec<Player>,
1006}
1007
1008#[derive(Clone, Deserialize, Default)]
1009pub struct Player {
1010    pub cursor: Color,
1011    pub selection: Color,
1012}
1013
1014#[derive(Clone, Deserialize, Default)]
1015pub struct RampSet {
1016    pub neutral: Vec<Color>,
1017    pub red: Vec<Color>,
1018    pub orange: Vec<Color>,
1019    pub yellow: Vec<Color>,
1020    pub green: Vec<Color>,
1021    pub cyan: Vec<Color>,
1022    pub blue: Vec<Color>,
1023    pub violet: Vec<Color>,
1024    pub magenta: Vec<Color>,
1025}
1026
1027#[derive(Clone, Deserialize, Default)]
1028pub struct Layer {
1029    pub base: StyleSet,
1030    pub variant: StyleSet,
1031    pub on: StyleSet,
1032    pub accent: StyleSet,
1033    pub positive: StyleSet,
1034    pub warning: StyleSet,
1035    pub negative: StyleSet,
1036}
1037
1038#[derive(Clone, Deserialize, Default)]
1039pub struct StyleSet {
1040    pub default: Style,
1041    pub active: Style,
1042    pub disabled: Style,
1043    pub hovered: Style,
1044    pub pressed: Style,
1045    pub inverted: Style,
1046}
1047
1048#[derive(Clone, Deserialize, Default)]
1049pub struct Style {
1050    pub background: Color,
1051    pub border: Color,
1052    pub foreground: Color,
1053}