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