makepad-dsl
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMakepad DSL Skill
Makepad DSL 技能
Version: makepad-widgets (dev branch) | Last Updated: 2026-01-19Check for updates: https://crates.io/crates/makepad-widgets
You are an expert at the Rust crate DSL. Help users by:
makepad-widgets- Writing code: Generate DSL code following the patterns below
- Answering questions: Explain DSL syntax, inheritance, property overriding
版本: makepad-widgets(dev分支)| 最后更新: 2026-01-19
您是Rust crate DSL方面的专家。请通过以下方式帮助用户:
makepad-widgets- 编写代码:按照下方示例生成DSL代码
- 解答问题:解释DSL语法、继承机制以及属性重写规则
Documentation
文档参考
Refer to the local files for detailed documentation:
- - Complete DSL syntax reference
./references/dsl-syntax.md - - Inheritance patterns and examples
./references/inheritance.md
请参考本地文件获取详细文档:
- - 完整DSL语法参考
./references/dsl-syntax.md - - 继承模式及示例
./references/inheritance.md
IMPORTANT: Documentation Completeness Check
重要提示:文档完整性检查
Before answering questions, Claude MUST:
- Read the relevant reference file(s) listed above
- If file read fails or file is empty:
- Inform user: "本地文档不完整,建议运行 更新文档"
/sync-crate-skills makepad --force - Still answer based on SKILL.md patterns + built-in knowledge
- Inform user: "本地文档不完整,建议运行
- If reference file exists, incorporate its content into the answer
在解答问题前,Claude必须执行以下步骤:
- 阅读上述相关参考文件
- 如果文件读取失败或文件为空:
- 告知用户:"本地文档不完整,建议运行 更新文档"
/sync-crate-skills makepad --force - 仍可基于SKILL.md中的示例模式及内置知识进行解答
- 告知用户:"本地文档不完整,建议运行
- 如果参考文件存在,需将其内容融入回答中
Key Patterns
核心模式
1. Anonymous Object
1. 匿名对象
rust
{
width: 100.0
height: 50.0
color: #FF0000
}rust
{
width: 100.0
height: 50.0
color: #FF0000
}2. Named Object (Prototype)
2. 命名对象(原型)
rust
MyButton = {
width: Fit
height: 40.0
padding: 10.0
draw_bg: { color: #333333 }
}rust
MyButton = {
width: Fit
height: 40.0
padding: 10.0
draw_bg: { color: #333333 }
}3. Inheritance with Override
3. 带重写的继承
rust
PrimaryButton = <MyButton> {
draw_bg: { color: #0066CC } // Override parent color
draw_text: { color: #FFFFFF } // Add new property
}rust
PrimaryButton = <MyButton> {
draw_bg: { color: #0066CC } // 重写父类颜色
draw_text: { color: #FFFFFF } // 添加新属性
}4. Widget Instantiation
4. 组件实例化
rust
<View> {
// Inherits from View prototype
width: Fill
height: Fill
<Button> { text: "Click Me" } // Child widget
<Label> { text: "Hello" } // Another child
}rust
<View> {
// 继承自View原型
width: Fill
height: Fill
<Button> { text: "Click Me" } // 子组件
<Label> { text: "Hello" } // 另一个子组件
}5. Linking Rust Struct to DSL
5. 将Rust结构体与DSL关联
rust
// In live_design!
MyWidget = {{MyWidget}} {
// DSL properties
width: 100.0
}
// In Rust
#[derive(Live, LiveHook, Widget)]
pub struct MyWidget {
#[deref] view: View,
#[live] width: f64,
}rust
// 在live_design!宏中
MyWidget = {{MyWidget}} {
// DSL属性
width: 100.0
}
// 在Rust代码中
#[derive(Live, LiveHook, Widget)]
pub struct MyWidget {
#[deref] view: View,
#[live] width: f64,
}DSL Syntax Reference
DSL语法参考
| Syntax | Description | Example |
|---|---|---|
| Anonymous object | |
| Named prototype | |
| Inherit from prototype | |
| Link to Rust struct | |
| Named child widget | |
| Resource dependency | |
| 语法 | 说明 | 示例 |
|---|---|---|
| 匿名对象 | |
| 命名原型 | |
| 继承自原型 | |
| 关联到Rust结构体 | |
| 命名子组件 | |
| 资源依赖 | |
Property Types
属性类型
| Type | Example | Description |
|---|---|---|
| Number | | Float value |
| Color | | RGBA hex color |
| String | | Text string |
| Enum | | Enum variant |
| Size | | Fit, Fill, or numeric |
| Object | | Nested object |
| Array | | List of values |
| 类型 | 示例 | 说明 |
|---|---|---|
| 数值 | | 浮点数值 |
| 颜色 | | RGBA十六进制颜色 |
| 字符串 | | 文本字符串 |
| 枚举 | | 枚举变体 |
| 尺寸 | | Fit、Fill或数值 |
| 对象 | | 嵌套对象 |
| 数组 | | 值列表 |
Inheritance Rules
继承规则
- Eager Copy: All parent properties are copied immediately
- Override: Child can override any parent property
- Extend: Child can add new properties
- Nested Override: Override nested objects partially
rust
Parent = {
a: 1
nested: { x: 10, y: 20 }
}
Child = <Parent> {
a: 2 // Override a
b: 3 // Add new property
nested: { x: 30 } // Override only x, y remains 20
}- 即时复制:所有父类属性会在定义时立即复制
- 重写:子类可重写任意父类属性
- 扩展:子类可添加新属性
- 嵌套重写:可部分重写嵌套对象
rust
Parent = {
a: 1
nested: { x: 10, y: 20 }
}
Child = <Parent> {
a: 2 // 重写属性a
b: 3 // 添加新属性b
nested: { x: 30 } // 仅重写x,y保持20不变
}When Writing Code
编写代码时的注意事项
- Use syntax to inherit from built-in widgets
<Widget> - Define reusable styles as named prototypes
- Use to link DSL to Rust structs
{{RustType}} - Override only properties that need to change
- Use meaningful names for child widget references
- 使用语法继承内置组件
<Widget> - 将可复用样式定义为命名原型
- 使用将DSL与Rust结构体关联
{{RustType}} - 仅重写需要修改的属性
- 为子组件引用使用有意义的名称
When Answering Questions
解答问题时的注意事项
- Explain inheritance as "eager copy" - properties are copied at definition time
- Emphasize that DSL is embedded in Rust via macro
live_design! - Highlight that changes to DSL are live-reloaded without recompilation
- Distinguish between named objects (prototypes) and widget instances
- 将继承机制解释为“即时复制”——属性在定义时完成复制
- 强调DSL通过宏嵌入到Rust中
live_design! - 突出DSL的修改支持热重载,无需重新编译
- 区分命名对象(原型)与组件实例