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 breadcrumb_height: f32,
  92    pub breadcrumbs: Interactive<ContainedText>,
  93    pub disconnected_overlay: ContainedText,
  94    pub modal: ContainerStyle,
  95    pub zoomed_panel_foreground: ContainerStyle,
  96    pub zoomed_pane_foreground: ContainerStyle,
  97    pub zoomed_background: ContainerStyle,
  98    pub notification: ContainerStyle,
  99    pub notifications: Notifications,
 100    pub joining_project_avatar: ImageStyle,
 101    pub joining_project_message: ContainedText,
 102    pub external_location_message: ContainedText,
 103    pub drop_target_overlay_color: Color,
 104}
 105
 106#[derive(Clone, Deserialize, Default, JsonSchema)]
 107pub struct BlankPaneStyle {
 108    pub logo: SvgStyle,
 109    pub logo_shadow: SvgStyle,
 110    pub logo_container: ContainerStyle,
 111    pub keyboard_hints: ContainerStyle,
 112    pub keyboard_hint: Interactive<ContainedText>,
 113    pub keyboard_hint_width: f32,
 114}
 115
 116#[derive(Clone, Deserialize, Default, JsonSchema)]
 117pub struct Titlebar {
 118    #[serde(flatten)]
 119    pub container: ContainerStyle,
 120    pub height: f32,
 121    pub menu: TitlebarMenu,
 122    pub project_menu_button: Toggleable<Interactive<ContainedText>>,
 123    pub project_name_divider: ContainedText,
 124    pub git_menu_button: Toggleable<Interactive<ContainedText>>,
 125    pub item_spacing: f32,
 126    pub face_pile_spacing: f32,
 127    pub avatar_ribbon: AvatarRibbon,
 128    pub follower_avatar_overlap: f32,
 129    pub leader_selection: ContainerStyle,
 130    pub offline_icon: OfflineIcon,
 131    pub leader_avatar: AvatarStyle,
 132    pub follower_avatar: AvatarStyle,
 133    pub inactive_avatar_grayscale: bool,
 134    pub sign_in_button: Toggleable<Interactive<ContainedText>>,
 135    pub outdated_warning: ContainedText,
 136    pub share_button: Toggleable<Interactive<ContainedText>>,
 137    pub muted: Color,
 138    pub speaking: Color,
 139    pub screen_share_button: Toggleable<Interactive<IconButton>>,
 140    pub toggle_contacts_button: Toggleable<Interactive<IconButton>>,
 141    pub toggle_microphone_button: Toggleable<Interactive<IconButton>>,
 142    pub toggle_speakers_button: Toggleable<Interactive<IconButton>>,
 143    pub leave_call_button: Interactive<IconButton>,
 144    pub toggle_contacts_badge: ContainerStyle,
 145    pub user_menu: UserMenu,
 146}
 147
 148#[derive(Clone, Deserialize, Default, JsonSchema)]
 149pub struct TitlebarMenu {
 150    pub width: f32,
 151    pub height: f32,
 152}
 153
 154#[derive(Clone, Deserialize, Default, JsonSchema)]
 155pub struct UserMenu {
 156    pub user_menu_button_online: UserMenuButton,
 157    pub user_menu_button_offline: UserMenuButton,
 158}
 159
 160#[derive(Clone, Deserialize, Default, JsonSchema)]
 161pub struct UserMenuButton {
 162    pub user_menu: Toggleable<Interactive<Icon>>,
 163    pub avatar: AvatarStyle,
 164    pub icon: Icon,
 165}
 166
 167#[derive(Copy, Clone, Deserialize, Default, JsonSchema)]
 168pub struct AvatarStyle {
 169    #[serde(flatten)]
 170    pub image: ImageStyle,
 171    pub outer_width: f32,
 172    pub outer_corner_radius: f32,
 173}
 174
 175#[derive(Deserialize, Default, Clone, JsonSchema)]
 176pub struct Copilot {
 177    pub out_link_icon: Interactive<IconStyle>,
 178    pub modal: ModalStyle,
 179    pub auth: CopilotAuth,
 180}
 181
 182#[derive(Deserialize, Default, Clone, JsonSchema)]
 183pub struct CopilotAuth {
 184    pub content_width: f32,
 185    pub prompting: CopilotAuthPrompting,
 186    pub not_authorized: CopilotAuthNotAuthorized,
 187    pub authorized: CopilotAuthAuthorized,
 188    pub cta_button: CopilotCTAButton,
 189    pub header: IconStyle,
 190}
 191
 192#[derive(Deserialize, Default, Clone, JsonSchema)]
 193pub struct CopilotAuthPrompting {
 194    pub subheading: ContainedText,
 195    pub hint: ContainedText,
 196    pub device_code: DeviceCode,
 197}
 198
 199#[derive(Deserialize, Default, Clone, JsonSchema)]
 200pub struct DeviceCode {
 201    pub text: TextStyle,
 202    pub cta: CopilotCTAButton,
 203    pub left: f32,
 204    pub left_container: ContainerStyle,
 205    pub right: f32,
 206    pub right_container: Interactive<ContainerStyle>,
 207}
 208
 209#[derive(Deserialize, Default, Clone, JsonSchema)]
 210pub struct CopilotAuthNotAuthorized {
 211    pub subheading: ContainedText,
 212    pub warning: ContainedText,
 213}
 214
 215#[derive(Deserialize, Default, Clone, JsonSchema)]
 216pub struct CopilotAuthAuthorized {
 217    pub subheading: ContainedText,
 218    pub hint: ContainedText,
 219}
 220
 221#[derive(Deserialize, Default, JsonSchema)]
 222pub struct CollabPanel {
 223    #[serde(flatten)]
 224    pub container: ContainerStyle,
 225    pub disclosure: DisclosureStyle<()>,
 226    pub list_empty_state: Toggleable<Interactive<ContainedText>>,
 227    pub list_empty_icon: Icon,
 228    pub list_empty_label_container: ContainerStyle,
 229    pub log_in_button: Interactive<ContainedText>,
 230    pub channel_editor: ContainerStyle,
 231    pub channel_hash: Icon,
 232    pub tabbed_modal: TabbedModal,
 233    pub contact_finder: ContactFinder,
 234    pub channel_modal: ChannelModal,
 235    pub user_query_editor: FieldEditor,
 236    pub user_query_editor_height: f32,
 237    pub leave_call_button: Toggleable<Interactive<IconButton>>,
 238    pub add_contact_button: Toggleable<Interactive<IconButton>>,
 239    pub add_channel_button: Toggleable<Interactive<IconButton>>,
 240    pub header_row: ContainedText,
 241    pub subheader_row: Toggleable<Interactive<ContainedText>>,
 242    pub leave_call: Interactive<ContainedText>,
 243    pub contact_row: Toggleable<Interactive<ContainerStyle>>,
 244    pub channel_row: Toggleable<Interactive<ContainerStyle>>,
 245    pub channel_name: ContainedText,
 246    pub row_height: f32,
 247    pub project_row: Toggleable<Interactive<ProjectRow>>,
 248    pub tree_branch: Toggleable<Interactive<TreeBranch>>,
 249    pub contact_avatar: ImageStyle,
 250    pub channel_avatar: ImageStyle,
 251    pub extra_participant_label: ContainedText,
 252    pub contact_status_free: ContainerStyle,
 253    pub contact_status_busy: ContainerStyle,
 254    pub contact_username: ContainedText,
 255    pub contact_button: Interactive<IconButton>,
 256    pub contact_button_spacing: f32,
 257    pub channel_indent: f32,
 258    pub disabled_button: IconButton,
 259    pub section_icon_size: f32,
 260    pub calling_indicator: ContainedText,
 261    pub face_overlap: f32,
 262}
 263
 264#[derive(Deserialize, Default, JsonSchema)]
 265pub struct ComponentTest {
 266    pub button: Interactive<ButtonStyle<TextStyle>>,
 267    pub toggle: Toggleable<Interactive<ButtonStyle<TextStyle>>>,
 268    pub disclosure: DisclosureStyle<TextStyle>,
 269}
 270
 271#[derive(Deserialize, Default, JsonSchema)]
 272pub struct TabbedModal {
 273    pub tab_button: Toggleable<Interactive<ContainedText>>,
 274    pub modal: ContainerStyle,
 275    pub header: ContainerStyle,
 276    pub body: ContainerStyle,
 277    pub title: ContainedText,
 278    pub picker: Picker,
 279    pub max_height: f32,
 280    pub max_width: f32,
 281    pub row_height: f32,
 282}
 283
 284#[derive(Deserialize, Default, JsonSchema)]
 285pub struct ChannelModal {
 286    pub contact_avatar: ImageStyle,
 287    pub contact_username: ContainerStyle,
 288    pub remove_member_button: ContainedText,
 289    pub cancel_invite_button: ContainedText,
 290    pub member_icon: IconButton,
 291    pub invitee_icon: IconButton,
 292    pub member_tag: ContainedText,
 293}
 294
 295#[derive(Deserialize, Default, JsonSchema)]
 296pub struct ProjectRow {
 297    #[serde(flatten)]
 298    pub container: ContainerStyle,
 299    pub icon: Icon,
 300    pub name: ContainedText,
 301}
 302
 303#[derive(Deserialize, Default, Clone, Copy, JsonSchema)]
 304pub struct TreeBranch {
 305    pub width: f32,
 306    pub color: Color,
 307}
 308
 309#[derive(Deserialize, Default, JsonSchema)]
 310pub struct ContactFinder {
 311    pub contact_avatar: ImageStyle,
 312    pub contact_username: ContainerStyle,
 313    pub contact_button: IconButton,
 314    pub disabled_contact_button: IconButton,
 315}
 316
 317#[derive(Deserialize, Default, JsonSchema)]
 318pub struct DropdownMenu {
 319    #[serde(flatten)]
 320    pub container: ContainerStyle,
 321    pub header: Interactive<DropdownMenuItem>,
 322    pub section_header: ContainedText,
 323    pub item: Toggleable<Interactive<DropdownMenuItem>>,
 324    pub row_height: f32,
 325}
 326
 327#[derive(Deserialize, Default, JsonSchema)]
 328pub struct DropdownMenuItem {
 329    #[serde(flatten)]
 330    pub container: ContainerStyle,
 331    #[serde(flatten)]
 332    pub text: TextStyle,
 333    pub secondary_text: Option<TextStyle>,
 334    #[serde(default)]
 335    pub secondary_text_spacing: f32,
 336}
 337
 338#[derive(Clone, Deserialize, Default, JsonSchema)]
 339pub struct TabBar {
 340    #[serde(flatten)]
 341    pub container: ContainerStyle,
 342    pub pane_button: Toggleable<Interactive<IconButton>>,
 343    pub pane_button_container: ContainerStyle,
 344    pub active_pane: TabStyles,
 345    pub inactive_pane: TabStyles,
 346    pub dragged_tab: Tab,
 347    pub height: f32,
 348    pub nav_button: Interactive<IconButton>,
 349}
 350
 351impl TabBar {
 352    pub fn tab_style(&self, pane_active: bool, tab_active: bool) -> &Tab {
 353        let tabs = if pane_active {
 354            &self.active_pane
 355        } else {
 356            &self.inactive_pane
 357        };
 358
 359        if tab_active {
 360            &tabs.active_tab
 361        } else {
 362            &tabs.inactive_tab
 363        }
 364    }
 365}
 366
 367#[derive(Clone, Deserialize, Default, JsonSchema)]
 368pub struct TabStyles {
 369    pub active_tab: Tab,
 370    pub inactive_tab: Tab,
 371}
 372
 373#[derive(Clone, Deserialize, Default, JsonSchema)]
 374pub struct AvatarRibbon {
 375    #[serde(flatten)]
 376    pub container: ContainerStyle,
 377    pub width: f32,
 378    pub height: f32,
 379}
 380
 381#[derive(Clone, Deserialize, Default, JsonSchema)]
 382pub struct OfflineIcon {
 383    #[serde(flatten)]
 384    pub container: ContainerStyle,
 385    pub width: f32,
 386    pub color: Color,
 387}
 388
 389#[derive(Clone, Deserialize, Default, JsonSchema)]
 390pub struct Tab {
 391    pub height: f32,
 392    #[serde(flatten)]
 393    pub container: ContainerStyle,
 394    #[serde(flatten)]
 395    pub label: LabelStyle,
 396    pub description: ContainedText,
 397    pub spacing: f32,
 398    pub close_icon_width: f32,
 399    pub type_icon_width: f32,
 400    pub icon_close: Color,
 401    pub icon_close_active: Color,
 402    pub icon_dirty: Color,
 403    pub icon_conflict: Color,
 404    pub git: GitProjectStatus,
 405}
 406
 407#[derive(Clone, Deserialize, Default, JsonSchema)]
 408pub struct Toolbar {
 409    #[serde(flatten)]
 410    pub container: ContainerStyle,
 411    pub height: f32,
 412    pub item_spacing: f32,
 413    pub toggleable_tool: Toggleable<Interactive<IconButton>>,
 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 dismiss_button: Interactive<IconButton>,
 441    pub editor_icon: IconStyle,
 442    pub mode_button: Toggleable<Interactive<ContainedText>>,
 443    pub nav_button: Toggleable<Interactive<ContainedLabel>>,
 444    pub search_bar_row_height: 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    pub inline: InlineAssistantStyle,
1154}
1155
1156#[derive(Clone, Deserialize, Default, JsonSchema)]
1157pub struct InlineAssistantStyle {
1158    #[serde(flatten)]
1159    pub container: ContainerStyle,
1160    pub editor: FieldEditor,
1161    pub disabled_editor: FieldEditor,
1162    pub pending_edit_background: Color,
1163    pub include_conversation: ToggleIconButtonStyle,
1164}
1165
1166#[derive(Clone, Deserialize, Default, JsonSchema)]
1167pub struct Contained<T> {
1168    container: ContainerStyle,
1169    contained: T,
1170}
1171
1172#[derive(Clone, Deserialize, Default, JsonSchema)]
1173pub struct SavedConversation {
1174    pub container: Interactive<ContainerStyle>,
1175    pub saved_at: ContainedText,
1176    pub title: ContainedText,
1177}
1178
1179#[derive(Clone, Deserialize, Default, JsonSchema)]
1180pub struct FeedbackStyle {
1181    pub submit_button: Interactive<ContainedText>,
1182    pub button_margin: f32,
1183    pub info_text_default: ContainedText,
1184    pub link_text_default: ContainedText,
1185    pub link_text_hover: ContainedText,
1186}
1187
1188#[derive(Clone, Deserialize, Default, JsonSchema)]
1189pub struct WelcomeStyle {
1190    pub page_width: f32,
1191    pub logo: SvgStyle,
1192    pub logo_subheading: ContainedText,
1193    pub usage_note: ContainedText,
1194    pub checkbox: CheckboxStyle,
1195    pub checkbox_container: ContainerStyle,
1196    pub button: Interactive<ContainedText>,
1197    pub button_group: ContainerStyle,
1198    pub heading_group: ContainerStyle,
1199    pub checkbox_group: ContainerStyle,
1200}
1201
1202#[derive(Clone, Deserialize, Default, JsonSchema)]
1203pub struct ColorScheme {
1204    pub name: String,
1205    pub is_light: bool,
1206    pub ramps: RampSet,
1207    pub lowest: Layer,
1208    pub middle: Layer,
1209    pub highest: Layer,
1210
1211    pub popover_shadow: Shadow,
1212    pub modal_shadow: Shadow,
1213
1214    pub players: Vec<Player>,
1215}
1216
1217#[derive(Clone, Deserialize, Default, JsonSchema)]
1218pub struct Player {
1219    pub cursor: Color,
1220    pub selection: Color,
1221}
1222
1223#[derive(Clone, Deserialize, Default, JsonSchema)]
1224pub struct RampSet {
1225    pub neutral: Vec<Color>,
1226    pub red: Vec<Color>,
1227    pub orange: Vec<Color>,
1228    pub yellow: Vec<Color>,
1229    pub green: Vec<Color>,
1230    pub cyan: Vec<Color>,
1231    pub blue: Vec<Color>,
1232    pub violet: Vec<Color>,
1233    pub magenta: Vec<Color>,
1234}
1235
1236#[derive(Clone, Deserialize, Default, JsonSchema)]
1237pub struct Layer {
1238    pub base: StyleSet,
1239    pub variant: StyleSet,
1240    pub on: StyleSet,
1241    pub accent: StyleSet,
1242    pub positive: StyleSet,
1243    pub warning: StyleSet,
1244    pub negative: StyleSet,
1245}
1246
1247#[derive(Clone, Deserialize, Default, JsonSchema)]
1248pub struct StyleSet {
1249    pub default: Style,
1250    pub active: Style,
1251    pub disabled: Style,
1252    pub hovered: Style,
1253    pub pressed: Style,
1254    pub inverted: Style,
1255}
1256
1257#[derive(Clone, Deserialize, Default, JsonSchema)]
1258pub struct Style {
1259    pub background: Color,
1260    pub border: Color,
1261    pub foreground: Color,
1262}