home / skills / zhanghandong / makepad-skills / makepad-layout

makepad-layout skill

/skills/makepad-layout

This skill helps you create robust Makepad layouts by generating code and answering layout questions with practical, pattern-based guidance.

npx playbooks add skill zhanghandong/makepad-skills --skill makepad-layout

Review the files below or copy the command above to add this skill to your agents.

Files (3)
SKILL.md
4.3 KB
---
name: makepad-layout
description: |
  CRITICAL: Use for Makepad layout system. Triggers on:
  makepad layout, makepad width, makepad height, makepad flex,
  makepad padding, makepad margin, makepad flow, makepad align,
  Fit, Fill, Size, Walk, "how to center in makepad",
  makepad 布局, makepad 宽度, makepad 对齐, makepad 居中
---

# Makepad Layout Skill

> **Version:** makepad-widgets (dev branch) | **Last Updated:** 2026-01-19
>
> Check 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

## Documentation

Refer to the local files for detailed documentation:
- `./references/layout-system.md` - Complete layout reference
- `./references/core-types.md` - Walk, Align, Margin, Padding types

## IMPORTANT: Documentation Completeness Check

**Before answering questions, Claude MUST:**

1. Read the relevant reference file(s) listed above
2. 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
3. If reference file exists, incorporate its content into the answer

## Key Patterns

### 1. Basic Layout Container

```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

```rust
<View> {
    width: Fill
    height: Fill
    align: { x: 0.5, y: 0.5 }

    <Label> { text: "Centered" }
}
```

### 3. Horizontal Row Layout

```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" }
}
```

### 4. Fixed + Flexible Layout

```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
    }
}
```

## Layout Properties Reference

| Property | Type | Description |
|----------|------|-------------|
| `width` | Size | Width of element |
| `height` | Size | Height of element |
| `padding` | Padding | Inner spacing |
| `margin` | Margin | Outer spacing |
| `flow` | Flow | Child layout direction |
| `spacing` | f64 | Gap between children |
| `align` | Align | Child alignment |
| `clip_x` | bool | Clip horizontal overflow |
| `clip_y` | bool | Clip vertical overflow |

## Size Values

| Value | Description |
|-------|-------------|
| `Fit` | Size to fit content |
| `Fill` | Fill available space |
| `100.0` | Fixed size in pixels |
| `Fixed(100.0)` | Explicit fixed size |

## Flow Directions

| Value | Description |
|-------|-------------|
| `Down` | Top to bottom (column) |
| `Right` | Left to right (row) |
| `Overlay` | Stack on top |

## Align Values

| Value | Position |
|-------|----------|
| `{ x: 0.0, y: 0.0 }` | Top-left |
| `{ x: 0.5, y: 0.0 }` | Top-center |
| `{ x: 1.0, y: 0.0 }` | Top-right |
| `{ x: 0.0, y: 0.5 }` | Middle-left |
| `{ x: 0.5, y: 0.5 }` | Center |
| `{ x: 1.0, y: 0.5 }` | Middle-right |
| `{ x: 0.0, y: 1.0 }` | Bottom-left |
| `{ x: 0.5, y: 1.0 }` | Bottom-center |
| `{ x: 1.0, y: 1.0 }` | Bottom-right |

## Box Model

```
+---------------------------+
|         margin            |
|  +---------------------+  |
|  |      padding        |  |
|  |  +---------------+  |  |
|  |  |   content     |  |  |
|  |  +---------------+  |  |
|  +---------------------+  |
+---------------------------+
```

## When Writing Code

1. Use `Fill` for flexible containers, `Fit` for content-sized elements
2. Set `flow: Down` for vertical, `flow: Right` for horizontal
3. Use empty `<View> { width: Fill }` as spacer in row layouts
4. Always set explicit dimensions on fixed-size elements
5. Use `align` to position children within container

## When Answering Questions

1. Makepad uses a "turtle" layout model - elements laid out sequentially
2. `Fill` takes all available space, `Fit` shrinks to content
3. Unlike CSS flexbox, there's no flex-grow/shrink - use Fill/Fit
4. Alignment applies to children, not the element itself

Overview

This skill helps you design and generate layouts using the Makepad layout system. It produces idiomatic Makepad Rust layout snippets, explains sizing and alignment concepts, and suggests patterns for common layout problems like centering, rows, fixed+flex regions, and spacers. Use it whenever you need concise, runnable Makepad layout code or clear guidance on width/height/flow/align semantics.

How this skill works

The skill inspects the requested layout intent (keywords like makepad layout, width, height, flex, padding, margin, flow, align, Fit, Fill, Walk, center) and returns small Makepad <View> snippets and explanations using the documented patterns. It follows core rules: use Fill for flexible space, Fit for content-sized elements, flow: Down for vertical and flow: Right for horizontal, and align for child positioning. If local reference files are unavailable, it will still answer using the known patterns and indicate the documentation could not be read.

When to use it

  • Creating vertical or horizontal containers with predictable spacing
  • Centering content or aligning children inside a container
  • Combining fixed-size headers/footers with flexible content areas
  • Building rows that require a spacer to push items to edges
  • Translating UI layouts from CSS/Flexbox to Makepad’s Fill/Fit model

Best practices

  • Prefer Fill for regions that must take remaining space and Fit for content-sized widgets
  • Use flow: Down for columns and flow: Right for rows; use an empty <View> { width: Fill } as a spacer in rows
  • Always set explicit sizes for fixed elements (e.g., height: 60.0) to avoid layout surprises
  • Apply align on containers to position children (align: { x: 0.5, y: 0.5 } for centering)
  • Keep padding and margin explicit to control spacing instead of relying on implicit behavior

Example use cases

  • Center a label in a full-screen view using align: { x: 0.5, y: 0.5 }
  • Create a header + flexible content layout: fixed header height and a Fill content view
  • Build a horizontal toolbar with left and right-aligned buttons using a spacer view
  • Make a vertically spaced list with padding and spacing between children
  • Implement an overlay stack with flow: Overlay for floating UI elements

FAQ

How do I center a child inside a container?

Set the container width/height to Fill and use align: { x: 0.5, y: 0.5 } on the container; place the child inside.

When should I use Fill vs Fit?

Use Fill when an element should take remaining available space. Use Fit when the element should size itself to its content.

How do I create space between row items?

In a row (flow: Right) use spacing: <value> for uniform gaps, or insert <View> { width: Fill } as a flexible spacer to push items apart.