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