theme.rs

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