Getting Started
Get from zero to a running native GPUI window in a few minutes. GPUI-RSX expands JSX-like markup into plain GPUI builder calls at compile time—there is no virtual DOM and no runtime template parser.
1. Add dependencies
Section titled “1. Add dependencies”Add GPUI Kit (aliased as gpui so macro-generated paths resolve cleanly) and GPUI-RSX to your Cargo.toml:
[dependencies]gpui = { package = "gpui-kit", version = "=0.10.0" }gpui-rsx = "0.13.0"GPUI Kit pins its matching gpui-pre snapshot and re-exports the engine, gpui-component controls, and icons. Commit Cargo.lock so builds stay reproducible across machines.
Upgrading from Zed Git
gpuior the officialgpui = "0.2.2"crate? Follow the Migration Guide.
2. Write your first view
Section titled “2. Write your first view”Replace src/main.rs with a complete counter view. Always import gpui::* and gpui::prelude::* so generated builder methods are in scope:
use gpui::component::{ ActiveTheme as _, button::{Button, ButtonVariants as _},};use gpui::prelude::*;use gpui::*;use gpui_rsx::{rsx, rsx_listener};
#[derive(Default)]struct CounterView { count: usize,}
impl Render for CounterView { fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { rsx! { <div class="size-full flex flex-col gap-[16px] p-[24px]" bg={cx.theme().background} text_color={cx.theme().foreground} > <h1 class="text-xl font-bold">{format!("Count: {}", self.count)}</h1> <p class="text-sm text-gray-500"> {"Static RSX expands directly to native GPUI builder calls."} </p> <Button("increment") label="Increment" primary onClick={rsx_listener!(cx, notify, |view, _, _, _| { view.count += 1; })} /> </div> } }}
fn main() { application().with_assets(assets::Assets).run(|cx: &mut App| { gpui::init(cx); gpui::open_window(WindowOptions::default(), cx, |_, cx| { cx.new(|_| CounterView::default()) }) .expect("failed to open window"); cx.activate(true); });}3. Run the application
Section titled “3. Run the application”Launch from your project root:
cargo runGPUI requires your platform’s native build dependencies. Check the Compatibility Matrix to align Rust, GPUI Kit, and component versions.
Core mental model
Section titled “Core mental model”Once your first window opens, four patterns cover 90% of day-to-day RSX code:
Elements & text children
Section titled “Elements & text children”Every element expands into a GPUI builder chain. Mix string literals and Rust expressions freely inside tags:
rsx! { <div> "Count: " {self.count.to_string()} </div>}// Expands to:// div().child("Count: ").child(self.count.to_string())Flags, value attributes & aliases
Section titled “Flags, value attributes & aliases”| RSX syntax | Expands to | When to use |
|---|---|---|
<div flex flex_col rounded_md /> |
.flex().flex_col().rounded_md() |
Zero-argument builder flags |
<div gap={px(16.0)} bg={rgb(0x3b82f6)} /> |
.gap(px(16.0)).bg(rgb(0x3b82f6)) |
Typed Rust values & theme colors |
<button onClick={handler} textColor={rgb(0xffffff)} /> |
.on_click(handler).text_color(...) |
CamelCase aliases for GPUI snake_case methods |
Static & conditional class
Section titled “Static & conditional class”String literals and clsx-style conditional arrays expand entirely at compile time with zero runtime parsing:
rsx! { <div class={[ "flex items-center p-8 rounded-md", if selected { "bg-blue-500 text-white" } else { "bg-gray-100" }, disabled && "opacity-50", ]} w={px(self.sidebar_width)} bg={cx.theme().background} > {label.as_str()} </div>}If a class string is assembled at runtime (class={row_class}), GPUI-RSX generates a compact StyleRefinement matcher. Dynamic strings do not support state variants (hover:, active:) or stateful scroll classes—see Class Handling for the full matrix.
Interactive controls & keyed lists
Section titled “Interactive controls & keyed lists”- Components: Pass constructor arguments in parentheses (
<Button("save") ... />→Button::new("save")). - Events: Wrap updates in
rsx_listener!(cx, notify, |view, _, _, _| { ... })to mutate state and trigger a redraw automatically, or passcx.listener(...)directly. - Lists: Add
key={...}to interactive elements inside{for ...}so GPUI preserves element identity across updates. For uniform-height lists with hundreds or thousands of rows, switch to<uniform_list>.
rsx! { <ul> {for task in &self.tasks { <li key={task.id} onClick={handler}> {task.title.as_str()} </li> }} </ul>}Where to go next
Section titled “Where to go next”- Syntax Reference — elements, fragments, loops,
#[component], and named slots. - Class Handling — static expansion, conditional arrays, state variants, and dynamic limits.
- Themes & Design Tokens — share colors, spacing, and typography via
rsx.toml. - IDs and Keys — how automatic IDs work and when to specify
keyorid. - CLI & Editors — set up VS Code / Zed LSP, formatting, linting, and
cargo rsx dev. - Incident Console — study a modular, multi-pane native desktop application.