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 server_name_container: ContainerStyle,
 873    pub server_name_color: Color,
 874    pub server_name_size_percent: f32,
 875}
 876
 877#[derive(Clone, Copy, Default, Deserialize, JsonSchema)]
 878pub struct SelectionStyle {
 879    pub cursor: Color,
 880    pub selection: Color,
 881}
 882
 883#[derive(Clone, Deserialize, Default, JsonSchema)]
 884pub struct FieldEditor {
 885    #[serde(flatten)]
 886    pub container: ContainerStyle,
 887    pub text: TextStyle,
 888    #[serde(default)]
 889    pub placeholder_text: Option<TextStyle>,
 890    pub selection: SelectionStyle,
 891}
 892
 893#[derive(Clone, Deserialize, Default, JsonSchema)]
 894pub struct InteractiveColor {
 895    pub color: Color,
 896}
 897
 898#[derive(Clone, Deserialize, Default, JsonSchema)]
 899pub struct CodeActions {
 900    #[serde(default)]
 901    pub indicator: Toggleable<Interactive<InteractiveColor>>,
 902    pub vertical_scale: f32,
 903}
 904
 905#[derive(Clone, Deserialize, Default, JsonSchema)]
 906pub struct Folds {
 907    pub indicator: Toggleable<Interactive<InteractiveColor>>,
 908    pub ellipses: FoldEllipses,
 909    pub fold_background: Color,
 910    pub icon_margin_scale: f32,
 911    pub folded_icon: String,
 912    pub foldable_icon: String,
 913}
 914
 915#[derive(Clone, Deserialize, Default, JsonSchema)]
 916pub struct FoldEllipses {
 917    pub text_color: Color,
 918    pub background: Interactive<InteractiveColor>,
 919    pub corner_radius_factor: f32,
 920}
 921
 922#[derive(Clone, Deserialize, Default, JsonSchema)]
 923pub struct DiffStyle {
 924    pub inserted: Color,
 925    pub modified: Color,
 926    pub deleted: Color,
 927    pub removed_width_em: f32,
 928    pub width_em: f32,
 929    pub corner_radius: f32,
 930}
 931
 932#[derive(Debug, Default, Clone, Copy, JsonSchema)]
 933pub struct Interactive<T> {
 934    pub default: T,
 935    pub hovered: Option<T>,
 936    pub clicked: Option<T>,
 937    pub disabled: Option<T>,
 938}
 939
 940impl<T> Deref for Interactive<T> {
 941    type Target = T;
 942
 943    fn deref(&self) -> &Self::Target {
 944        &self.default
 945    }
 946}
 947
 948impl Interactive<()> {
 949    pub fn new_blank() -> Self {
 950        Self {
 951            default: (),
 952            hovered: None,
 953            clicked: None,
 954            disabled: None,
 955        }
 956    }
 957}
 958
 959#[derive(Clone, Copy, Debug, Default, Deserialize, JsonSchema)]
 960pub struct Toggleable<T> {
 961    active: T,
 962    inactive: T,
 963}
 964
 965impl<T> Deref for Toggleable<T> {
 966    type Target = T;
 967
 968    fn deref(&self) -> &Self::Target {
 969        &self.inactive
 970    }
 971}
 972
 973impl Toggleable<()> {
 974    pub fn new_blank() -> Self {
 975        Self {
 976            active: (),
 977            inactive: (),
 978        }
 979    }
 980}
 981
 982impl<T> Toggleable<T> {
 983    pub fn new(active: T, inactive: T) -> Self {
 984        Self { active, inactive }
 985    }
 986    pub fn in_state(&self, active: bool) -> &T {
 987        if active {
 988            &self.active
 989        } else {
 990            &self.inactive
 991        }
 992    }
 993    pub fn active_state(&self) -> &T {
 994        self.in_state(true)
 995    }
 996
 997    pub fn inactive_state(&self) -> &T {
 998        self.in_state(false)
 999    }
1000}
1001
1002impl<T> Interactive<T> {
1003    pub fn style_for(&self, state: &mut MouseState) -> &T {
1004        if state.clicked() == Some(platform::MouseButton::Left) && self.clicked.is_some() {
1005            self.clicked.as_ref().unwrap()
1006        } else if state.hovered() {
1007            self.hovered.as_ref().unwrap_or(&self.default)
1008        } else {
1009            &self.default
1010        }
1011    }
1012    pub fn disabled_style(&self) -> &T {
1013        self.disabled.as_ref().unwrap_or(&self.default)
1014    }
1015}
1016
1017impl<T> Toggleable<Interactive<T>> {
1018    pub fn style_for(&self, active: bool, state: &mut MouseState) -> &T {
1019        self.in_state(active).style_for(state)
1020    }
1021
1022    pub fn default_style(&self) -> &T {
1023        &self.inactive.default
1024    }
1025}
1026
1027impl<'de, T: DeserializeOwned> Deserialize<'de> for Interactive<T> {
1028    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1029    where
1030        D: serde::Deserializer<'de>,
1031    {
1032        #[derive(Deserialize)]
1033        struct Helper {
1034            default: Value,
1035            hovered: Option<Value>,
1036            clicked: Option<Value>,
1037            disabled: Option<Value>,
1038        }
1039
1040        let json = Helper::deserialize(deserializer)?;
1041
1042        let deserialize_state = |state_json: Option<Value>| -> Result<Option<T>, D::Error> {
1043            if let Some(mut state_json) = state_json {
1044                if let Value::Object(state_json) = &mut state_json {
1045                    if let Value::Object(default) = &json.default {
1046                        for (key, value) in default {
1047                            if !state_json.contains_key(key) {
1048                                state_json.insert(key.clone(), value.clone());
1049                            }
1050                        }
1051                    }
1052                }
1053                Ok(Some(
1054                    serde_json::from_value::<T>(state_json).map_err(serde::de::Error::custom)?,
1055                ))
1056            } else {
1057                Ok(None)
1058            }
1059        };
1060
1061        let hovered = deserialize_state(json.hovered)?;
1062        let clicked = deserialize_state(json.clicked)?;
1063        let disabled = deserialize_state(json.disabled)?;
1064        let default = serde_json::from_value(json.default).map_err(serde::de::Error::custom)?;
1065
1066        Ok(Interactive {
1067            default,
1068            hovered,
1069            clicked,
1070            disabled,
1071        })
1072    }
1073}
1074
1075impl Editor {
1076    pub fn selection_style_for_room_participant(&self, participant_index: u32) -> SelectionStyle {
1077        if self.guest_selections.is_empty() {
1078            return SelectionStyle::default();
1079        }
1080        let style_ix = participant_index as usize % self.guest_selections.len();
1081        self.guest_selections[style_ix]
1082    }
1083}
1084
1085#[derive(Default, JsonSchema)]
1086pub struct SyntaxTheme {
1087    pub highlights: Vec<(String, HighlightStyle)>,
1088}
1089
1090impl SyntaxTheme {
1091    pub fn new(highlights: Vec<(String, HighlightStyle)>) -> Self {
1092        Self { highlights }
1093    }
1094}
1095
1096impl<'de> Deserialize<'de> for SyntaxTheme {
1097    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1098    where
1099        D: serde::Deserializer<'de>,
1100    {
1101        let syntax_data: HashMap<String, HighlightStyle> = Deserialize::deserialize(deserializer)?;
1102
1103        let mut result = Self::new(Vec::new());
1104        for (key, style) in syntax_data {
1105            match result
1106                .highlights
1107                .binary_search_by(|(needle, _)| needle.cmp(&key))
1108            {
1109                Ok(i) | Err(i) => {
1110                    result.highlights.insert(i, (key, style));
1111                }
1112            }
1113        }
1114
1115        Ok(result)
1116    }
1117}
1118
1119#[derive(Clone, Deserialize, Default, JsonSchema)]
1120pub struct HoverPopover {
1121    pub container: ContainerStyle,
1122    pub info_container: ContainerStyle,
1123    pub warning_container: ContainerStyle,
1124    pub error_container: ContainerStyle,
1125    pub block_style: ContainerStyle,
1126    pub prose: TextStyle,
1127    pub diagnostic_source_highlight: HighlightStyle,
1128    pub highlight: Color,
1129}
1130
1131#[derive(Clone, Deserialize, Default, JsonSchema)]
1132pub struct TerminalStyle {
1133    pub black: Color,
1134    pub red: Color,
1135    pub green: Color,
1136    pub yellow: Color,
1137    pub blue: Color,
1138    pub magenta: Color,
1139    pub cyan: Color,
1140    pub white: Color,
1141    pub bright_black: Color,
1142    pub bright_red: Color,
1143    pub bright_green: Color,
1144    pub bright_yellow: Color,
1145    pub bright_blue: Color,
1146    pub bright_magenta: Color,
1147    pub bright_cyan: Color,
1148    pub bright_white: Color,
1149    pub foreground: Color,
1150    pub background: Color,
1151    pub modal_background: Color,
1152    pub cursor: Color,
1153    pub dim_black: Color,
1154    pub dim_red: Color,
1155    pub dim_green: Color,
1156    pub dim_yellow: Color,
1157    pub dim_blue: Color,
1158    pub dim_magenta: Color,
1159    pub dim_cyan: Color,
1160    pub dim_white: Color,
1161    pub bright_foreground: Color,
1162    pub dim_foreground: Color,
1163}
1164
1165#[derive(Clone, Deserialize, Default, JsonSchema)]
1166pub struct AssistantStyle {
1167    pub container: ContainerStyle,
1168    pub hamburger_button: Interactive<IconStyle>,
1169    pub split_button: Interactive<IconStyle>,
1170    pub assist_button: Interactive<IconStyle>,
1171    pub quote_button: Interactive<IconStyle>,
1172    pub zoom_in_button: Interactive<IconStyle>,
1173    pub zoom_out_button: Interactive<IconStyle>,
1174    pub plus_button: Interactive<IconStyle>,
1175    pub title: ContainedText,
1176    pub message_header: ContainerStyle,
1177    pub sent_at: ContainedText,
1178    pub user_sender: Interactive<ContainedText>,
1179    pub assistant_sender: Interactive<ContainedText>,
1180    pub system_sender: Interactive<ContainedText>,
1181    pub model: Interactive<ContainedText>,
1182    pub remaining_tokens: ContainedText,
1183    pub low_remaining_tokens: ContainedText,
1184    pub no_remaining_tokens: ContainedText,
1185    pub error_icon: Icon,
1186    pub api_key_editor: FieldEditor,
1187    pub api_key_prompt: ContainedText,
1188    pub saved_conversation: SavedConversation,
1189    pub inline: InlineAssistantStyle,
1190}
1191
1192#[derive(Clone, Deserialize, Default, JsonSchema)]
1193pub struct InlineAssistantStyle {
1194    #[serde(flatten)]
1195    pub container: ContainerStyle,
1196    pub editor: FieldEditor,
1197    pub disabled_editor: FieldEditor,
1198    pub pending_edit_background: Color,
1199    pub include_conversation: ToggleIconButtonStyle,
1200}
1201
1202#[derive(Clone, Deserialize, Default, JsonSchema)]
1203pub struct Contained<T> {
1204    container: ContainerStyle,
1205    contained: T,
1206}
1207
1208#[derive(Clone, Deserialize, Default, JsonSchema)]
1209pub struct SavedConversation {
1210    pub container: Interactive<ContainerStyle>,
1211    pub saved_at: ContainedText,
1212    pub title: ContainedText,
1213}
1214
1215#[derive(Clone, Deserialize, Default, JsonSchema)]
1216pub struct FeedbackStyle {
1217    pub submit_button: Interactive<ContainedText>,
1218    pub button_margin: f32,
1219    pub info_text_default: ContainedText,
1220    pub link_text_default: ContainedText,
1221    pub link_text_hover: ContainedText,
1222}
1223
1224#[derive(Clone, Deserialize, Default, JsonSchema)]
1225pub struct WelcomeStyle {
1226    pub page_width: f32,
1227    pub logo: SvgStyle,
1228    pub logo_subheading: ContainedText,
1229    pub usage_note: ContainedText,
1230    pub checkbox: CheckboxStyle,
1231    pub checkbox_container: ContainerStyle,
1232    pub button: Interactive<ContainedText>,
1233    pub button_group: ContainerStyle,
1234    pub heading_group: ContainerStyle,
1235    pub checkbox_group: ContainerStyle,
1236}
1237
1238#[derive(Clone, Deserialize, Default, JsonSchema)]
1239pub struct ColorScheme {
1240    pub name: String,
1241    pub is_light: bool,
1242    pub ramps: RampSet,
1243    pub lowest: Layer,
1244    pub middle: Layer,
1245    pub highest: Layer,
1246
1247    pub popover_shadow: Shadow,
1248    pub modal_shadow: Shadow,
1249
1250    pub players: Vec<Player>,
1251}
1252
1253#[derive(Clone, Deserialize, Default, JsonSchema)]
1254pub struct Player {
1255    pub cursor: Color,
1256    pub selection: Color,
1257}
1258
1259#[derive(Clone, Deserialize, Default, JsonSchema)]
1260pub struct RampSet {
1261    pub neutral: Vec<Color>,
1262    pub red: Vec<Color>,
1263    pub orange: Vec<Color>,
1264    pub yellow: Vec<Color>,
1265    pub green: Vec<Color>,
1266    pub cyan: Vec<Color>,
1267    pub blue: Vec<Color>,
1268    pub violet: Vec<Color>,
1269    pub magenta: Vec<Color>,
1270}
1271
1272#[derive(Clone, Deserialize, Default, JsonSchema)]
1273pub struct Layer {
1274    pub base: StyleSet,
1275    pub variant: StyleSet,
1276    pub on: StyleSet,
1277    pub accent: StyleSet,
1278    pub positive: StyleSet,
1279    pub warning: StyleSet,
1280    pub negative: StyleSet,
1281}
1282
1283#[derive(Clone, Deserialize, Default, JsonSchema)]
1284pub struct StyleSet {
1285    pub default: Style,
1286    pub active: Style,
1287    pub disabled: Style,
1288    pub hovered: Style,
1289    pub pressed: Style,
1290    pub inverted: Style,
1291}
1292
1293#[derive(Clone, Deserialize, Default, JsonSchema)]
1294pub struct Style {
1295    pub background: Color,
1296    pub border: Color,
1297    pub foreground: Color,
1298}