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