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 git_menu_button: Toggleable<Interactive<ContainedText>>,
 122    pub item_spacing: f32,
 123    pub face_pile_spacing: f32,
 124    pub avatar_ribbon: AvatarRibbon,
 125    pub follower_avatar_overlap: f32,
 126    pub leader_selection: ContainerStyle,
 127    pub offline_icon: OfflineIcon,
 128    pub leader_avatar: AvatarStyle,
 129    pub follower_avatar: AvatarStyle,
 130    pub inactive_avatar_grayscale: bool,
 131    pub sign_in_button: Toggleable<Interactive<ContainedText>>,
 132    pub outdated_warning: ContainedText,
 133    pub share_button: Toggleable<Interactive<ContainedText>>,
 134    pub muted: Color,
 135    pub speaking: Color,
 136    pub screen_share_button: Toggleable<Interactive<IconButton>>,
 137    pub toggle_contacts_button: Toggleable<Interactive<IconButton>>,
 138    pub toggle_microphone_button: Toggleable<Interactive<IconButton>>,
 139    pub toggle_speakers_button: Toggleable<Interactive<IconButton>>,
 140    pub leave_call_button: Interactive<IconButton>,
 141    pub toggle_contacts_badge: ContainerStyle,
 142    pub user_menu: UserMenu,
 143}
 144
 145#[derive(Clone, Deserialize, Default, JsonSchema)]
 146pub struct TitlebarMenu {
 147    pub width: f32,
 148    pub height: f32,
 149}
 150
 151#[derive(Clone, Deserialize, Default, JsonSchema)]
 152pub struct UserMenu {
 153    pub user_menu_button_online: UserMenuButton,
 154    pub user_menu_button_offline: UserMenuButton,
 155}
 156
 157#[derive(Clone, Deserialize, Default, JsonSchema)]
 158pub struct UserMenuButton {
 159    pub user_menu: Toggleable<Interactive<Icon>>,
 160    pub avatar: AvatarStyle,
 161    pub icon: Icon,
 162}
 163
 164#[derive(Copy, Clone, Deserialize, Default, JsonSchema)]
 165pub struct AvatarStyle {
 166    #[serde(flatten)]
 167    pub image: ImageStyle,
 168    pub outer_width: f32,
 169    pub outer_corner_radius: f32,
 170}
 171
 172#[derive(Deserialize, Default, Clone, JsonSchema)]
 173pub struct Copilot {
 174    pub out_link_icon: Interactive<IconStyle>,
 175    pub modal: ModalStyle,
 176    pub auth: CopilotAuth,
 177}
 178
 179#[derive(Deserialize, Default, Clone, JsonSchema)]
 180pub struct CopilotAuth {
 181    pub content_width: f32,
 182    pub prompting: CopilotAuthPrompting,
 183    pub not_authorized: CopilotAuthNotAuthorized,
 184    pub authorized: CopilotAuthAuthorized,
 185    pub cta_button: CopilotCTAButton,
 186    pub header: IconStyle,
 187}
 188
 189#[derive(Deserialize, Default, Clone, JsonSchema)]
 190pub struct CopilotAuthPrompting {
 191    pub subheading: ContainedText,
 192    pub hint: ContainedText,
 193    pub device_code: DeviceCode,
 194}
 195
 196#[derive(Deserialize, Default, Clone, JsonSchema)]
 197pub struct DeviceCode {
 198    pub text: TextStyle,
 199    pub cta: CopilotCTAButton,
 200    pub left: f32,
 201    pub left_container: ContainerStyle,
 202    pub right: f32,
 203    pub right_container: Interactive<ContainerStyle>,
 204}
 205
 206#[derive(Deserialize, Default, Clone, JsonSchema)]
 207pub struct CopilotAuthNotAuthorized {
 208    pub subheading: ContainedText,
 209    pub warning: ContainedText,
 210}
 211
 212#[derive(Deserialize, Default, Clone, JsonSchema)]
 213pub struct CopilotAuthAuthorized {
 214    pub subheading: ContainedText,
 215    pub hint: ContainedText,
 216}
 217
 218#[derive(Deserialize, Default, JsonSchema)]
 219pub struct CollabPanel {
 220    #[serde(flatten)]
 221    pub container: ContainerStyle,
 222    pub disclosure: DisclosureStyle<()>,
 223    pub list_empty_state: Toggleable<Interactive<ContainedText>>,
 224    pub list_empty_icon: Icon,
 225    pub list_empty_label_container: ContainerStyle,
 226    pub log_in_button: Interactive<ContainedText>,
 227    pub channel_editor: ContainerStyle,
 228    pub channel_hash: Icon,
 229    pub tabbed_modal: TabbedModal,
 230    pub contact_finder: ContactFinder,
 231    pub channel_modal: ChannelModal,
 232    pub user_query_editor: FieldEditor,
 233    pub user_query_editor_height: f32,
 234    pub leave_call_button: Toggleable<Interactive<IconButton>>,
 235    pub add_contact_button: Toggleable<Interactive<IconButton>>,
 236    pub add_channel_button: Toggleable<Interactive<IconButton>>,
 237    pub header_row: ContainedText,
 238    pub subheader_row: Toggleable<Interactive<ContainedText>>,
 239    pub leave_call: Interactive<ContainedText>,
 240    pub contact_row: Toggleable<Interactive<ContainerStyle>>,
 241    pub channel_row: Toggleable<Interactive<ContainerStyle>>,
 242    pub channel_name: ContainedText,
 243    pub row_height: f32,
 244    pub project_row: Toggleable<Interactive<ProjectRow>>,
 245    pub tree_branch: Toggleable<Interactive<TreeBranch>>,
 246    pub contact_avatar: ImageStyle,
 247    pub channel_avatar: ImageStyle,
 248    pub extra_participant_label: ContainedText,
 249    pub contact_status_free: ContainerStyle,
 250    pub contact_status_busy: ContainerStyle,
 251    pub contact_username: ContainedText,
 252    pub contact_button: Interactive<IconButton>,
 253    pub contact_button_spacing: f32,
 254    pub channel_indent: f32,
 255    pub disabled_button: IconButton,
 256    pub section_icon_size: f32,
 257    pub calling_indicator: ContainedText,
 258    pub face_overlap: f32,
 259}
 260
 261#[derive(Deserialize, Default, JsonSchema)]
 262pub struct ComponentTest {
 263    pub button: Interactive<ButtonStyle<TextStyle>>,
 264    pub toggle: Toggleable<Interactive<ButtonStyle<TextStyle>>>,
 265    pub disclosure: DisclosureStyle<TextStyle>,
 266}
 267
 268#[derive(Deserialize, Default, JsonSchema)]
 269pub struct TabbedModal {
 270    pub tab_button: Toggleable<Interactive<ContainedText>>,
 271    pub modal: ContainerStyle,
 272    pub header: ContainerStyle,
 273    pub body: ContainerStyle,
 274    pub title: ContainedText,
 275    pub picker: Picker,
 276    pub max_height: f32,
 277    pub max_width: f32,
 278    pub row_height: f32,
 279}
 280
 281#[derive(Deserialize, Default, JsonSchema)]
 282pub struct ChannelModal {
 283    pub contact_avatar: ImageStyle,
 284    pub contact_username: ContainerStyle,
 285    pub remove_member_button: ContainedText,
 286    pub cancel_invite_button: ContainedText,
 287    pub member_icon: IconButton,
 288    pub invitee_icon: IconButton,
 289    pub member_tag: ContainedText,
 290}
 291
 292#[derive(Deserialize, Default, JsonSchema)]
 293pub struct ProjectRow {
 294    #[serde(flatten)]
 295    pub container: ContainerStyle,
 296    pub icon: Icon,
 297    pub name: ContainedText,
 298}
 299
 300#[derive(Deserialize, Default, Clone, Copy, JsonSchema)]
 301pub struct TreeBranch {
 302    pub width: f32,
 303    pub color: Color,
 304}
 305
 306#[derive(Deserialize, Default, JsonSchema)]
 307pub struct ContactFinder {
 308    pub contact_avatar: ImageStyle,
 309    pub contact_username: ContainerStyle,
 310    pub contact_button: IconButton,
 311    pub disabled_contact_button: IconButton,
 312}
 313
 314#[derive(Deserialize, Default, JsonSchema)]
 315pub struct DropdownMenu {
 316    #[serde(flatten)]
 317    pub container: ContainerStyle,
 318    pub header: Interactive<DropdownMenuItem>,
 319    pub section_header: ContainedText,
 320    pub item: Toggleable<Interactive<DropdownMenuItem>>,
 321    pub row_height: f32,
 322}
 323
 324#[derive(Deserialize, Default, JsonSchema)]
 325pub struct DropdownMenuItem {
 326    #[serde(flatten)]
 327    pub container: ContainerStyle,
 328    #[serde(flatten)]
 329    pub text: TextStyle,
 330    pub secondary_text: Option<TextStyle>,
 331    #[serde(default)]
 332    pub secondary_text_spacing: f32,
 333}
 334
 335#[derive(Clone, Deserialize, Default, JsonSchema)]
 336pub struct TabBar {
 337    #[serde(flatten)]
 338    pub container: ContainerStyle,
 339    pub pane_button: Toggleable<Interactive<IconButton>>,
 340    pub pane_button_container: ContainerStyle,
 341    pub active_pane: TabStyles,
 342    pub inactive_pane: TabStyles,
 343    pub dragged_tab: Tab,
 344    pub height: f32,
 345    pub nav_button: Interactive<IconButton>,
 346}
 347
 348impl TabBar {
 349    pub fn tab_style(&self, pane_active: bool, tab_active: bool) -> &Tab {
 350        let tabs = if pane_active {
 351            &self.active_pane
 352        } else {
 353            &self.inactive_pane
 354        };
 355
 356        if tab_active {
 357            &tabs.active_tab
 358        } else {
 359            &tabs.inactive_tab
 360        }
 361    }
 362}
 363
 364#[derive(Clone, Deserialize, Default, JsonSchema)]
 365pub struct TabStyles {
 366    pub active_tab: Tab,
 367    pub inactive_tab: Tab,
 368}
 369
 370#[derive(Clone, Deserialize, Default, JsonSchema)]
 371pub struct AvatarRibbon {
 372    #[serde(flatten)]
 373    pub container: ContainerStyle,
 374    pub width: f32,
 375    pub height: f32,
 376}
 377
 378#[derive(Clone, Deserialize, Default, JsonSchema)]
 379pub struct OfflineIcon {
 380    #[serde(flatten)]
 381    pub container: ContainerStyle,
 382    pub width: f32,
 383    pub color: Color,
 384}
 385
 386#[derive(Clone, Deserialize, Default, JsonSchema)]
 387pub struct Tab {
 388    pub height: f32,
 389    #[serde(flatten)]
 390    pub container: ContainerStyle,
 391    #[serde(flatten)]
 392    pub label: LabelStyle,
 393    pub description: ContainedText,
 394    pub spacing: f32,
 395    pub close_icon_width: f32,
 396    pub type_icon_width: f32,
 397    pub icon_close: Color,
 398    pub icon_close_active: Color,
 399    pub icon_dirty: Color,
 400    pub icon_conflict: Color,
 401    pub git: GitProjectStatus,
 402}
 403
 404#[derive(Clone, Deserialize, Default, JsonSchema)]
 405pub struct Toolbar {
 406    #[serde(flatten)]
 407    pub container: ContainerStyle,
 408    pub height: f32,
 409    pub item_spacing: f32,
 410    pub toggleable_tool: Toggleable<Interactive<IconButton>>,
 411    pub toggleable_text_tool: Toggleable<Interactive<ContainedText>>,
 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    pub server_name_container: ContainerStyle,
 839    pub server_name_color: Color,
 840    pub server_name_size_percent: f32,
 841}
 842
 843#[derive(Clone, Copy, Default, Deserialize, JsonSchema)]
 844pub struct SelectionStyle {
 845    pub cursor: Color,
 846    pub selection: Color,
 847}
 848
 849#[derive(Clone, Deserialize, Default, JsonSchema)]
 850pub struct FieldEditor {
 851    #[serde(flatten)]
 852    pub container: ContainerStyle,
 853    pub text: TextStyle,
 854    #[serde(default)]
 855    pub placeholder_text: Option<TextStyle>,
 856    pub selection: SelectionStyle,
 857}
 858
 859#[derive(Clone, Deserialize, Default, JsonSchema)]
 860pub struct InteractiveColor {
 861    pub color: Color,
 862}
 863
 864#[derive(Clone, Deserialize, Default, JsonSchema)]
 865pub struct CodeActions {
 866    #[serde(default)]
 867    pub indicator: Toggleable<Interactive<InteractiveColor>>,
 868    pub vertical_scale: f32,
 869}
 870
 871#[derive(Clone, Deserialize, Default, JsonSchema)]
 872pub struct Folds {
 873    pub indicator: Toggleable<Interactive<InteractiveColor>>,
 874    pub ellipses: FoldEllipses,
 875    pub fold_background: Color,
 876    pub icon_margin_scale: f32,
 877    pub folded_icon: String,
 878    pub foldable_icon: String,
 879}
 880
 881#[derive(Clone, Deserialize, Default, JsonSchema)]
 882pub struct FoldEllipses {
 883    pub text_color: Color,
 884    pub background: Interactive<InteractiveColor>,
 885    pub corner_radius_factor: f32,
 886}
 887
 888#[derive(Clone, Deserialize, Default, JsonSchema)]
 889pub struct DiffStyle {
 890    pub inserted: Color,
 891    pub modified: Color,
 892    pub deleted: Color,
 893    pub removed_width_em: f32,
 894    pub width_em: f32,
 895    pub corner_radius: f32,
 896}
 897
 898#[derive(Debug, Default, Clone, Copy, JsonSchema)]
 899pub struct Interactive<T> {
 900    pub default: T,
 901    pub hovered: Option<T>,
 902    pub clicked: Option<T>,
 903    pub disabled: Option<T>,
 904}
 905
 906impl<T> Deref for Interactive<T> {
 907    type Target = T;
 908
 909    fn deref(&self) -> &Self::Target {
 910        &self.default
 911    }
 912}
 913
 914impl Interactive<()> {
 915    pub fn new_blank() -> Self {
 916        Self {
 917            default: (),
 918            hovered: None,
 919            clicked: None,
 920            disabled: None,
 921        }
 922    }
 923}
 924
 925#[derive(Clone, Copy, Debug, Default, Deserialize, JsonSchema)]
 926pub struct Toggleable<T> {
 927    active: T,
 928    inactive: T,
 929}
 930
 931impl<T> Deref for Toggleable<T> {
 932    type Target = T;
 933
 934    fn deref(&self) -> &Self::Target {
 935        &self.inactive
 936    }
 937}
 938
 939impl Toggleable<()> {
 940    pub fn new_blank() -> Self {
 941        Self {
 942            active: (),
 943            inactive: (),
 944        }
 945    }
 946}
 947
 948impl<T> Toggleable<T> {
 949    pub fn new(active: T, inactive: T) -> Self {
 950        Self { active, inactive }
 951    }
 952    pub fn in_state(&self, active: bool) -> &T {
 953        if active {
 954            &self.active
 955        } else {
 956            &self.inactive
 957        }
 958    }
 959    pub fn active_state(&self) -> &T {
 960        self.in_state(true)
 961    }
 962
 963    pub fn inactive_state(&self) -> &T {
 964        self.in_state(false)
 965    }
 966}
 967
 968impl<T> Interactive<T> {
 969    pub fn style_for(&self, state: &mut MouseState) -> &T {
 970        if state.clicked() == Some(platform::MouseButton::Left) && self.clicked.is_some() {
 971            self.clicked.as_ref().unwrap()
 972        } else if state.hovered() {
 973            self.hovered.as_ref().unwrap_or(&self.default)
 974        } else {
 975            &self.default
 976        }
 977    }
 978    pub fn disabled_style(&self) -> &T {
 979        self.disabled.as_ref().unwrap_or(&self.default)
 980    }
 981}
 982
 983impl<T> Toggleable<Interactive<T>> {
 984    pub fn style_for(&self, active: bool, state: &mut MouseState) -> &T {
 985        self.in_state(active).style_for(state)
 986    }
 987
 988    pub fn default_style(&self) -> &T {
 989        &self.inactive.default
 990    }
 991}
 992
 993impl<'de, T: DeserializeOwned> Deserialize<'de> for Interactive<T> {
 994    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
 995    where
 996        D: serde::Deserializer<'de>,
 997    {
 998        #[derive(Deserialize)]
 999        struct Helper {
1000            default: Value,
1001            hovered: Option<Value>,
1002            clicked: Option<Value>,
1003            disabled: Option<Value>,
1004        }
1005
1006        let json = Helper::deserialize(deserializer)?;
1007
1008        let deserialize_state = |state_json: Option<Value>| -> Result<Option<T>, D::Error> {
1009            if let Some(mut state_json) = state_json {
1010                if let Value::Object(state_json) = &mut state_json {
1011                    if let Value::Object(default) = &json.default {
1012                        for (key, value) in default {
1013                            if !state_json.contains_key(key) {
1014                                state_json.insert(key.clone(), value.clone());
1015                            }
1016                        }
1017                    }
1018                }
1019                Ok(Some(
1020                    serde_json::from_value::<T>(state_json).map_err(serde::de::Error::custom)?,
1021                ))
1022            } else {
1023                Ok(None)
1024            }
1025        };
1026
1027        let hovered = deserialize_state(json.hovered)?;
1028        let clicked = deserialize_state(json.clicked)?;
1029        let disabled = deserialize_state(json.disabled)?;
1030        let default = serde_json::from_value(json.default).map_err(serde::de::Error::custom)?;
1031
1032        Ok(Interactive {
1033            default,
1034            hovered,
1035            clicked,
1036            disabled,
1037        })
1038    }
1039}
1040
1041impl Editor {
1042    pub fn replica_selection_style(&self, replica_id: u16) -> &SelectionStyle {
1043        let style_ix = replica_id as usize % (self.guest_selections.len() + 1);
1044        if style_ix == 0 {
1045            &self.selection
1046        } else {
1047            &self.guest_selections[style_ix - 1]
1048        }
1049    }
1050}
1051
1052#[derive(Default, JsonSchema)]
1053pub struct SyntaxTheme {
1054    pub highlights: Vec<(String, HighlightStyle)>,
1055}
1056
1057impl SyntaxTheme {
1058    pub fn new(highlights: Vec<(String, HighlightStyle)>) -> Self {
1059        Self { highlights }
1060    }
1061}
1062
1063impl<'de> Deserialize<'de> for SyntaxTheme {
1064    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1065    where
1066        D: serde::Deserializer<'de>,
1067    {
1068        let syntax_data: HashMap<String, HighlightStyle> = Deserialize::deserialize(deserializer)?;
1069
1070        let mut result = Self::new(Vec::new());
1071        for (key, style) in syntax_data {
1072            match result
1073                .highlights
1074                .binary_search_by(|(needle, _)| needle.cmp(&key))
1075            {
1076                Ok(i) | Err(i) => {
1077                    result.highlights.insert(i, (key, style));
1078                }
1079            }
1080        }
1081
1082        Ok(result)
1083    }
1084}
1085
1086#[derive(Clone, Deserialize, Default, JsonSchema)]
1087pub struct HoverPopover {
1088    pub container: ContainerStyle,
1089    pub info_container: ContainerStyle,
1090    pub warning_container: ContainerStyle,
1091    pub error_container: ContainerStyle,
1092    pub block_style: ContainerStyle,
1093    pub prose: TextStyle,
1094    pub diagnostic_source_highlight: HighlightStyle,
1095    pub highlight: Color,
1096}
1097
1098#[derive(Clone, Deserialize, Default, JsonSchema)]
1099pub struct TerminalStyle {
1100    pub black: Color,
1101    pub red: Color,
1102    pub green: Color,
1103    pub yellow: Color,
1104    pub blue: Color,
1105    pub magenta: Color,
1106    pub cyan: Color,
1107    pub white: Color,
1108    pub bright_black: Color,
1109    pub bright_red: Color,
1110    pub bright_green: Color,
1111    pub bright_yellow: Color,
1112    pub bright_blue: Color,
1113    pub bright_magenta: Color,
1114    pub bright_cyan: Color,
1115    pub bright_white: Color,
1116    pub foreground: Color,
1117    pub background: Color,
1118    pub modal_background: Color,
1119    pub cursor: Color,
1120    pub dim_black: Color,
1121    pub dim_red: Color,
1122    pub dim_green: Color,
1123    pub dim_yellow: Color,
1124    pub dim_blue: Color,
1125    pub dim_magenta: Color,
1126    pub dim_cyan: Color,
1127    pub dim_white: Color,
1128    pub bright_foreground: Color,
1129    pub dim_foreground: Color,
1130}
1131
1132#[derive(Clone, Deserialize, Default, JsonSchema)]
1133pub struct AssistantStyle {
1134    pub container: ContainerStyle,
1135    pub hamburger_button: Interactive<IconStyle>,
1136    pub split_button: Interactive<IconStyle>,
1137    pub assist_button: Interactive<IconStyle>,
1138    pub quote_button: Interactive<IconStyle>,
1139    pub zoom_in_button: Interactive<IconStyle>,
1140    pub zoom_out_button: Interactive<IconStyle>,
1141    pub plus_button: Interactive<IconStyle>,
1142    pub title: ContainedText,
1143    pub message_header: ContainerStyle,
1144    pub sent_at: ContainedText,
1145    pub user_sender: Interactive<ContainedText>,
1146    pub assistant_sender: Interactive<ContainedText>,
1147    pub system_sender: Interactive<ContainedText>,
1148    pub model: Interactive<ContainedText>,
1149    pub remaining_tokens: ContainedText,
1150    pub low_remaining_tokens: ContainedText,
1151    pub no_remaining_tokens: ContainedText,
1152    pub error_icon: Icon,
1153    pub api_key_editor: FieldEditor,
1154    pub api_key_prompt: ContainedText,
1155    pub saved_conversation: SavedConversation,
1156    pub inline: InlineAssistantStyle,
1157}
1158
1159#[derive(Clone, Deserialize, Default, JsonSchema)]
1160pub struct InlineAssistantStyle {
1161    #[serde(flatten)]
1162    pub container: ContainerStyle,
1163    pub editor: FieldEditor,
1164    pub disabled_editor: FieldEditor,
1165    pub pending_edit_background: Color,
1166    pub include_conversation: ToggleIconButtonStyle,
1167}
1168
1169#[derive(Clone, Deserialize, Default, JsonSchema)]
1170pub struct Contained<T> {
1171    container: ContainerStyle,
1172    contained: T,
1173}
1174
1175#[derive(Clone, Deserialize, Default, JsonSchema)]
1176pub struct SavedConversation {
1177    pub container: Interactive<ContainerStyle>,
1178    pub saved_at: ContainedText,
1179    pub title: ContainedText,
1180}
1181
1182#[derive(Clone, Deserialize, Default, JsonSchema)]
1183pub struct FeedbackStyle {
1184    pub submit_button: Interactive<ContainedText>,
1185    pub button_margin: f32,
1186    pub info_text_default: ContainedText,
1187    pub link_text_default: ContainedText,
1188    pub link_text_hover: ContainedText,
1189}
1190
1191#[derive(Clone, Deserialize, Default, JsonSchema)]
1192pub struct WelcomeStyle {
1193    pub page_width: f32,
1194    pub logo: SvgStyle,
1195    pub logo_subheading: ContainedText,
1196    pub usage_note: ContainedText,
1197    pub checkbox: CheckboxStyle,
1198    pub checkbox_container: ContainerStyle,
1199    pub button: Interactive<ContainedText>,
1200    pub button_group: ContainerStyle,
1201    pub heading_group: ContainerStyle,
1202    pub checkbox_group: ContainerStyle,
1203}
1204
1205#[derive(Clone, Deserialize, Default, JsonSchema)]
1206pub struct ColorScheme {
1207    pub name: String,
1208    pub is_light: bool,
1209    pub ramps: RampSet,
1210    pub lowest: Layer,
1211    pub middle: Layer,
1212    pub highest: Layer,
1213
1214    pub popover_shadow: Shadow,
1215    pub modal_shadow: Shadow,
1216
1217    pub players: Vec<Player>,
1218}
1219
1220#[derive(Clone, Deserialize, Default, JsonSchema)]
1221pub struct Player {
1222    pub cursor: Color,
1223    pub selection: Color,
1224}
1225
1226#[derive(Clone, Deserialize, Default, JsonSchema)]
1227pub struct RampSet {
1228    pub neutral: Vec<Color>,
1229    pub red: Vec<Color>,
1230    pub orange: Vec<Color>,
1231    pub yellow: Vec<Color>,
1232    pub green: Vec<Color>,
1233    pub cyan: Vec<Color>,
1234    pub blue: Vec<Color>,
1235    pub violet: Vec<Color>,
1236    pub magenta: Vec<Color>,
1237}
1238
1239#[derive(Clone, Deserialize, Default, JsonSchema)]
1240pub struct Layer {
1241    pub base: StyleSet,
1242    pub variant: StyleSet,
1243    pub on: StyleSet,
1244    pub accent: StyleSet,
1245    pub positive: StyleSet,
1246    pub warning: StyleSet,
1247    pub negative: StyleSet,
1248}
1249
1250#[derive(Clone, Deserialize, Default, JsonSchema)]
1251pub struct StyleSet {
1252    pub default: Style,
1253    pub active: Style,
1254    pub disabled: Style,
1255    pub hovered: Style,
1256    pub pressed: Style,
1257    pub inverted: Style,
1258}
1259
1260#[derive(Clone, Deserialize, Default, JsonSchema)]
1261pub struct Style {
1262    pub background: Color,
1263    pub border: Color,
1264    pub foreground: Color,
1265}