Langsung ke konten
Skillpedia
Website & UI (frontend)48k · #5140

makepad-2-0-dsl

Fungsinya

Panduan ini membantu Anda memahami dan menggunakan bahasa pemrograman Makepad 2.0 untuk membuat antarmuka pengguna. Panduan ini menjelaskan cara mendefinisikan elemen visual, propertinya, dan bagaimana elemen-elemen tersebut saling berinteraksi.

Kapan dipakai

  • ✓Saat membangun antarmuka visual sebuah aplikasi dengan Makepad.
  • ✓Saat mencoba memperbaiki error pada kode antarmuka Makepad.
  • ✓Saat mempelajari sintaks khusus Makepad untuk desain.

Link skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/makepad-2-0-dsl/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/makepad-2-0-dsl/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit →

Contoh permintaan ke AI

“Bagaimana cara mendefinisikan tombol yang berubah warna saat mouse diarahkan ke atasnya?”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Makepad menggunakan bahasa khusus tempat Anda menulis definisi antarmuka. Anda menggunakan simbol ':' untuk mengatur properti dan ':=' untuk memberi nama pada elemen, sehingga elemen tersebut bisa dikendalikan nanti.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

Limitations

  • Verify against current Makepad 2.0 docs; upstream APIs change frequently.
  • Do not run bundled scripts without explicit user approval.

When to Use

  • Use when this upstream workflow matches the user's stated goal.
  • Use when the task requires the procedures documented in this skill.

Makepad 2.0 DSL Syntax Skill

Overview

Makepad 2.0 replaced the compile-time live_design! macro with the runtime script_mod! macro, powered by the Splash scripting language. This skill covers the complete DSL syntax, property system, registration patterns, and common pitfalls.

Key Syntax Rules

Property Assignment: Colon, NOT Equals

key: value          // CORRECT - colon syntax
key = value         // WRONG - old 1.x syntax, no longer works

Properties are whitespace/newline separated. No commas between siblings.

View{
    width: Fill
    height: Fit
    flow: Down
    spacing: 10
    padding: 15
}

Named Instances: := Operator

Use := to create addressable, named widget instances:

my_button := Button{ text: "Click me" }
title := Label{ text: "Hello" }

Named instances are:

  • Addressable from Rust code via id!(my_button) or ids!(my_button)
  • Overridable via dot-path syntax: MyTemplate{ title.text: "New text" }
  • Stored in the script object's vec (not map)

Regular properties use : and go into map:

width: Fill       // regular property -> map
label := Label{}  // named child -> vec

Merge Operator: +:

The +: operator extends/merges with the parent instead of replacing:

draw_bg +: {
    color: #f00    // Only overrides color, keeps all other draw_bg properties
}

Without +:, you REPLACE the entire property:

draw_bg: { color: #f00 }    // REPLACES all of draw_bg - loses hover, border, etc.
draw_bg +: { color: #f00 }  // MERGES - only changes color, keeps everything else

Dot-Path Shorthand

Dot-path is syntactic sugar for merge:

draw_bg.color: #f00
// is equivalent to:
draw_bg +: { color: #f00 }

draw_text.text_style.font_size: 14
// is equivalent to:
draw_text +: { text_style +: { font_size: 14 } }

Let Bindings: Local Templates

let creates local, reusable templates within a script_mod! block:

let MyCard = RoundedView{
    width: Fill height: Fit
    padding: 16 flow: Down spacing: 8
    draw_bg.color: #2a2a3d
    draw_bg.border_radius: 8.0
    title := Label{ text: "Default Title" draw_text.color: #fff }
    body := Label{ text: "" draw_text.color: #aaa }
}

// Instantiate and override:
MyCard{ title.text: "Card 1" body.text: "Content here" }
MyCard{ title.text: "Card 2" body.text: "More content" }

IMPORTANT: let bindings are LOCAL to the script_mod! block. They cannot be accessed from other script_mod! blocks. To share across modules, store in mod.widgets.*.

Spread Operator: ..

Inherit all properties from another definition:

set_type_default() do #(DrawMyShader::script_shader(vm)){
    ..mod.draw.DrawQuad   // Inherit from DrawQuad
}

Script Module Structure

Basic App Structure

use makepad_widgets::*;

app_main!(App);

script_mod!{
    use mod.prelude.widgets.*

    load_all_resources() do #(App::script_component(vm)){
        ui: Root{
            main_window := Window{
                window.inner_size: vec2(800, 600)
                body +: {
                    // UI content here
                    my_button := Button{ text: "Click" }
                }
            }
        }
    }
}

impl App {
    fn run(vm: &mut ScriptVm) -> Self {
        crate::makepad_widgets::script_mod(vm);  // 1. Register base widgets
        App::from_script_mod(vm, self::script_mod)
    }
}

#[derive(Script, ScriptHook)]
pub struct App {
    #[source] source: ScriptObjectRef,   // REQUIRED for Script-derived structs
    #[live] ui: WidgetRef,
}

impl MatchEvent for App {
    fn handle_actions(&mut self, cx: &mut Cx, actions: &Actions) {
        if self.ui.button(ids!(my_button)).clicked(actions) {
            log!("Button clicked!");
        }
    }
}

impl AppMain for App {
    fn handle_event(&mut self, cx: &mut Cx, event: &Event) {
        self.match_event(cx, event);
        self.ui.handle_event(cx, event, &mut Scope::empty());
    }
}

Widget Definition Module

script_mod!{
    use mod.prelude.widgets_internal.*   // For widget library internals
    use mod.widgets.*                     // Access other registered widgets


…
Pertanyaan umum

Apa perbedaan ':' dan '='?

Gunakan ':' untuk mengatur properti elemen (seperti warna atau ukuran). '=' digunakan di versi lama dan sudah tidak berfungsi.

Bagaimana cara membuat elemen yang bisa dipakai ulang?

Anda bisa menggunakan kata kunci 'let' untuk membuat template elemen yang bisa dipakai ulang. Ini membantu menghindari penulisan kode yang berulang.

Apa itu operator '+:'?

Operator '+:' memungkinkan Anda mengubah hanya sebagian properti dari elemen yang sudah ada, tanpa mengganti elemen tersebut secara keseluruhan. Ini berguna untuk melakukan perubahan kecil tanpa kehilangan pengaturan sebelumnya.

Detail

Deskripsi asli dari pembuat

Makepad 2.0 guidance for dsl; use when building or debugging Makepad UI code.

repo: sickn33/agentic-awesome-skills

Popularitas

Bintang GitHub
48k
Peringkat
#5140
Lisensi
MIT
Diperbarui
15/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa