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