ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
01_hello_markup/main.cpp

Example from examples/01_hello_markup/.

Example from examples/01_hello_markup/.

#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