Cookbook
Self-contained patterns for interface problems that come up in most terminal applications. Each recipe is a complete program from the repository's example/ directory — it compiles as part of the project's example build, so you can paste it into a project and adapt it.
The recipes rely on three RTXUI idioms worth internalizing:
- State lives in C++ members; the template reads it. Templates interpolate bound names — they do not evaluate expressions, contain statements, or perform assignments.
- Logic is a computed method. A
constmethod returns a class string or a boolean; the template binds it withclass="{method_name}"orcondition="{method_name}". Ternaries and comparisons live in C++. - Event handlers name a bound method, optionally with one argument:
onclick="Select(home)"invokesvoid Select(std::string)with"home".
Tabbed navigation
Track the active tab in a state variable. Buttons call a single parameterized method; each button's class and each pane's visibility come from computed methods. The <if>/<elif>/<else> chain shows one pane at a time.
For most tabbed interfaces the built-in <tabs>/<tab-pane> components are enough; this recipe is the underlying pattern for when you need full control over the header.
Background work without freezing the UI
Callbacks run on the main thread, so blocking inside one (network requests, large file reads) freezes rendering. Run the work on a std::thread and post the result back to the main loop with rtxui::PostTask(...), which may be called from any thread. State mutations posted this way are picked up by the normal digest cycle; a task posted after the application exited is dropped.
A detached thread must not outlive the component it captures. In real applications, join or signal worker threads before the component is destroyed, or route results through state that survives the component.
Confirmation dialog
The built-in <dialog> element renders centered above the rest of the interface with a dimmed backdrop, and closes on Escape. Bind its open attribute to a boolean and flip that boolean from methods.
To build an overlay by hand instead — a dropdown, a toast, a context menu — use position: absolute (or fixed) with z-index inside a position: relative ancestor, and gate it behind an <if>. The positioning guide covers the mechanics.

