This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
GPUI Component is a UI component library for building desktop applications using GPUI. It provides 60+ cross-platform desktop UI components, inspired by macOS/Windows controls and combined with shadcn/ui design.
This is a Rust workspace project with the following main crates:
crates/ui- Core UI component library (published asgpui-component)crates/story- Gallery application for showcasing and testing componentscrates/macros- Procedural macros (IntoPlotderive)crates/assets- Static assetscrates/webview- WebView component supportexamples/- Various example applications
# Run Story Gallery (component showcase application)
cargo run
# Run individual examples
cargo run --example hello_world
cargo run --example table
# Build the project
cargo build
# Lint check
cargo clippy -- --deny warnings
# Format check
cargo fmt --check
# Spell check
typos
# Check for unused dependencies
cargo macheteNote: Per user configuration, tests do not need to be run.
# Run all tests
cargo test --all
# Run tests for a specific crate
cargo test -p gpui-component
# Run doc tests
cargo test -p gpui-component --doc# View FPS on macOS (using Metal HUD)
MTL_HUD_ENABLED=1 cargo run
# Profile performance using samply
samply record cargo runCritical requirement: You must call gpui_component::init(cx) at your application's entry point before using any GPUI Component features.
fn main() {
let app = Application::new();
app.run(move |cx| {
// This must be called first
gpui_component::init(cx);
cx.spawn(async move |cx| {
cx.open_window(WindowOptions::default(), |window, cx| {
let view = cx.new(|_| MyView);
// The first level view in a window must be a Root
cx.new(|cx| Root::new(view, window, cx))
})?;
Ok::<_, anyhow::Error>(())
}).detach();
});
}Root is the top-level view for a window and manages:
- Sheet (side panels)
- Dialog (dialogs)
- Notification (notifications)
- Keyboard navigation (Tab/Shift-Tab)
The first view of every window must be a Root.
- Uses
Themeglobal singleton for theme configuration - Supports light/dark mode switching
- Access theme via
ActiveThemetrait:cx.theme() - Theme configuration includes:
- Colors (
ThemeColor) - Syntax highlighting theme (
HighlightTheme) - Font configuration (system font and monospace font)
- UI parameters like border radius, shadows
- Scrollbar display mode
- Colors (
A complex panel layout system supporting:
- DockArea: Main container managing center area and left/bottom/right docks
- DockItem: Tree-based layout structure
Split: Split layout (horizontal/vertical)Tabs: Tab layoutPanel: Individual panel
- Panel: Defined via
PanelViewtrait - PanelRegistry: Global panel registry for serializing/deserializing layouts
- StackPanel: Resizable split panel container
- TabPanel: Tab panel container
The Dock system supports:
- Panel drag-and-drop reordering
- Panel zoom
- Layout locking
- Layout serialization/restoration
Text input system based on Rope data structure:
- InputState: Input state management
- Rope: Efficient text storage (from ropey crate)
- LSP integration support (diagnostics, completion, hover)
- Syntax highlighting support (Tree-sitter)
- Multiple input modes:
- Regular input (
Input) - Number input (
NumberInput) - OTP input (
OtpInput)
- Regular input (
- Stateless design: Use
RenderOncetrait, components should be stateless when possible - Size system: Supports
xs,sm,md(default),lgsizes viaSizabletrait. - Mouse cursor: Buttons use
defaultcursor notpointer(desktop app convention), unless it's a link button - Style system: Provides CSS-like styling API via
Styledtrait andElementExtextensions
- Follow naming and organization patterns from existing code
- Reference macOS/Windows control API design for naming
- AI-generated code must be refactored to match project style
- Mark AI-generated portions when submitting PRs
The Icon element does not include SVG files by default. You need to:
- Use Lucide or other icon libraries
- Name SVG files according to the
IconNameenum definition (located incrates/ui/src/icon.rs)
- GPUI: Git version from Zed repository
- Tree-sitter: For syntax highlighting
- Ropey: Rope data structure for text, and
RopeExttrait with more features. - Markdown rendering:
markdowncrate - HTML rendering:
html5ever(basic support) - Charts: Built-in chart components
- LSP:
lsp-typescrate
Uses rust-i18n crate.
- Localization files are located in
crates/ui/locales/. - Only add
en,zh-CN,zh-HKby default.
- macOS (aarch64, x86_64)
- Linux (x86_64)
- Windows (x86_64)
CI runs full test suite on each platform.
This project has custom Claude Code skills in .claude/skills/ to assist with common development tasks:
- new-component - Creating new GPUI components with proper structure and patterns
- generate-component-story - Creating story examples for components in the gallery
- generate-component-documentation - Generating documentation for components
- gpui-action - Working with actions and keyboard shortcuts
- gpui-async - Async operations and background tasks
- gpui-context - Context management (App, Window, AsyncApp)
- gpui-element - Implementing custom elements using low-level Element API
- gpui-entity - Entity management and state handling
- gpui-event - Event handling and subscriptions
- gpui-focus-handle - Focus management and keyboard navigation
- gpui-global - Global state management
- gpui-layout-and-style - Layout and styling systems
- gpui-test - Writing tests for GPUI applications
- github-pull-request-description - Writing PR descriptions
When working on tasks related to these areas, Claude Code will automatically use the appropriate skill to provide specialized guidance and patterns.
See .claude/COMPONENT_TEST_RULES.md for detailed testing principles:
- Simplicity First: Focus on complex logic and core functionality, avoid excessive simple tests
- Builder Pattern Testing: Every component should have a
test_*_buildertest covering the builder pattern - Complex Logic Testing: Test conditional branching, state transitions, and edge cases