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