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 message: ChatMessage,
 638    pub pending_message: ChatMessage,
 639    pub sign_in_prompt: Interactive<TextStyle>,
 640    pub icon_button: Interactive<IconButton>,
 641}
 642
 643#[derive(Deserialize, Default, JsonSchema)]
 644pub struct ChatMessage {
 645    #[serde(flatten)]
 646    pub container: ContainerStyle,
 647    pub body: TextStyle,
 648    pub sender: ContainedText,
 649    pub timestamp: ContainedText,
 650}
 651
 652#[derive(Deserialize, Default, JsonSchema)]
 653pub struct ChannelSelect {
 654    #[serde(flatten)]
 655    pub container: ContainerStyle,
 656    pub header: ChannelName,
 657    pub item: ChannelName,
 658    pub active_item: ChannelName,
 659    pub hovered_item: ChannelName,
 660    pub menu: ContainerStyle,
 661}
 662
 663#[derive(Deserialize, Default, JsonSchema)]
 664pub struct ChannelName {
 665    #[serde(flatten)]
 666    pub container: ContainerStyle,
 667    pub hash: ContainedText,
 668    pub name: TextStyle,
 669}
 670
 671#[derive(Clone, Deserialize, Default, JsonSchema)]
 672pub struct Picker {
 673    #[serde(flatten)]
 674    pub container: ContainerStyle,
 675    pub empty_container: ContainerStyle,
 676    pub input_editor: FieldEditor,
 677    pub empty_input_editor: FieldEditor,
 678    pub no_matches: ContainedLabel,
 679    pub item: Toggleable<Interactive<ContainedLabel>>,
 680    pub header: ContainedLabel,
 681    pub footer: Interactive<ContainedLabel>,
 682}
 683
 684#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
 685pub struct ContainedText {
 686    #[serde(flatten)]
 687    pub container: ContainerStyle,
 688    #[serde(flatten)]
 689    pub text: TextStyle,
 690}
 691
 692#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
 693pub struct ContainedLabel {
 694    #[serde(flatten)]
 695    pub container: ContainerStyle,
 696    #[serde(flatten)]
 697    pub label: LabelStyle,
 698}
 699
 700#[derive(Clone, Deserialize, Default, JsonSchema)]
 701pub struct ProjectDiagnostics {
 702    #[serde(flatten)]
 703    pub container: ContainerStyle,
 704    pub empty_message: TextStyle,
 705    pub tab_icon_width: f32,
 706    pub tab_icon_spacing: f32,
 707    pub tab_summary_spacing: f32,
 708}
 709
 710#[derive(Deserialize, Default, JsonSchema)]
 711pub struct ContactNotification {
 712    pub header_avatar: ImageStyle,
 713    pub header_message: ContainedText,
 714    pub header_height: f32,
 715    pub body_message: ContainedText,
 716    pub button: Interactive<ContainedText>,
 717    pub dismiss_button: Interactive<IconButton>,
 718}
 719
 720#[derive(Deserialize, Default, JsonSchema)]
 721pub struct UpdateNotification {
 722    pub message: ContainedText,
 723    pub action_message: Interactive<ContainedText>,
 724    pub dismiss_button: Interactive<IconButton>,
 725}
 726
 727#[derive(Deserialize, Default, JsonSchema)]
 728pub struct MessageNotification {
 729    pub message: ContainedText,
 730    pub action_message: Interactive<ContainedText>,
 731    pub dismiss_button: Interactive<IconButton>,
 732}
 733
 734#[derive(Deserialize, Default, JsonSchema)]
 735pub struct ProjectSharedNotification {
 736    pub window_height: f32,
 737    pub window_width: f32,
 738    #[serde(default)]
 739    pub background: Color,
 740    pub owner_container: ContainerStyle,
 741    pub owner_avatar: ImageStyle,
 742    pub owner_metadata: ContainerStyle,
 743    pub owner_username: ContainedText,
 744    pub message: ContainedText,
 745    pub worktree_roots: ContainedText,
 746    pub button_width: f32,
 747    pub open_button: ContainedText,
 748    pub dismiss_button: ContainedText,
 749}
 750
 751#[derive(Deserialize, Default, JsonSchema)]
 752pub struct IncomingCallNotification {
 753    pub window_height: f32,
 754    pub window_width: f32,
 755    #[serde(default)]
 756    pub background: Color,
 757    pub caller_container: ContainerStyle,
 758    pub caller_avatar: ImageStyle,
 759    pub caller_metadata: ContainerStyle,
 760    pub caller_username: ContainedText,
 761    pub caller_message: ContainedText,
 762    pub worktree_roots: ContainedText,
 763    pub button_width: f32,
 764    pub accept_button: ContainedText,
 765    pub decline_button: ContainedText,
 766}
 767
 768#[derive(Clone, Deserialize, Default, JsonSchema)]
 769pub struct Editor {
 770    pub text_color: Color,
 771    #[serde(default)]
 772    pub background: Color,
 773    pub selection: SelectionStyle,
 774    pub gutter_background: Color,
 775    pub gutter_padding_factor: f32,
 776    pub active_line_background: Color,
 777    pub highlighted_line_background: Color,
 778    pub rename_fade: f32,
 779    pub document_highlight_read_background: Color,
 780    pub document_highlight_write_background: Color,
 781    pub diff: DiffStyle,
 782    pub wrap_guide: Color,
 783    pub active_wrap_guide: Color,
 784    pub line_number: Color,
 785    pub line_number_active: Color,
 786    pub guest_selections: Vec<SelectionStyle>,
 787    pub absent_selection: SelectionStyle,
 788    pub syntax: Arc<SyntaxTheme>,
 789    pub hint: HighlightStyle,
 790    pub suggestion: HighlightStyle,
 791    pub diagnostic_path_header: DiagnosticPathHeader,
 792    pub diagnostic_header: DiagnosticHeader,
 793    pub error_diagnostic: DiagnosticStyle,
 794    pub invalid_error_diagnostic: DiagnosticStyle,
 795    pub warning_diagnostic: DiagnosticStyle,
 796    pub invalid_warning_diagnostic: DiagnosticStyle,
 797    pub information_diagnostic: DiagnosticStyle,
 798    pub invalid_information_diagnostic: DiagnosticStyle,
 799    pub hint_diagnostic: DiagnosticStyle,
 800    pub invalid_hint_diagnostic: DiagnosticStyle,
 801    pub autocomplete: AutocompleteStyle,
 802    pub code_actions: CodeActions,
 803    pub folds: Folds,
 804    pub unnecessary_code_fade: f32,
 805    pub hover_popover: HoverPopover,
 806    pub link_definition: HighlightStyle,
 807    pub composition_mark: HighlightStyle,
 808    pub jump_icon: Interactive<IconButton>,
 809    pub scrollbar: Scrollbar,
 810    pub whitespace: Color,
 811}
 812
 813#[derive(Clone, Deserialize, Default, JsonSchema)]
 814pub struct Scrollbar {
 815    pub track: ContainerStyle,
 816    pub thumb: ContainerStyle,
 817    pub width: f32,
 818    pub min_height_factor: f32,
 819    pub git: BufferGitDiffColors,
 820    pub selections: Color,
 821}
 822
 823#[derive(Clone, Deserialize, Default, JsonSchema)]
 824pub struct BufferGitDiffColors {
 825    pub inserted: Color,
 826    pub modified: Color,
 827    pub deleted: Color,
 828}
 829
 830#[derive(Clone, Deserialize, Default, JsonSchema)]
 831pub struct DiagnosticPathHeader {
 832    #[serde(flatten)]
 833    pub container: ContainerStyle,
 834    pub filename: ContainedText,
 835    pub path: ContainedText,
 836    pub text_scale_factor: f32,
 837}
 838
 839#[derive(Clone, Deserialize, Default, JsonSchema)]
 840pub struct DiagnosticHeader {
 841    #[serde(flatten)]
 842    pub container: ContainerStyle,
 843    pub source: ContainedLabel,
 844    pub message: ContainedLabel,
 845    pub code: ContainedText,
 846    pub text_scale_factor: f32,
 847    pub icon_width_factor: f32,
 848}
 849
 850#[derive(Clone, Deserialize, Default, JsonSchema)]
 851pub struct DiagnosticStyle {
 852    pub message: LabelStyle,
 853    #[serde(default)]
 854    pub header: ContainerStyle,
 855    pub text_scale_factor: f32,
 856}
 857
 858#[derive(Clone, Deserialize, Default, JsonSchema)]
 859pub struct AutocompleteStyle {
 860    #[serde(flatten)]
 861    pub container: ContainerStyle,
 862    pub item: ContainerStyle,
 863    pub selected_item: ContainerStyle,
 864    pub hovered_item: ContainerStyle,
 865    pub match_highlight: HighlightStyle,
 866    pub server_name_container: ContainerStyle,
 867    pub server_name_color: Color,
 868    pub server_name_size_percent: f32,
 869}
 870
 871#[derive(Clone, Copy, Default, Deserialize, JsonSchema)]
 872pub struct SelectionStyle {
 873    pub cursor: Color,
 874    pub selection: Color,
 875}
 876
 877#[derive(Clone, Deserialize, Default, JsonSchema)]
 878pub struct FieldEditor {
 879    #[serde(flatten)]
 880    pub container: ContainerStyle,
 881    pub text: TextStyle,
 882    #[serde(default)]
 883    pub placeholder_text: Option<TextStyle>,
 884    pub selection: SelectionStyle,
 885}
 886
 887#[derive(Clone, Deserialize, Default, JsonSchema)]
 888pub struct InteractiveColor {
 889    pub color: Color,
 890}
 891
 892#[derive(Clone, Deserialize, Default, JsonSchema)]
 893pub struct CodeActions {
 894    #[serde(default)]
 895    pub indicator: Toggleable<Interactive<InteractiveColor>>,
 896    pub vertical_scale: f32,
 897}
 898
 899#[derive(Clone, Deserialize, Default, JsonSchema)]
 900pub struct Folds {
 901    pub indicator: Toggleable<Interactive<InteractiveColor>>,
 902    pub ellipses: FoldEllipses,
 903    pub fold_background: Color,
 904    pub icon_margin_scale: f32,
 905    pub folded_icon: String,
 906    pub foldable_icon: String,
 907}
 908
 909#[derive(Clone, Deserialize, Default, JsonSchema)]
 910pub struct FoldEllipses {
 911    pub text_color: Color,
 912    pub background: Interactive<InteractiveColor>,
 913    pub corner_radius_factor: f32,
 914}
 915
 916#[derive(Clone, Deserialize, Default, JsonSchema)]
 917pub struct DiffStyle {
 918    pub inserted: Color,
 919    pub modified: Color,
 920    pub deleted: Color,
 921    pub removed_width_em: f32,
 922    pub width_em: f32,
 923    pub corner_radius: f32,
 924}
 925
 926#[derive(Debug, Default, Clone, Copy, JsonSchema)]
 927pub struct Interactive<T> {
 928    pub default: T,
 929    pub hovered: Option<T>,
 930    pub clicked: Option<T>,
 931    pub disabled: Option<T>,
 932}
 933
 934impl<T> Deref for Interactive<T> {
 935    type Target = T;
 936
 937    fn deref(&self) -> &Self::Target {
 938        &self.default
 939    }
 940}
 941
 942impl Interactive<()> {
 943    pub fn new_blank() -> Self {
 944        Self {
 945            default: (),
 946            hovered: None,
 947            clicked: None,
 948            disabled: None,
 949        }
 950    }
 951}
 952
 953#[derive(Clone, Copy, Debug, Default, Deserialize, JsonSchema)]
 954pub struct Toggleable<T> {
 955    active: T,
 956    inactive: T,
 957}
 958
 959impl<T> Deref for Toggleable<T> {
 960    type Target = T;
 961
 962    fn deref(&self) -> &Self::Target {
 963        &self.inactive
 964    }
 965}
 966
 967impl Toggleable<()> {
 968    pub fn new_blank() -> Self {
 969        Self {
 970            active: (),
 971            inactive: (),
 972        }
 973    }
 974}
 975
 976impl<T> Toggleable<T> {
 977    pub fn new(active: T, inactive: T) -> Self {
 978        Self { active, inactive }
 979    }
 980    pub fn in_state(&self, active: bool) -> &T {
 981        if active {
 982            &self.active
 983        } else {
 984            &self.inactive
 985        }
 986    }
 987    pub fn active_state(&self) -> &T {
 988        self.in_state(true)
 989    }
 990
 991    pub fn inactive_state(&self) -> &T {
 992        self.in_state(false)
 993    }
 994}
 995
 996impl<T> Interactive<T> {
 997    pub fn style_for(&self, state: &mut MouseState) -> &T {
 998        if state.clicked() == Some(platform::MouseButton::Left) && self.clicked.is_some() {
 999            self.clicked.as_ref().unwrap()
1000        } else if state.hovered() {
1001            self.hovered.as_ref().unwrap_or(&self.default)
1002        } else {
1003            &self.default
1004        }
1005    }
1006    pub fn disabled_style(&self) -> &T {
1007        self.disabled.as_ref().unwrap_or(&self.default)
1008    }
1009}
1010
1011impl<T> Toggleable<Interactive<T>> {
1012    pub fn style_for(&self, active: bool, state: &mut MouseState) -> &T {
1013        self.in_state(active).style_for(state)
1014    }
1015
1016    pub fn default_style(&self) -> &T {
1017        &self.inactive.default
1018    }
1019}
1020
1021impl<'de, T: DeserializeOwned> Deserialize<'de> for Interactive<T> {
1022    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1023    where
1024        D: serde::Deserializer<'de>,
1025    {
1026        #[derive(Deserialize)]
1027        struct Helper {
1028            default: Value,
1029            hovered: Option<Value>,
1030            clicked: Option<Value>,
1031            disabled: Option<Value>,
1032        }
1033
1034        let json = Helper::deserialize(deserializer)?;
1035
1036        let deserialize_state = |state_json: Option<Value>| -> Result<Option<T>, D::Error> {
1037            if let Some(mut state_json) = state_json {
1038                if let Value::Object(state_json) = &mut state_json {
1039                    if let Value::Object(default) = &json.default {
1040                        for (key, value) in default {
1041                            if !state_json.contains_key(key) {
1042                                state_json.insert(key.clone(), value.clone());
1043                            }
1044                        }
1045                    }
1046                }
1047                Ok(Some(
1048                    serde_json::from_value::<T>(state_json).map_err(serde::de::Error::custom)?,
1049                ))
1050            } else {
1051                Ok(None)
1052            }
1053        };
1054
1055        let hovered = deserialize_state(json.hovered)?;
1056        let clicked = deserialize_state(json.clicked)?;
1057        let disabled = deserialize_state(json.disabled)?;
1058        let default = serde_json::from_value(json.default).map_err(serde::de::Error::custom)?;
1059
1060        Ok(Interactive {
1061            default,
1062            hovered,
1063            clicked,
1064            disabled,
1065        })
1066    }
1067}
1068
1069impl Editor {
1070    pub fn selection_style_for_room_participant(&self, participant_index: u32) -> SelectionStyle {
1071        if self.guest_selections.is_empty() {
1072            return SelectionStyle::default();
1073        }
1074        let style_ix = participant_index as usize % self.guest_selections.len();
1075        self.guest_selections[style_ix]
1076    }
1077}
1078
1079#[derive(Default, JsonSchema)]
1080pub struct SyntaxTheme {
1081    pub highlights: Vec<(String, HighlightStyle)>,
1082}
1083
1084impl SyntaxTheme {
1085    pub fn new(highlights: Vec<(String, HighlightStyle)>) -> Self {
1086        Self { highlights }
1087    }
1088}
1089
1090impl<'de> Deserialize<'de> for SyntaxTheme {
1091    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1092    where
1093        D: serde::Deserializer<'de>,
1094    {
1095        let syntax_data: HashMap<String, HighlightStyle> = Deserialize::deserialize(deserializer)?;
1096
1097        let mut result = Self::new(Vec::new());
1098        for (key, style) in syntax_data {
1099            match result
1100                .highlights
1101                .binary_search_by(|(needle, _)| needle.cmp(&key))
1102            {
1103                Ok(i) | Err(i) => {
1104                    result.highlights.insert(i, (key, style));
1105                }
1106            }
1107        }
1108
1109        Ok(result)
1110    }
1111}
1112
1113#[derive(Clone, Deserialize, Default, JsonSchema)]
1114pub struct HoverPopover {
1115    pub container: ContainerStyle,
1116    pub info_container: ContainerStyle,
1117    pub warning_container: ContainerStyle,
1118    pub error_container: ContainerStyle,
1119    pub block_style: ContainerStyle,
1120    pub prose: TextStyle,
1121    pub diagnostic_source_highlight: HighlightStyle,
1122    pub highlight: Color,
1123}
1124
1125#[derive(Clone, Deserialize, Default, JsonSchema)]
1126pub struct TerminalStyle {
1127    pub black: Color,
1128    pub red: Color,
1129    pub green: Color,
1130    pub yellow: Color,
1131    pub blue: Color,
1132    pub magenta: Color,
1133    pub cyan: Color,
1134    pub white: Color,
1135    pub bright_black: Color,
1136    pub bright_red: Color,
1137    pub bright_green: Color,
1138    pub bright_yellow: Color,
1139    pub bright_blue: Color,
1140    pub bright_magenta: Color,
1141    pub bright_cyan: Color,
1142    pub bright_white: Color,
1143    pub foreground: Color,
1144    pub background: Color,
1145    pub modal_background: Color,
1146    pub cursor: Color,
1147    pub dim_black: Color,
1148    pub dim_red: Color,
1149    pub dim_green: Color,
1150    pub dim_yellow: Color,
1151    pub dim_blue: Color,
1152    pub dim_magenta: Color,
1153    pub dim_cyan: Color,
1154    pub dim_white: Color,
1155    pub bright_foreground: Color,
1156    pub dim_foreground: Color,
1157}
1158
1159#[derive(Clone, Deserialize, Default, JsonSchema)]
1160pub struct AssistantStyle {
1161    pub container: ContainerStyle,
1162    pub hamburger_button: Interactive<IconStyle>,
1163    pub split_button: Interactive<IconStyle>,
1164    pub assist_button: Interactive<IconStyle>,
1165    pub quote_button: Interactive<IconStyle>,
1166    pub zoom_in_button: Interactive<IconStyle>,
1167    pub zoom_out_button: Interactive<IconStyle>,
1168    pub plus_button: Interactive<IconStyle>,
1169    pub title: ContainedText,
1170    pub message_header: ContainerStyle,
1171    pub sent_at: ContainedText,
1172    pub user_sender: Interactive<ContainedText>,
1173    pub assistant_sender: Interactive<ContainedText>,
1174    pub system_sender: Interactive<ContainedText>,
1175    pub model: Interactive<ContainedText>,
1176    pub remaining_tokens: ContainedText,
1177    pub low_remaining_tokens: ContainedText,
1178    pub no_remaining_tokens: ContainedText,
1179    pub error_icon: Icon,
1180    pub api_key_editor: FieldEditor,
1181    pub api_key_prompt: ContainedText,
1182    pub saved_conversation: SavedConversation,
1183    pub inline: InlineAssistantStyle,
1184}
1185
1186#[derive(Clone, Deserialize, Default, JsonSchema)]
1187pub struct InlineAssistantStyle {
1188    #[serde(flatten)]
1189    pub container: ContainerStyle,
1190    pub editor: FieldEditor,
1191    pub disabled_editor: FieldEditor,
1192    pub pending_edit_background: Color,
1193    pub include_conversation: ToggleIconButtonStyle,
1194}
1195
1196#[derive(Clone, Deserialize, Default, JsonSchema)]
1197pub struct Contained<T> {
1198    container: ContainerStyle,
1199    contained: T,
1200}
1201
1202#[derive(Clone, Deserialize, Default, JsonSchema)]
1203pub struct SavedConversation {
1204    pub container: Interactive<ContainerStyle>,
1205    pub saved_at: ContainedText,
1206    pub title: ContainedText,
1207}
1208
1209#[derive(Clone, Deserialize, Default, JsonSchema)]
1210pub struct FeedbackStyle {
1211    pub submit_button: Interactive<ContainedText>,
1212    pub button_margin: f32,
1213    pub info_text_default: ContainedText,
1214    pub link_text_default: ContainedText,
1215    pub link_text_hover: ContainedText,
1216}
1217
1218#[derive(Clone, Deserialize, Default, JsonSchema)]
1219pub struct WelcomeStyle {
1220    pub page_width: f32,
1221    pub logo: SvgStyle,
1222    pub logo_subheading: ContainedText,
1223    pub usage_note: ContainedText,
1224    pub checkbox: CheckboxStyle,
1225    pub checkbox_container: ContainerStyle,
1226    pub button: Interactive<ContainedText>,
1227    pub button_group: ContainerStyle,
1228    pub heading_group: ContainerStyle,
1229    pub checkbox_group: ContainerStyle,
1230}
1231
1232#[derive(Clone, Deserialize, Default, JsonSchema)]
1233pub struct ColorScheme {
1234    pub name: String,
1235    pub is_light: bool,
1236    pub ramps: RampSet,
1237    pub lowest: Layer,
1238    pub middle: Layer,
1239    pub highest: Layer,
1240
1241    pub popover_shadow: Shadow,
1242    pub modal_shadow: Shadow,
1243
1244    pub players: Vec<Player>,
1245}
1246
1247#[derive(Clone, Deserialize, Default, JsonSchema)]
1248pub struct Player {
1249    pub cursor: Color,
1250    pub selection: Color,
1251}
1252
1253#[derive(Clone, Deserialize, Default, JsonSchema)]
1254pub struct RampSet {
1255    pub neutral: Vec<Color>,
1256    pub red: Vec<Color>,
1257    pub orange: Vec<Color>,
1258    pub yellow: Vec<Color>,
1259    pub green: Vec<Color>,
1260    pub cyan: Vec<Color>,
1261    pub blue: Vec<Color>,
1262    pub violet: Vec<Color>,
1263    pub magenta: Vec<Color>,
1264}
1265
1266#[derive(Clone, Deserialize, Default, JsonSchema)]
1267pub struct Layer {
1268    pub base: StyleSet,
1269    pub variant: StyleSet,
1270    pub on: StyleSet,
1271    pub accent: StyleSet,
1272    pub positive: StyleSet,
1273    pub warning: StyleSet,
1274    pub negative: StyleSet,
1275}
1276
1277#[derive(Clone, Deserialize, Default, JsonSchema)]
1278pub struct StyleSet {
1279    pub default: Style,
1280    pub active: Style,
1281    pub disabled: Style,
1282    pub hovered: Style,
1283    pub pressed: Style,
1284    pub inverted: Style,
1285}
1286
1287#[derive(Clone, Deserialize, Default, JsonSchema)]
1288pub struct Style {
1289    pub background: Color,
1290    pub border: Color,
1291    pub foreground: Color,
1292}