theme.rs

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