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