theme.rs

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