Skip to content

API Reference

use gpui_rsx::{rsx, rsx_expand, rsx_permissive, rsx_strict};
MacroBehavior
rsx!Default permissive RSX macro.
rsx_permissive!Explicit permissive mode; unsupported classes are ignored when safe.
rsx_strict!Unsupported static classes become compile errors; unsupported dynamic classes panic when evaluated.
rsx_expand!Returns a string preview of generated GPUI builder code.
RSX tagGenerated constructor
div, span, section, article, header, footer, main, nav, asidediv()
h1 through h6, p, label, adiv()
button, input, textarea, select, formdiv()
ul, ol, lidiv()
svgsvg()
img src={source} or img source={source}img(source)
canvas prepaint={a} paint={b}canvas(a, b)
MyComponentMyComponent()
ui::TaskCardui::TaskCard()
any tag with base={expr}expr
RSXGenerated form
<div flex />.flex()
<div gap={px(4.0)} />.gap(px(4.0))
<div class="flex gap-4" />compile-time class method expansion
<div class={classes} />generated runtime class matcher
<div visible={cond} />.visible() or .invisible()
<img grayscale />.grayscale(true)
<Button base={Button::new("id")} />starts method chain from Button::new("id")
<button key={id} onClick={h} />generated composite .id(...) plus .on_click(h)

id, key, and base are macro-level attributes. id generates .id(...); key and base are consumed by the macro.

RSX attributeGPUI method
onClickon_click
onMouseDownon_mouse_down
onMouseUpon_mouse_up
onMouseMoveon_mouse_move
onHoveron_hover
onDragon_drag
onDropon_drop
onKeyDown / onKeyUpon_key_down / on_key_up
captureKeyDown / captureKeyUpcapture_key_down / capture_key_up
backgroundColorbg
textColortext_color
fontSizetext_size
fontWeightfont_weight
lineHeightline_height
minWidth / maxWidthmin_w / max_w
minHeight / maxHeightmin_h / max_h
gapX / gapYgap_x / gap_y
overflowScrolloverflow_scroll
overflowXScroll / overflowYScrolloverflow_x_scroll / overflow_y_scroll
trackScrolltrack_scroll
groupHover / groupActivegroup_hover / group_active
tabIndex / tabStoptab_index / tab_stop

Multi-argument methods use tuple values:

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

groupDragOver / group_drag_over is not available as an attribute because GPUI requires an explicit drag data type. Use when or base and call group_drag_over::<YourType>(...) directly.

AttributeShapeGenerated idea
when`when={(condition,el
whenSome`whenSome={(option,el, value
whenClasswhenClass={(condition, "class list")}`.when(condition,

whenClass requires a string literal and rejects stateful scroll classes.

Static class strings are the broadest and fastest path. Dynamic class strings support the common runtime matcher subset.

AreaExamples
Layoutflex, flex-col, grid, hidden, absolute, relative
Alignmentitems-center, justify-between, content-stretch, self-center
Spacinggap-4, gap-x-2, p-4, px-2, m-4, mt-2
Sizingw-full, w-64, w-[280px], w-[37.5%], w-6/24
Colorsbg-blue-500, text-white, border-gray-300, bg-[#ff0000]
Typographytext-sm, text-2xl, font-bold, text-center, truncate
Bordersborder, border-t, border-2, rounded-md, rounded-full
Misccursor-pointer, debug-outline, shadow-md, opacity-50, col-span-full

Numeric utilities use direct pixel semantics: w-64 means w(px(64.0)).

The macro injects IDs for attributes and static classes that require GPUI stateful identity:

CategoryNames
EventsonClick, onHover, onDrag, onAuxClick, onA11yAction
Interactive stateactive, activeClass, groupActive, focusable, tooltip, hoverableTooltip, tooltipShowDelay, anchorScroll, trackScroll, scrollbarWidth
Accessibilityrole, ariaLabel, ariaSelected, ariaExpanded, and other aria* attributes
Scroll classesoverflow-scroll, overflow-x-scroll, overflow-y-scroll

Inside {for ...}, stateful elements must provide id={...} or key={...}. groupHover does not require an ID; groupActive does.

RSX bodyReturn expression
Single elementgenerated GPUI element expression
Fragment <>...</>vec![...]
Child expression {expr}.child(expr)
Spread {...iter}.children(iter)
For loop {for item in iter { ... }}.children(iter.into_iter().map(...)) or .flat_map(...)