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