Skip to content

API Reference

A compact lookup table for GPUI-RSX macros, constructors, attribute rules, and generated GPUI mappings. For step-by-step explanations and full examples, see the Syntax Reference and Runnable Demos.

use gpui_rsx::{
component, rsx, rsx_expand, rsx_fragment, rsx_listener, rsx_permissive,
rsx_runtime, rsx_strict, rsx_tw, rsx_update,
};
Macro Purpose
rsx! Default permissive RSX macro (pixel spacing unless configured otherwise).
rsx_strict! Compile-time errors for unsupported static classes; unsupported dynamic tokens panic unless handled by onUnknownClass.
rsx_permissive! Explicitly selects permissive class handling while preserving configured spacing scale.
rsx_tw! Uses Tailwind’s 4px numeric spacing scale (gap-4 → 16px).
rsx_fragment! Always returns Vec<gpui::AnyElement> for heterogeneous root elements.
rsx_expand! Returns a string preview of generated GPUI builder code (debug only; no type checking).
rsx_runtime! Emits shared dynamic class helpers at the crate root; pair with [options] dynamic-runtime = "rsx_runtime" (Performance).
rsx_listener! Wraps cx.listener(...); the notify variant calls cx.notify() automatically after normal return (Event listeners).
rsx_update! Executes a synchronous FnOnce update, calls cx.notify() on normal return, and returns the closure’s value (Explicit state updates).
#[component] Generates a typed props builder for a named-field struct or synchronous function (Components).

Generated GPUI paths default to ::gpui. Override via [options] gpui-path in rsx.toml when using a renamed dependency (Compatibility).

RSX tag Generated constructor
div, span, section, article, header, footer, main, nav, aside div()
h1–h6, p, label, a div()
button, input, textarea, select, form div()
ul, ol, li div()
svg svg()
img src={source} or img source={source} img(source)
canvas prepaint={a} paint={b} canvas(a, b)
uniform_list count={n} render={f} uniform_list(id_or_auto, n, f)
MyComponent / ui::TaskCard MyComponent() / ui::TaskCard()
Button("id") / Tab() Button::new("id") / Tab::new()
widget("a", 1) widget("a", 1)
Any tag with base={expr} expr
RSX Generated code
<div flex /> .flex()
<div gap={px(4.0)} /> .gap(px(4.0))
<div class="flex gap-4" /> Compile-time class method chain
<div class={["flex", cond && "gap-4"]} /> Compile-time conditional method chain
<div class={classes} /> Runtime StyleRefinement class matcher
<div visible={cond} /> .visible() or .invisible()
<img grayscale /> / <uniform_list yFlipped ... /> .grayscale(true) / .y_flipped(true)
<Button("id") /> / <Button base={Button::new("id")} /> Starts method chain from Button::new("id")
<div slot="header">...</div> (inside component) Calls .header(div()...) on parent component builder
<button key={id} onClick={h} /> Generated composite .id(...) + .on_click(h)

id, key, and base are macro-level attributes: id emits .id(...), while key and base are consumed by the macro.

RSX attribute GPUI method
onClick / onHover on_click / on_hover
onMouseDown / onMouseUp / onMouseMove on_mouse_down / on_mouse_up / on_mouse_move
onDrag / onDrop on_drag / on_drop
onKeyDown / onKeyUp on_key_down / on_key_up
captureKeyDown / captureKeyUp capture_key_down / capture_key_up
backgroundColor / textColor bg / text_color
fontSize / fontWeight / lineHeight text_size / font_weight / line_height
minWidth / maxWidth min_w / max_w
minHeight / maxHeight min_h / max_h
gapX / gapY gap_x / gap_y
overflowScroll / overflowXScroll / overflowYScroll overflow_scroll / overflow_x_scroll / overflow_y_scroll
trackScroll track_scroll
groupHover / groupActive group_hover / group_active
tabIndex / tabStop tab_index / tab_stop

Pass multi-argument methods as tuples:

rsx! {
<div
onMouseDown={(MouseButton::Left, handler)}
onDrag={(drag_value, build_drag)}
/>
}

groupDragOver / group_drag_over is not supported as an attribute because GPUI requires an explicit drag payload type parameter. Call group_drag_over::<YourType>(...) inside when or base.

Attribute Syntax Expansion
when `when={(condition, el
whenSome `whenSome={(option, el, val
whenClass whenClass={(condition, "class list")} `.when(condition,

whenClass requires a string literal and rejects stateful scroll classes.

Area Examples
Layout flex, flex-col, grid, hidden, absolute, relative
Alignment items-center, justify-between, content-stretch, self-center
Spacing gap-4, gap-x-2, p-4, px-2, m-4, mt-2, -m-2
Sizing w-full, w-64, w-[280px], w-[37.5%], w-6/24
Colors bg-blue-500, text-white, border-gray-300, bg-[#ff0000]
Typography text-sm, text-2xl, font-bold, text-center, truncate, text-ellipsis-start, text-ellipsis-middle
Borders border, border-t, border-2, rounded-md, rounded-full
Misc cursor-pointer, debug-outline, shadow-md, opacity-50, col-span-full

Numeric utilities default to direct pixels (w-64 → w(px(64.0))).

The macro injects .id(...) automatically when any of the following are present:

Category Names
Events onClick, onHover, onDrag, onAuxClick, onA11yAction
Interactive state active, activeClass, groupActive, focusable, tooltip, hoverableTooltip, tooltipShowDelay, anchorScroll, trackScroll, restrictScrollToAxis, externalDragPayload
Accessibility role, accessibilityId, ariaLabel, ariaDescription, ariaKeyShortcuts, ariaActiveDescendant, a11ySyntheticChildren, and other aria* attributes
Scroll classes overflow-scroll, overflow-x-scroll, overflow-y-scroll

Inside {for ...}, stateful elements must specify id={...} or key={...}. groupHover, scrollbarWidth, and mouse exit/pressure/pinch handlers do not require a stateful ID.

RSX body Generated return type / form
Single element Concrete GPUI element expression
Fragment <>...</> vec![...] (or Vec<AnyElement> if containing {for ...} or {...spread})
Nested fragment Flattened directly into the enclosing element, fragment, or loop
Child expression {expr} .child(expr)
Spread {...iter} .children(iter)
if / match child .when(...) or .child(...) depending on branch structure
{for ...} child .children(...) collecting loop iterations