theme.rs

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