ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
ZenitUI 1.0 — Guide & API Reference

ZenitUI is a retained-mode C++20 UI framework with a Flexbox & 2D Grid layout engine, a CSS-like styling language (ZStyle), a declarative UI DSL (ZMarkup), full Unicode/Bidi text shaping, and pluggable rendering/platform backends.

Mental Model

  1. One node type: every container and widget derives from ZenitUI::Layout (typically via the CRTP helper ZenitUI::TLayout).
  2. Per-instance state in UIContext: create a ZenitUI::UIContext, bind a backend via IBackend::initAndBind(cfg, ctx) (or ctx.attachBackend(...)), load fonts/textures/shaders through the unified UIContext asset facade (ctx.loadFont, ctx.loadTexture, ctx.loadEffectAsset), and mount your root tree with ctx.mount(root).
  3. Four-pass frame cycle:
    • ctx.runFrame(dt) runs update (input, Drag & Drop, style transitions, animations, cursor/IME sync), measure (bottom-up), and arrange (top-down) on the mounted root.
    • ctx.renderFrame() runs beginFrame, draw (clips, off-screen layers, LayerCache, portals, drag ghosts), and endFrame.
  4. Imperative or declarative — same tree: build nodes with the fluent C++ API or with per-context ZMarkup (ZMarkup::build(src, ctx), ctx.markupRegistry().instantiate(...)), and style both with .zstyle stylesheets loaded into ctx.theme.

Quick Start (Hello Markup)

Directly from examples/01_hello_markup/main.cpp (compiled against every registered backend in CI):

#include "ExampleHost.hpp"
#include <memory>
#include <string>
using namespace ZenitUI;
static constexpr const char *kStyle = R"zs(
:root {
font: inter;
font-size: 15px;
letter-spacing: 0px;
color: #E6E8F0;
}
.page {
width: 100%;
height: 100%;
justify: center;
align-items: center;
background: #0F1117;
padding: 24px;
}
.card {
width: 100%;
max-width: 480px;
background: #171A23;
border-width: 1px;
border-color: #2A3040;
radius: 14px;
padding: 28px;
gap: 18px;
}
.badge {
background: #1E293B;
border-width: 1px;
border-color: #334155;
radius: 999px;
padding: 4px 12px;
font-size: 12px;
color: #7DD3FC;
}
.title {
font: inter-bold;
font-size: 26px;
color: #F8FAFC;
}
.subtitle {
font-size: 14px;
color: #94A3B8;
}
.counter-box {
width: 100%;
background: #11141C;
border-width: 1px;
border-color: #252B3B;
radius: 10px;
padding: 18px;
gap: 14px;
wrap: true;
justify: space-between;
align-items: center;
}
.counter-value {
font: inter-bold;
font-size: 32px;
color: #38BDF8;
}
Button.btn {
padding: 10px 18px;
radius: 8px;
background: #2563EB;
border-width: 1px;
border-color: #3B82F6;
color: #FFFFFF;
cursor: pointer;
transition-time: 0.12;
ease: ease-out-quad;
}
Button.btn:hover {
background: #3B82F6;
}
Button.btn:pressed {
background: #1D4ED8;
scale: 0.98;
}
Button.btn-ghost {
padding: 10px 16px;
radius: 8px;
background: #1E2230;
border-width: 1px;
border-color: #333B4F;
color: #CBD5E1;
cursor: pointer;
transition-time: 0.12;
}
Button.btn-ghost:hover {
background: #282E40;
color: #FFFFFF;
}
)zs";
static constexpr const char *kMarkup = R"zm(
VStack.page {
VStack.card {
HStack width="100%" justify="space-between" align-items="center" wrap="true" gap="8px" {
Text.badge "ZenitUI 1.0"
Text.badge@backend ""
}
VStack width="100%" gap="6px" {
Text.title wrap="true" "Hello, ZenitUI"
Text.subtitle wrap="true" "Declarative ZMarkup + ZStyle with zero global singletons and unified asset API."
}
HStack.counter-box {
VStack gap="2px" {
Text.subtitle "Interactive Clicks"
Text.counter-value@count "0"
}
HStack gap="10px" align-items="center" {
Button.btn@inc "+1 Click"
Button.btn-ghost@reset "Reset"
}
}
Text.subtitle@status wrap="true" "Ready — click the button or resize the window."
}
}
)zm";
int main()
{
cfg.title = "ZenitUI 01 — Hello Markup";
cfg.width = 760;
cfg.height = 520;
cfg.minWidth = 380;
cfg.minHeight = 360;
return ZenitExample::runApp(cfg, [](UIContext &ctx, IBackend &backend) -> std::shared_ptr<Layout> {
ZenitExample::loadDefaultFonts(ctx);
auto ui = ZMarkup::build(kMarkup, ctx);
ui.setTextRef("backend", std::string("Backend: ") + std::string(backend.name()));
auto clicks = std::make_shared<int>(0);
std::weak_ptr<UI::Text> countLbl = ui.ref<UI::Text>("count");
std::weak_ptr<UI::Text> statusLbl = ui.ref<UI::Text>("status");
auto refresh = [clicks, countLbl, statusLbl](const std::string &msg) {
if (auto c = countLbl.lock())
c->setText(std::to_string(*clicks));
if (auto s = statusLbl.lock())
s->setText(msg);
};
ui.onClickRef("inc", [clicks, refresh]() {
++(*clicks);
refresh("Button clicked " + std::to_string(*clicks) + " time(s).");
});
ui.onClickRef("reset", [clicks, refresh]() {
*clicks = 0;
refresh("Counter reset to zero.");
});
return ui.root();
});
}
Unified window, frame-loop, and subsystem host for interchangeable backends.
Definition Backend.hpp:49
virtual std::string_view name() const =0
Short human-readable backend identifier (e.g.
std::string ref
@ref for UINode::ref / refAll lookup.
Definition Layout.hpp:943
A read-only text node.
Definition Text.hpp:32
bool loadStyleString(std::string_view src, Theme &theme, const std::string &fileName="<string>", DiagnosticSink *sink=nullptr, bool strict=false, const Registry *registry=nullptr)
Parse src and apply it to theme.
Per-instance UI context: backends, theme, text engine, frame state, and routing.
Definition UIContext.hpp:725
Theme theme
Per-context stylesheet (rules, keyframes, and :root style).
Definition UIContext.hpp:911
Backend-agnostic window and graphics-context creation parameters.
Definition Backend.hpp:31

Browse by Topic

Module Contents Recommended Examples
Core, Layout & Lifecycle Layout, TLayout, Flexbox & 2D Grid, frame lifecycle, UIContext, compact Value units, Drag & Drop, cursors, scroll 02_layout_flex, 15_grid_dashboard, 09_drag_drop, 10_overlays_cursors, 13_i18n_rtl
Built-in Widgets Built-in widgets (Text, Button, TextInput, TextArea, Dropdown, Modal, VirtualList, Table, TabView, SplitPane, TreeView, MenuBar, ImageContainer, CanvasLayout, …) 04_widget_forms, 08_virtual_list, 14_desktop_workspace, 16_data_table, 10_overlays_cursors, 12_effects_canvas
ZMarkup, Prefabs & Data Binding Per-context ZMarkup DSL, UINode / WeakUINode, Prefabs & <Slot>, If / Each (keyed), Bindable<T> 01_hello_markup, 05_data_binding, 06_prefabs_slots, 07_dynamic_lists
ZStyle, Theme & Diagnostics .zstyle cascade, >, +, ~, *, :not(), Theme, custom properties, @media, dir:, linting & diagnostics 03_selectors_theme, 02_layout_flex, 15_grid_dashboard, 13_i18n_rtl
Animations, Transitions & Filters Transitions, @keyframes, imperative UIAnimation, FilterRegistry, LayerCache & shaders 11_animations, 12_effects_canvas
Backends, TextEngine, UTF-8 & Debugging Pluggable backends (IBackend, IRenderer, IPlatform, IAssetProvider), TextEngine (FreeType/HarfBuzz/SheenBidi), Utf8, Debug 01_hello_markup, 12_effects_canvas, 13_i18n_rtl, 00_demo

Suggested Reading Order

New to ZenitUI? Walk through the Examples tab in order:

  1. 01_hello_markup & 02_layout_flex — minimal app lifecycle, responsive Flexbox, and @media.
  2. 03_selectors_theme & 04_widget_forms — live CSS variable themes, combinators, and built-in form widgets.
  3. 05_data_binding, 06_prefabs_slots, 07_dynamic_lists & 08_virtual_list — Bindable<T>, reusable prefabs/slots, keyed Each, and 50k-row virtualization.
  4. 09_drag_drop, 10_overlays_cursors, 11_animations, 12_effects_canvas & 13_i18n_rtl — Drag & Drop, portals, cursors, animations, shaders/filters, and RTL/Bidi/CJK i18n.
  5. 14_desktop_workspace, 15_grid_dashboard & 16_data_table — desktop workspace shell (MenuBar, SplitPane, TabView, TreeView, FlatTreeModel, ImageContainer), responsive 2D Grid layouts, and 10k-row virtualized data tables.
  6. 00_demo — complete multi-tab end-to-end showcase.

Topic Guides

  • ZStyle Reference — Auto-generated reference of all ZStyle properties, value types, selectors, pseudo-classes, and @media features.
  • ZMarkup Reference — Auto-generated reference of ZMarkup syntax, universal/structural attributes, and built-in widgets.
  • Writing a Custom Backend — Implement IPlatform, IRenderer, IAssetProvider, and IBackend for your own engine or graphics API.
  • Available Backends — Auto-generated catalog of all built-in reference backends.