theme.rs

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