gpui-kit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGPUI Kit
GPUI Kit
Applications depend on one crate, . GPUI is , and
each layer is reachable by name: (styled components),
(unstyled behavior), (default icons),
.
gpui-kituse gpui_kit::*;gpui_kit::componentgpui_kit::basegpui_kit::assetsgpui_kit::platform应用程序仅依赖一个crate:。GPUI可通过引入,各层级可通过名称直接访问:(带样式的组件)、(无样式的行为逻辑)、(默认图标)、(平台相关模块)。
gpui-kituse gpui_kit::*;gpui_kit::componentgpui_kit::basegpui_kit::assetsgpui_kit::platformRead the Guides First
先阅读指南
Two guides hold the rules this skill assumes. They are requirements, not
inspiration. Read the guide file itself; do not answer from this page, from a
similar file in the codebase, or from training data.
| Guide | Read before |
|---|---|
Design Guides, skill | Choosing components, layout, spacing, hierarchy, color, density, interaction states, overlays, motion, interface copy |
| Coding Guides | Crate layering, |
Read the Design Guides first when the change has a visible surface: code
structure preserves product intent, it does not replace it. If the design
skill is not installed, fetch .
The coding guide is a verbatim copy of ,
so its links to and mean the design
skill and .
https://gpui-kit.com/docs/design-guides.mdhttps://gpui-kit.com/docs/coding-guides.md./design-guides.md./getting-started.mdhttps://gpui-kit.com/docs/getting-started.md本技能基于两份指南中的规则,这些规则是硬性要求而非参考建议。请直接阅读指南文件本身,不要基于本页面、代码库中类似文件或训练数据作答。
| 指南 | 阅读时机 |
|---|---|
设计指南(对应技能 | 选择组件、布局、间距、层级、颜色、密度、交互状态、覆盖层、动效、界面文案前 |
| 编码指南 | 进行 crate 分层设计、 |
当修改涉及可见界面时,请先阅读设计指南:代码结构是为了实现产品设计意图,而非替代它。若未安装设计技能,可获取。编码指南是的完整副本,因此其中指向和的链接分别对应设计技能和。
https://gpui-kit.com/docs/design-guides.mdhttps://gpui-kit.com/docs/coding-guides.md./design-guides.md./getting-started.mdhttps://gpui-kit.com/docs/getting-started.mdCoding Guides section map
编码指南章节概览
Read the whole guide for a new crate, module, or feature. For a narrow change,
read "Architecture at a glance" and "Rules for coding agents" first, then the
section for the change ().
grep -n '^## ' references/coding-guides.md| Section | Read when |
|---|---|
| Architecture at a glance | Always; crate layering, ownership boundary |
| Bootstrap and root ownership | |
| Understand GPUI's phases and contexts | Anything touching |
| Choose the right unit | Deciding |
| State ownership | Where a piece of state lives, who mutates it, |
| Stable identity | |
| Rendering and composition | |
| Behavior and presentation boundary | |
| Theme and styling | |
| Events, actions, and focus | |
| Async work and side effects | |
| Layout, measurement, and scrolling | Flex layout, sizing, |
| Lists, tables, and large data | |
| Public API design | Anything |
| Platform and capability boundaries | macOS/Windows/Linux/wasm differences, feature gates |
| File and naming conventions | New files, modules, type and method names, |
| Testing strategy | What to test, |
| Performance rules | Render cost, allocation, re-render triggers |
| Common failure modes | Before finishing; invented APIs, state in render, index ids |
| Rules for coding agents | Always when an agent writes code |
| Implementation checklist | Before finishing; run every item against the work |
若要创建新的crate、模块或功能,请通读完整指南。若仅进行局部修改,请先阅读「架构概览」和「编码代理规则」,再阅读与修改相关的章节(可通过查找)。
grep -n '^## ' references/coding-guides.md| 章节 | 阅读时机 |
|---|---|
| 架构概览 | 任何场景;crate分层、所有权边界 |
| 启动流程与根所有权 | |
| 理解GPUI的阶段与上下文 | 涉及 |
| 选择合适的单元 | 决定使用 |
| 状态所有权 | 确定状态存储位置、修改权限、 |
| 稳定标识 | |
| 渲染与组合 | |
| 行为与展示边界 | |
| 主题与样式 | |
| 事件、动作与焦点 | |
| 异步工作与副作用 | |
| 布局、测量与滚动 | Flex布局、尺寸设置、 |
| 列表、表格与大数据 | |
| 公共API设计 | 任何 |
| 平台与能力边界 | macOS/Windows/Linux/wasm差异、特性门控相关开发 |
| 文件与命名规范 | 创建新文件、模块、类型与方法名称、 |
| 测试策略 | 测试内容、 |
| 性能规则 | 渲染成本、内存分配、重渲染触发条件相关优化 |
| 常见失败模式 | 完成开发前;避免自创API、在渲染中存储状态、使用索引作为ID |
| 编码代理规则 | 当代理编写代码时必须遵守 |
| 实现检查清单 | 完成开发前;对照清单检查所有工作内容 |
Non-negotiables
不可协商规则
A floor, not a substitute for the guides.
- Never invent an API. Search the current source for the real signature. Do not translate a React, CSS, or older-GPUI example by analogy; a plausible-looking method that does not exist is the most common failure.
- One dependency. Applications depend on alone. GPUI is
gpui-kit; the layers areuse gpui_kit::*;,gpui_kit::component,gpui_kit::base,gpui_kit::assets.gpui_kit::platform - Framework owns behavior, application owns presentation. Do not put
colors, sizing, or layout in ; do not put interaction behavior in application styling code.
gpui-base - Stable identity. Repeated elements need domain-derived s, not list indexes.
ElementId - No fields across the seam. Public data types use builders and reader methods.
pub - Spell out.
Contextis GPUI's; name anything else after what it holds.cx
这些是最低要求,不能替代完整指南。
- 禁止自创API:在现有源码中查找真实的方法签名。不要通过类比React、CSS或旧版GPUI示例来编写代码;看似合理但实际不存在的方法是最常见的错误。
- 单一依赖:应用程序仅依赖。GPUI通过
gpui-kit引入;各层级为use gpui_kit::*;、gpui_kit::component、gpui_kit::base、gpui_kit::assets。gpui_kit::platform - 框架负责行为,应用负责展示:不要在中添加颜色、尺寸或布局代码;不要在应用样式代码中添加交互行为逻辑。
gpui-base - 稳定标识:重复元素需要基于业务领域生成的,而非列表索引。
ElementId - 跨边界无字段:公共数据类型需使用构建器和读取器方法。
pub - 需完整拼写:
Context是GPUI专用的缩写;其他上下文需根据其存储内容命名。cx
Documentation
文档
- Full reference: fetch
https://gpui-kit.com/llms-full.txt - Per-component API: fetch , e.g.
https://gpui-kit.com/docs/components/{name}.md,button.md,input.md,select.md,dialog.mddata-table.md - Any site page can be fetched as Markdown by appending to the URL
.md
- 完整参考文档:获取
https://gpui-kit.com/llms-full.txt - 组件API文档:获取,例如
https://gpui-kit.com/docs/components/{name}.md、button.md、input.md、select.md、dialog.mddata-table.md - 网站任意页面:在URL后添加即可获取对应Markdown格式文档
.md
Quick Reference
快速参考
Setup and examples: references/usage.md.
rust
use gpui_kit::*;
use gpui_kit::component::Root;
gpui_kit::application()
.with_assets(gpui_kit::assets::Assets)
.run(|cx| {
gpui_kit::init(cx); // first, before anything else
// ... open_window(..., |window, cx| cx.new(|cx| Root::new(view, window, cx)))
});- Stateless (): build in
RenderOnce:renderButton::new("save").primary().label("Save").on_click(|_, _, _| {}) - Stateful: hold in the view, pass a reference in
Entity<State>:renderthenlet input = cx.new(|cx| InputState::new(window, cx));Input::new(&self.input) - Sizes:
.xsmall().small()(default).medium().large() - Theme: ·
cx.theme().primary·.background·.foreground·.border.muted - Overlays: ,
window.open_dialog(...),open_sheet(...)viapush_notification(...)gpui_kit::component::WindowExt
搭建示例与用法:references/usage.md。
rust
use gpui_kit::*;
use gpui_kit::component::Root;
gpui_kit::application()
.with_assets(gpui_kit::assets::Assets)
.run(|cx| {
gpui_kit::init(cx); // 首先执行,其他操作之前
// ... open_window(..., |window, cx| cx.new(|cx| Root::new(view, window, cx)))
});- 无状态组件():在
RenderOnce中构建:renderButton::new("save").primary().label("Save").on_click(|_, _, _| {}) - 有状态组件:在视图中持有,在
Entity<State>中传入引用:render然后使用let input = cx.new(|cx| InputState::new(window, cx));Input::new(&self.input) - 尺寸选项:
.xsmall().small()(默认).medium().large() - 主题访问:·
cx.theme().primary·.background·.foreground·.border.muted - 覆盖层:通过调用
gpui_kit::component::WindowExt、window.open_dialog(...)、open_sheet(...)push_notification(...)
Component Catalog
组件目录
Import paths are relative to , so
means . For the full API
fetch the component's doc.
gpui_kit::component::input::{Input, InputState}use gpui_kit::component::input::{Input, InputState};.md导入路径基于,因此表示。如需完整API,请获取对应组件的文档。
gpui_kit::component::input::{Input, InputState}use gpui_kit::component::input::{Input, InputState};.mdInput & Form
输入与表单
| Component | Import | Notes |
|---|---|---|
| | Stateful. Text, password, mask, validation |
| | Stateful. Multi-line text |
| | Stateful. Code editor, |
| | Stateful. Numeric with step |
| | Stateful. One-time password |
| | Stateful. Dropdown picker |
| | Stateful. Searchable select |
| | Stateless. |
| | Stateless. Toggle |
| | Stateless. |
| | Stateful. |
| | Stateless. |
| | Stateless. |
| | Stateless. Multi-step progress |
| | Stateful. |
| | Stateful. |
| | Stateful. Inline month view |
| | Layout container for form fields |
| 组件 | 导入路径 | 说明 |
|---|---|---|
| | 有状态。支持文本、密码、掩码、验证 |
| | 有状态。多行文本输入 |
| | 有状态。代码编辑器,支持 |
| | 有状态。带步长的数值输入 |
| | 有状态。一次性密码输入 |
| | 有状态。下拉选择器 |
| | 有状态。可搜索的选择器 |
| | 无状态。 |
| | 无状态。开关组件 |
| | 无状态。单选按钮 |
| | 有状态。滑块组件 |
| | 无状态。切换按钮 |
| | 无状态。评分组件 |
| | 无状态。多步骤进度组件 |
| | 有状态。颜色选择器 |
| | 有状态。日期选择器 |
| | 有状态。内联月历视图 |
| | 表单字段的布局容器 |
Display & Feedback
展示与反馈
| Component | Import | Notes |
|---|---|---|
| | Stateless. Primary UI action |
| | Stateless. Lucide icons |
| | Stateless. |
| | Stateless. Closable tags |
| | Stateless. |
| | Stateless. Form label |
| | Stateless. Keyboard key display |
| | Stateless. Info/success/warning/error |
| | Stateless. Loading indicator |
| | Stateless. Loading placeholder |
| | Stateless. Streaming-text shimmer |
| | Stateless. Inline status marker |
| | Stateless. |
| | Via |
| | Stateful. |
| | Stateless. Copy button |
| | |
| Image | | GPUI's |
| 组件 | 导入路径 | 说明 |
|---|---|---|
| | 无状态。主要UI操作按钮 |
| | 无状态。Lucide图标库 |
| | 无状态。徽章组件 |
| | 无状态。可关闭标签 |
| | 无状态。头像组件 |
| | 无状态。表单标签 |
| | 无状态。键盘按键展示 |
| | 无状态。信息/成功/警告/错误提示 |
| | 无状态。加载指示器 |
| | 无状态。加载占位符 |
| | 无状态。流式文本闪烁效果 |
| | 无状态。行内状态标记 |
| | 无状态。进度条/圆形进度组件 |
| | 通过元素的 |
| | 有状态。悬停卡片 |
| | 无状态。复制按钮 |
| | 支持 |
| Image | | GPUI的 |
Overlay & Popups
覆盖层与弹窗
| Component | Import | Notes |
|---|---|---|
| | Via |
| | Via |
| | Side panel, via |
| | Via |
| | Floating overlay |
| | Context menus |
| | Button with dropdown menu |
| | Stateful. Command palette |
| Focus trap | | |
| 组件 | 导入路径 | 说明 |
|---|---|---|
| | 通过 |
| | 通过 |
| | 侧边面板,通过 |
| | 通过 |
| | 浮动覆盖层 |
| | 上下文菜单 |
| | 带下拉菜单的按钮 |
| | 有状态。命令面板 |
| Focus trap | | 在容器上调用 |
Navigation & Layout
导航与布局
| Component | Import | Notes |
|---|---|---|
| | Tabbed interface |
| | App navigation panel |
| | Window title bar |
| | Window status bar |
| | Navigation breadcrumb |
| | Page navigation |
| | Collapsible sections |
| | Single collapsible |
| | Labeled container |
| | Draggable split panes |
| | Custom scrollbar |
| 组件 | 导入路径 | 说明 |
|---|---|---|
| | 标签页界面 |
| | 应用导航面板 |
| | 窗口标题栏 |
| | 窗口状态栏 |
| | 导航面包屑 |
| | 分页导航 |
| | 可折叠区域 |
| | 单个可折叠组件 |
| | 带标签的容器 |
| | 可拖拽拆分面板 |
| | 自定义滚动条 |
Data Display
数据展示
| Component | Import | Notes |
|---|---|---|
| | Stateful. Full-featured table |
| | Simpler table |
| | High-perf large lists |
| | Stateful. Searchable list |
| | Stateful. Hierarchy |
| | Key-value pairs |
| | Settings panel |
| 组件 | 导入路径 | 说明 |
|---|---|---|
| | 有状态。全功能表格 |
| | 简易表格 |
| | 高性能大数据列表 |
| | 有状态。可搜索列表 |
| | 有状态。层级树组件 |
| | 键值对列表 |
| | 设置面板 |
Chat & Messaging
聊天与消息
| Component | Import | Notes |
|---|---|---|
| | Stateless. Chat message row |
| | Stateless. Message bubble |
| | Stateless. File/media attachment card |
| | Stateful. Auto-scrolling message list |
| 组件 | 导入路径 | 说明 |
|---|---|---|
| | 无状态。聊天消息行 |
| | 无状态。消息气泡 |
| | 无状态。文件/媒体附件卡片 |
| | 有状态。自动滚动消息列表 |
Charts
图表
| Component | Import | Notes |
|---|---|---|
| | Bar, line, area, pie charts |
| | |
| 组件 | 导入路径 | 说明 |
|---|---|---|
| | 柱状图、折线图、面积图、饼图 |
| | 数据需实现 |
GPUI References
GPUI参考文档
Load the file for the mechanism the task touches. Each file starts with a
contents line.
| Topic | File | Load when |
|---|---|---|
| Actions & keybindings | action.md | |
| Async & background tasks | async.md | |
| Context management | context.md | |
| Custom elements (low-level) | element.md | |
| Entity state | entity.md | |
| Events & subscriptions | event.md | |
| Focus & keyboard nav | focus-handle.md | |
| Global state | global.md | |
| Layout & styling | layout-style.md | |
| ElementId | element-id.md | |
| Testing | test.md | |
Deep dives, for when the topic file is not enough:
- Element trait: element-api.md (complete API, hitbox, events) · element-patterns.md (text, interactive, container, composite) · element-examples.md (full examples) · element-best-practices.md (performance, state, pitfalls) · element-advanced.md (custom layouts, async updates, virtual lists)
- Entities: entity-api.md (complete API, lifecycle) · entity-patterns.md (model-view, cross-entity, observer) · entity-best-practices.md (memory, performance) · entity-advanced.md (collections, registry, debounce, state machines)
- Testing: test-examples.md (organization, setup, assertions, running tests) · test-reference.md (re-entrancy, property tests, mocking)
根据任务涉及的机制加载对应文件,每个文件开头都有目录说明。
| 主题 | 文件 | 加载时机 |
|---|---|---|
| 动作与快捷键绑定 | action.md | 使用 |
| 异步与后台任务 | async.md | 使用 |
| 上下文管理 | context.md | 涉及 |
| 自定义元素(底层) | element.md | 实现 |
| 实体状态 | entity.md | 使用 |
| 事件与订阅 | event.md | 使用 |
| 焦点与键盘导航 | focus-handle.md | 使用 |
| 全局状态 | global.md | 使用 |
| 布局与样式 | layout-style.md | 使用 |
| ElementId | element-id.md | 使用 |
| 测试 | test.md | 使用 |
深度解析(当主题文件不足以覆盖需求时):
- Element trait:element-api.md(完整API、点击区域、事件)· element-patterns.md(文本、交互、容器、复合元素模式)· element-examples.md(完整示例)· element-best-practices.md(性能、状态、常见陷阱)· element-advanced.md(自定义布局、异步更新、虚拟列表)
- Entities:entity-api.md(完整API、生命周期)· entity-patterns.md(模型-视图、跨实体、观察者模式)· entity-best-practices.md(内存、性能)· entity-advanced.md(集合、注册表、防抖、状态机)
- 测试:test-examples.md(测试组织、设置、断言、运行测试)· test-reference.md(可重入性、属性测试、模拟)