theme.rs

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