theme.rs

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