#include "ExampleHost.hpp"
#include <memory>
#include <string>
using namespace ZenitUI;
static constexpr const char *kStyle = R"zs(
:root {
font: inter;
font-size: 14px;
letter-spacing: 0px;
color: #E2E8F0;
}
.app {
width: 100%;
height: 100%;
background: #0D1017;
}
.topbar {
width: 100%;
min-height: 54px;
background: #141824;
border-bottom: 1px;
border-color: #252C3D;
padding: 12px 20px;
gap: 12px;
justify: space-between;
align-items: center;
}
.brand {
font: inter-bold;
font-size: 17px;
color: #F8FAFC;
flex: 1;
min-width: 0px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.hint {
font-size: 12px;
color: #94A3B8;
}
.footer-hint {
font-size: 12px;
color: #94A3B8;
flex: 1;
min-width: 0px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.body {
width: 100%;
flex: 1;
min-height: 0px;
direction: row;
}
.sidebar {
width: 220px;
background: #121621;
border-right: 1px;
border-color: #232A3B;
padding: 16px;
gap: 8px;
}
.nav-item {
width: 100%;
padding: 9px 12px;
radius: 8px;
background: transparent;
color: #94A3B8;
cursor: pointer;
align-items: start;
transition-time: 0.1;
}
.nav-item:hover {
background: #1C2233;
color: #F8FAFC;
}
.nav-item.active {
background: #1E3A5F;
color: #7DD3FC;
}
.main {
flex: 1;
min-width: 0px;
min-height: 0px;
padding: 20px;
overflow-x: hidden;
overflow-y: auto;
}
.kpi-row {
width: 100%;
gap: 14px;
wrap: true;
}
.kpi-card {
flex: 1;
min-width: 190px;
background: #161B28;
border-width: 1px;
border-color: #262E42;
radius: 10px;
padding: 16px;
gap: 6px;
overflow: hidden;
}
.kpi-num {
font: inter-bold;
font-size: 24px;
color: #38BDF8;
}
.section {
width: 100%;
background: #161B28;
border-width: 1px;
border-color: #262E42;
radius: 10px;
padding: 16px;
gap: 12px;
}
.section-title {
font: inter-semibold;
font-size: 15px;
color: #F1F5F9;
}
.chip-wrap {
width: 100%;
wrap: true;
gap: 8px;
align-items: center;
}
.chip {
padding: 6px 12px;
radius: 999px;
background: #1F2638;
border-width: 1px;
border-color: #323D57;
font-size: 12px;
color: #CBD5E1;
}
.center-stage {
width: 100%;
height: 110px;
background: #10141F;
border-width: 1px;
border-color: #252D40;
radius: 8px;
padding: 12px;
}
.auto-box {
padding: 12px 18px;
margin: auto;
radius: 8px;
background: #1D4ED8;
align-items: center;
}
.footer {
width: 100%;
height: 36px;
background: #11141E;
border-top: 1px;
border-color: #222838;
padding: 0px 20px;
gap: 12px;
justify: space-between;
align-items: center;
}
/* Responsive collapse when window width <= 820px */
@media (max-width: 820px) {
.body {
direction: column;
}
.sidebar {
width: 100%;
direction: row;
border-right: 0px;
border-bottom: 1px;
padding: 10px 14px;
wrap: true;
}
.nav-item {
width: auto;
}
}
)zs";
static constexpr const char *kMarkup = R"zm(
VStack.app {
HStack.topbar {
Text.brand "ZenitUI — Responsive Flex Dashboard"
Text.hint@vp "1040 x 660"
}
HStack.body {
VStack.sidebar {
Button.nav-item.active@nav0 "Overview"
Button.nav-item@nav1 "Telemetry"
Button.nav-item@nav2 "Storage"
Button.nav-item@nav3 "Settings"
}
ScrollView.main {
VStack width="100%" gap="16px" {
HStack.kpi-row {
VStack.kpi-card {
Text.hint "ACTIVE SECTION"
Text.kpi-num@section "Overview"
}
VStack.kpi-card {
Text.hint "LAYOUT ENGINE"
Text.kpi-num "Flex + Wrap"
}
VStack.kpi-card {
Text.hint "MEDIA QUERY"
Text.kpi-num@mode "Desktop"
}
}
VStack.section {
Text.section-title wrap="true" "Wrapping HStack (wrap: true)"
HStack.chip-wrap {
Text.chip "VStack"
Text.chip "HStack"
Text.chip "Stack"
Text.chip "flex: 1"
Text.chip "min-width: 190px"
Text.chip "margin: auto"
Text.chip "justify: space-between"
Text.chip "align-items: stretch"
Text.chip "@media (max-width: 820px)"
}
}
VStack.section {
Text.section-title wrap="true" "margin: auto Centering"
Stack.center-stage {
VStack.auto-box {
Text "Centered with margin: auto"
}
}
}
}
}
}
HStack.footer {
Text.footer-hint "Resize window horizontally to inspect responsive flex & wrapping"
Text.hint@backend ""
}
}
)zm";
int main()
{
cfg.
title =
"ZenitUI 02 — Responsive Flex Layout";
std::weak_ptr<UI::Text> vpLbl;
std::weak_ptr<UI::Text> modeLbl;
return ZenitExample::runApp(
cfg,
ZenitExample::loadDefaultFonts(ctx);
auto ui = ZMarkup::build(kMarkup, ctx);
ui.setTextRef(
"backend", std::string(backend.
name()));
std::weak_ptr<UI::Text> sectionLbl = ui.
ref<
UI::Text>(
"section");
const char *refs[] = {"nav0", "nav1", "nav2", "nav3"};
const char *names[] = {"Overview", "Telemetry", "Storage", "Settings"};
auto navButtons = std::make_shared<std::vector<std::weak_ptr<Layout>>>();
for (const char *r : refs)
navButtons->push_back(ui.ref(r));
for (size_t i = 0; i < 4; ++i)
{
std::string label = names[i];
ui.onClickRef(refs[i], [i, label, navButtons, sectionLbl]() {
for (size_t j = 0; j < navButtons->size(); ++j)
{
if (auto b = (*navButtons)[j].lock())
{
if (j == i)
b->addClass("active");
else
b->removeClass("active");
}
}
if (auto s = sectionLbl.lock())
s->setText(label);
});
}
return ui.root();
},
const int w =
static_cast<int>(ctx.
viewport.
x);
const int h =
static_cast<int>(ctx.
viewport.
y);
if (auto vp = vpLbl.lock())
vp->setText(std::to_string(w) + " x " + std::to_string(h));
if (auto m = modeLbl.lock())
m->setText(w <= 820 ? "Compact" : "Desktop");
});
}
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
Vec2 viewport
Current logical viewport dimensions.
Definition UIContext.hpp:899
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