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