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