Skill

Master Makepad Event and Action Handling

Skill for Makepad event and action handling - Event/Hit enums, cx.action() emission, and child-to-parent action capture.

Works with github

91
Spark score
out of 100
Updated last month
Version 1.0.0

Add to Favorites

Why it matters

Become an expert in Makepad's event and action handling system. This skill assists in managing UI interactions, event propagation, and widget communication within Makepad applications.

Outcomes

What it gets done

01

Handle various event types including mouse, keyboard, touch, and lifecycle events.

02

Create and manage actions for communication between widgets and their parents.

03

Understand and debug event propagation and flow within the Makepad framework.

04

Assist in designing and implementing event handling logic for Makepad widgets.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/ag-makepad-event-action | bash

Overview

Makepad Event/Action Skill

A Makepad event/action reference skill covering the Event and Hit enums, cx.action() action emission (main-thread and thread-safe), parent capture of child actions via capture_actions(), and the six-step event propagation flow. Use for Makepad input/lifecycle event handling or widget-to-parent action communication. Scoped to the event/action system specifically - not DSL, layout, animation, fonts, or shaders.

What it does

Makepad Event/Action Skill is an expert reference for handling input, lifecycle, and UI interaction events in the Makepad Rust UI framework, and for designing widget-to-parent communication through its action system (tracks the makepad-widgets dev branch). It covers mouse, keyboard, touch, and lifecycle event handling, action creation, and event propagation flow.

Before answering, it is instructed to read local event-system.md and action-system.md reference files and incorporate their content, falling back to SKILL.md patterns plus built-in knowledge if a file is missing or empty (surfacing a documentation-sync command to the user in that case). It documents the full Event enum - lifecycle variants (Startup, Shutdown, Foreground/Background, Resume/Pause), drawing (Draw, LiveEdit), window (focus/geometry/close), mouse (MouseDown/Move/Up, Scroll), touch (TouchUpdate), keyboard (KeyDown/Up, TextInput, TextCopy), timer (Timer, NextFrame), network (HttpResponse), and widget Actions - alongside the Hit enum used inside handle_event to test whether an event targets a specific widget's area (FingerDown/Up/Move/HoverIn/HoverOver/HoverOut/LongPress, KeyDown/Up, KeyFocus/Lost, TextInput/Copy, Nothing).

match event.hits(cx, self.area()) {
    Hit::FingerDown(fe) => { cx.action(MyWidgetAction::Pressed); }
    Hit::FingerUp(fe) => { if fe.is_over { cx.action(MyWidgetAction::Clicked); } }
    Hit::FingerHoverIn(_) => { self.animator_play(cx, id!(hover.on)); }
    _ => {}
}

For the action system, it shows defining a custom action enum with #[derive(Clone, Debug, DefaultNone)] (which auto-implements Default returning the None variant), emitting actions from the main thread via cx.action(...) or from any thread via the thread-safe Cx::post_action(...), and handling child actions by capturing them with cx.capture_actions(|cx| { ... }) and either checking a widget-specific helper like .clicked(&actions) or iterating and downcasting actions manually. It lists common widget action helpers (ButtonRef::clicked/pressed/released, TextInputRef::changed/returned).

The event flow is stated as six steps: an event arrives from the platform layer, the root widget receives it first, it propagates down to children via handle_event, widgets emit actions via cx.action(), the parent captures those actions via cx.capture_actions(), and the app handles whatever actions remain. Timer and next-frame patterns are covered separately: cx.start_timer(seconds) paired with checking Event::Timer(te) for a matching timer_id, and cx.new_next_frame() paired with checking Event::NextFrame(ne) for a matching frame_id.

Five conceptual points guide question-answering: use event.hits(cx, area) to check whether an event targets a widget, actions flow UP from child to parent while events flow DOWN, cx.capture_actions() intercepts child actions, Cx::post_action() is the thread-safe path for async operations, and the DefaultNone derive macro auto-implements Default for action enums.

When to use - and when NOT to

Use this skill when handling input, lifecycle, or UI interaction events in Makepad, or when the task involves handle_event, Event variants, Hit processing, or widget action propagation between widgets and parents.

It is scoped to Makepad's event/action system specifically, not DSL syntax, layout, animation, fonts, or shaders covered by sibling Makepad skills. It is not a substitute for environment-specific validation, testing, or expert review - if local reference documentation is missing, it flags this explicitly rather than silently guessing beyond its built-in knowledge.

Inputs and outputs

Inputs: a description of the input handling, lifecycle response, or widget-to-parent communication needed in a Makepad widget.

Outputs: Rust handle_event implementations matching events/hits to behavior, action enum definitions, and action emission/capture code for parent-child communication.

Integrations

Part of the Makepad skill family alongside basics, DSL, layout, animation, font, shader, deployment, and reference skills; references local event-system.md and action-system.md documentation kept in sync via a /sync-crate-skills makepad command.

Who it's for

Makepad developers implementing input handling, widget interactions, or parent-child communication who need the correct Event/Hit enum usage and action emission/capture patterns.

FAQ

Common questions

Discussion

Questions & comments ยท 0

Sign In Sign in to leave a comment.