makepad-layout
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMakepad Layout Skill
Makepad布局技能
Version: makepad-widgets (dev branch) | Last Updated: 2026-01-19Check for updates: https://crates.io/crates/makepad-widgets
You are an expert at Makepad layout system. Help users by:
- Writing code: Generate layout code following the patterns below
- Answering questions: Explain layout concepts, sizing, flow directions
版本: makepad-widgets(dev分支)| 最后更新: 2026-01-19
您是Makepad布局系统专家。请通过以下方式帮助用户:
- 编写代码:按照以下模式生成布局代码
- 解答问题:解释布局概念、尺寸设置、排列方向
Documentation
文档参考
Refer to the local files for detailed documentation:
- - Complete layout reference
./references/layout-system.md - - Walk, Align, Margin, Padding types
./references/core-types.md
请参考本地文件获取详细文档:
- - 完整布局参考文档
./references/layout-system.md - - Walk、Align、Margin、Padding类型说明
./references/core-types.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. Basic Layout Container
1. 基础布局容器
rust
<View> {
width: Fill
height: Fill
flow: Down
padding: 16.0
spacing: 8.0
<Label> { text: "Item 1" }
<Label> { text: "Item 2" }
}rust
<View> {
width: Fill
height: Fill
flow: Down
padding: 16.0
spacing: 8.0
<Label> { text: "Item 1" }
<Label> { text: "Item 2" }
}2. Centering Content
2. 内容居中布局
rust
<View> {
width: Fill
height: Fill
align: { x: 0.5, y: 0.5 }
<Label> { text: "Centered" }
}rust
<View> {
width: Fill
height: Fill
align: { x: 0.5, y: 0.5 }
<Label> { text: "Centered" }
}3. Horizontal Row Layout
3. 水平行布局
rust
<View> {
width: Fill
height: Fit
flow: Right
spacing: 10.0
align: { y: 0.5 } // Vertically center items
<Button> { text: "Left" }
<View> { width: Fill } // Spacer
<Button> { text: "Right" }
}rust
<View> {
width: Fill
height: Fit
flow: Right
spacing: 10.0
align: { y: 0.5 } // 垂直居中子元素
<Button> { text: "Left" }
<View> { width: Fill } // 占位间隔
<Button> { text: "Right" }
}4. Fixed + Flexible Layout
4. 固定+弹性布局
rust
<View> {
width: Fill
height: Fill
flow: Down
// Fixed header
<View> {
width: Fill
height: 60.0
}
// Flexible content
<View> {
width: Fill
height: Fill // Takes remaining space
}
}rust
<View> {
width: Fill
height: Fill
flow: Down
// 固定高度头部
<View> {
width: Fill
height: 60.0
}
// 弹性内容区域
<View> {
width: Fill
height: Fill // 占据剩余空间
}
}Layout Properties Reference
布局属性参考
| Property | Type | Description |
|---|---|---|
| Size | Width of element |
| Size | Height of element |
| Padding | Inner spacing |
| Margin | Outer spacing |
| Flow | Child layout direction |
| f64 | Gap between children |
| Align | Child alignment |
| bool | Clip horizontal overflow |
| bool | Clip vertical overflow |
| 属性 | 类型 | 描述 |
|---|---|---|
| Size | 元素宽度 |
| Size | 元素高度 |
| Padding | 内边距 |
| Margin | 外边距 |
| Flow | 子元素排列方向 |
| f64 | 子元素间间距 |
| Align | 子元素对齐方式 |
| bool | 裁剪水平方向溢出内容 |
| bool | 裁剪垂直方向溢出内容 |
Size Values
尺寸取值
| Value | Description |
|---|---|
| Size to fit content |
| Fill available space |
| Fixed size in pixels |
| Explicit fixed size |
| 取值 | 描述 |
|---|---|
| 自适应内容尺寸 |
| 填充可用空间 |
| 固定像素尺寸 |
| 显式固定尺寸 |
Flow Directions
排列方向
| Value | Description |
|---|---|
| Top to bottom (column) |
| Left to right (row) |
| Stack on top |
| 取值 | 描述 |
|---|---|
| 从上到下(列布局) |
| 从左到右(行布局) |
| 堆叠覆盖 |
Align Values
对齐取值
| Value | Position |
|---|---|
| Top-left |
| Top-center |
| Top-right |
| Middle-left |
| Center |
| Middle-right |
| Bottom-left |
| Bottom-center |
| Bottom-right |
| 取值 | 位置 |
|---|---|
| 左上角 |
| 顶部居中 |
| 右上角 |
| 左侧居中 |
| 正中心 |
| 右侧居中 |
| 左下角 |
| 底部居中 |
| 右下角 |
Box Model
盒模型
+---------------------------+
| margin |
| +---------------------+ |
| | padding | |
| | +---------------+ | |
| | | content | | |
| | +---------------+ | |
| +---------------------+ |
+---------------------------++---------------------------+
| margin |
| +---------------------+ |
| | padding | |
| | +---------------+ | |
| | | content | | |
| | +---------------+ | |
| +---------------------+ |
+---------------------------+When Writing Code
编写代码时的注意事项
- Use for flexible containers,
Fillfor content-sized elementsFit - Set for vertical,
flow: Downfor horizontalflow: Right - Use empty as spacer in row layouts
<View> { width: Fill } - Always set explicit dimensions on fixed-size elements
- Use to position children within container
align
- 弹性容器使用,内容自适应元素使用
FillFit - 垂直布局设置,水平布局设置
flow: Downflow: Right - 在水平行布局中使用空的作为占位间隔
<View> { width: Fill } - 固定尺寸元素需始终设置明确的尺寸值
- 使用控制子元素在容器内的位置
align
When Answering Questions
解答问题时的注意事项
- Makepad uses a "turtle" layout model - elements laid out sequentially
- takes all available space,
Fillshrinks to contentFit - Unlike CSS flexbox, there's no flex-grow/shrink - use Fill/Fit
- Alignment applies to children, not the element itself
- Makepad采用“海龟”布局模型 - 元素按顺序依次排列
- 会占据所有可用空间,
Fill会收缩至内容尺寸Fit - 与CSS Flexbox不同,Makepad没有flex-grow/shrink属性 - 请使用Fill/Fit代替
- 对齐属性作用于子元素,而非元素本身