#include "ExampleHost.hpp"
#include <cmath>
#include <cstdio>
#include <memory>
#include <string>
#include <vector>
using namespace ZenitUI;
static constexpr const char *kStyle = R"zs(
:root {
font: inter;
font-size: 13px;
letter-spacing: 0px;
color: #E5E7EB;
}
.workspace {
width: 100%;
height: 100%;
background: #0F1219;
}
/* ---- MenuBar & Menus ---- */
MenuBar {
width: 100%;
background: #151924;
border-width: 0px 0px 1px 0px;
border-color: #262D40;
padding: 3px 8px;
gap: 4px;
}
MenuBar .menubar-button {
padding: 5px 10px;
radius: 5px;
color: #CBD5E1;
background: transparent;
border-width: 0px;
}
MenuBar .menubar-button:hover {
background: #232A3D;
color: #F8FAFC;
}
MenuBar .menubar-button:checked {
background: #2563EB;
color: #FFFFFF;
}
Menu .menu-list {
background: #181D2A;
border-width: 1px;
border-color: #2E3750;
radius: 7px;
padding: 4px;
box-shadow: 0px 8px 20px #00000088;
}
MenuItem.active {
background: #2563EB;
color: #FFFFFF;
}
MenuItem:disabled {
opacity: 0.45;
}
/* ---- SplitPane ---- */
SplitPane {
background: #0F1219;
}
SplitPane::splitter {
background: #1E2433;
color: #64748B;
}
/* ---- Left Explorer Pane ---- */
.pane {
width: 100%;
height: 100%;
background: #131722;
}
.pane-header {
width: 100%;
padding: 7px 10px;
gap: 6px;
align-items: center;
background: #171C29;
border-width: 0px 0px 1px 0px;
border-color: #232A3C;
}
.pane-title {
font: inter-semibold;
font-size: 11px;
letter-spacing: 0.8px;
color: #94A3B8;
grow: 1;
}
TreeView {
width: 100%;
grow: 1;
min-height: 0;
background: #131722;
padding: 6px;
gap: 2px;
}
TreeRow:hover {
background: #1E2538;
}
TreeRow:checked {
background: #1D4ED8;
color: #FFFFFF;
}
/* ---- TabView & Tabs ---- */
TabView {
width: 100%;
height: 100%;
background: #111520;
}
TabBar {
background: #151A26;
border-width: 0px 0px 1px 0px;
border-color: #232A3C;
padding: 5px 8px;
gap: 6px;
}
TabBar .tab-button {
padding: 6px 12px;
radius: 6px;
background: #1B2130;
color: #94A3B8;
border-width: 1px;
border-color: #262E42;
}
TabBar .tab-button:hover {
background: #242C40;
color: #F1F5F9;
}
TabBar .tab-button:checked {
background: #2563EB;
border-color: #3B82F6;
color: #FFFFFF;
}
TabContent {
padding: 12px;
min-height: 0;
}
Tab {
width: 100%;
height: 100%;
min-height: 0;
gap: 10px;
}
/* ---- Toolbar & Buttons ---- */
.toolbar {
width: 100%;
gap: 6px;
wrap: true;
align-items: center;
}
Button.chip {
padding: 5px 10px;
radius: 6px;
background: #1B2132;
border-width: 1px;
border-color: #2D364D;
color: #CBD5E1;
font-size: 12px;
}
Button.chip:hover {
background: #252E45;
border-color: #38BDF8;
}
Button.chip:checked {
background: #2563EB;
border-color: #60A5FA;
color: #FFFFFF;
}
Button.mini {
padding: 3px 8px;
radius: 5px;
background: #1F2638;
border-width: 1px;
border-color: #303A52;
color: #CBD5E1;
font-size: 11px;
}
Button.mini:hover {
background: #2A334B;
border-color: #38BDF8;
}
/* ---- Image Preview Stage ---- */
.preview-stage {
width: 100%;
grow: 1;
min-height: 0;
background: #0B0E14;
border-width: 1px;
border-color: #262E42;
radius: 8px;
padding: 14px;
}
/* ---- Virtual Tree (FlatTreeModel + VirtualView) ---- */
.vtree-host {
width: 100%;
grow: 1;
min-height: 0;
background: #0D1119;
border-width: 1px;
border-color: #252D40;
radius: 8px;
padding: 4px;
}
.vtree-row {
width: 100%;
height: 100%;
align-items: center;
gap: 6px;
radius: 4px;
cursor: pointer;
}
.vtree-row:hover {
background: #1B2335;
}
.vtree-row:checked {
background: #1D4ED8;
color: #FFFFFF;
}
.vtree-toggle {
width: 18px;
height: 18px;
padding: 0px;
background: transparent;
border-width: 0px;
color: #94A3B8;
font-size: 11px;
}
.vtree-badge {
padding: 1px 6px;
radius: 4px;
background: #1E293B;
color: #7DD3FC;
font-size: 11px;
}
/* ---- Notes / Info Cards ---- */
.info-card {
width: 100%;
padding: 14px 16px;
radius: 8px;
background: #161B28;
border-width: 1px;
border-color: #262E42;
gap: 6px;
}
.card-heading {
font: inter-semibold;
font-size: 14px;
color: #F8FAFC;
}
.muted {
font-size: 12px;
color: #94A3B8;
}
/* ---- Bottom Log Pane & Status Bar ---- */
.log-scroll {
width: 100%;
grow: 1;
min-height: 0;
padding: 6px 10px;
background: #0E1118;
}
.log-line {
font-size: 12px;
color: #CBD5E1;
}
.statusbar {
width: 100%;
padding: 5px 12px;
gap: 16px;
align-items: center;
background: #151924;
border-width: 1px 0px 0px 0px;
border-color: #262D40;
}
.status-item {
font-size: 12px;
color: #94A3B8;
}
.status-accent {
font: inter-semibold;
font-size: 12px;
color: #7DD3FC;
}
)zs";
static constexpr const char *kMarkup = R"zm(
VStack.workspace {
MenuBar@menubar {
Menu title="File" {
MenuItem@mi-expand-tree label="Expand Project Tree" shortcut="Ctrl+E"
MenuItem@mi-collapse-tree label="Collapse Project Tree" shortcut="Ctrl+W"
MenuSeparator
MenuItem@mi-clear-log label="Clear Output Log" shortcut="Ctrl+L"
MenuSeparator
MenuItem label="Disabled Action" disabled="true"
}
Menu title="View" {
MenuItem@mi-tab-bottom label="Tab Bar at Bottom" checkable="true" checked="false"
MenuItem@mi-crop-img label="Crop Texture (sourceRect)" checkable="true" checked="false"
MenuSeparator
MenuItem label="Image Fit" {
MenuItem@mi-fit-fill label="Fill"
MenuItem@mi-fit-contain label="Contain"
MenuItem@mi-fit-cover label="Cover"
MenuItem@mi-fit-none label="None (1:1)"
MenuItem@mi-fit-scaledown label="Scale Down"
}
MenuSeparator
MenuItem@mi-reset-split label="Reset Split Layout"
}
Menu title="Tabs" {
MenuItem@mi-tab-0 label="1. Image Preview" shortcut="Alt+1"
MenuItem@mi-tab-1 label="2. Virtual Tree (5,550)" shortcut="Alt+2"
MenuItem@mi-tab-2 label="3. Shortcuts & Info" shortcut="Alt+3"
}
}
SplitPane@main-split orientation="horizontal" ratio="0.26" splitter-size="6" min-pane-size="180" width="100%" grow="1" min-height="0" {
VStack.pane {
HStack.pane-header {
Text.pane-title "EXPLORER (TreeView)"
Button.mini@btn-tree-expand "+"
Button.mini@btn-tree-collapse "-"
}
TreeView@project-tree indent="18" {
TreeItem@ti-root label="Workspace" value="workspace" expanded="true" {
TreeItem label="Textures" value="textures" expanded="true" {
TreeItem@ti-full label="npatches_y.png (Full)" value="tex:full" selected="true"
TreeItem@ti-crop label="npatches_y.png (Cropped)" value="tex:crop"
}
TreeItem@ti-lazy label="Remote Assets (Lazy)" value="remote" expandable="true"
TreeItem label="Virtual Data" value="vdata" {
TreeItem label="5,550-Node Catalog" value="tab:vtree"
}
TreeItem label="Docs" value="docs" {
TreeItem label="Shortcuts & Controls" value="tab:info"
}
}
}
HStack padding="6px 10px" {
Text.muted wrap="true" "Tip: Right-click any item for a structured ContextMenu."
}
}
SplitPane@right-split orientation="vertical" ratio="0.74" splitter-size="6" min-pane-size="110" width="100%" height="100%" {
TabView@tabs selected="0" position="top" {
Tab title="Image Preview" {
HStack.toolbar {
Text.muted "ObjectFit:"
Button.chip@btn-fit-fill "Fill"
Button.chip@btn-fit-contain "Contain"
Button.chip@btn-fit-cover "Cover"
Button.chip@btn-fit-none "None"
Button.chip@btn-fit-scaledown "ScaleDown"
Spacer grow="1"
Button.chip@btn-toggle-crop "sourceRect Crop: OFF"
}
Stack.preview-stage {
ImageContainer@preview-img fit="contain" width="100%" height="100%"
}
Text.muted@preview-info wrap="true" "Mode: contain | sourceRect: full texture"
}
Tab title="Virtual Tree (5,550)" {
HStack.toolbar {
Text.muted@vtree-stats grow="1" "Projected rows: 0 / 5,550"
Button.mini@btn-vt-expand "Expand All"
Button.mini@btn-vt-collapse "Collapse All"
Button.mini@btn-vt-top "Top"
Button.mini@btn-vt-bottom "Bottom"
}
Stack.vtree-host {
VirtualView@vtree uniform-height="30" width="100%" height="100%"
}
}
Tab title="Shortcuts & Info" {
ScrollView width="100%" grow="1" min-height="0" {
VStack width="100%" gap="10px" {
VStack.info-card {
Text.card-heading "MenuBar & ContextMenu"
Text.muted wrap="true" "Click a top-level menu to open it, then hover adjacent menus to switch. Use Up/Down/Left/Right/Enter/Escape for full keyboard navigation including nested submenus."
}
VStack.info-card {
Text.card-heading "SplitPane"
Text.muted wrap="true" "Drag either divider bar (cursor switches to ew-resize / ns-resize). Focus a SplitPane and use Arrow keys (or Shift+Arrows for 1% fine steps)."
}
VStack.info-card {
Text.card-heading "TreeView & FlatTreeModel"
Text.muted wrap="true" "The left sidebar uses retained TreeView/TreeItem nodes with expandable=\"true\" lazy loading. Tab 2 projects 5,550 C++ structs through FlatTreeModel onto a uniform-height VirtualView."
}
}
}
}
}
VStack.pane {
HStack.pane-header {
Text.pane-title "OUTPUT LOG"
Button.mini@btn-clear-log "Clear"
}
ScrollView.log-scroll@log-scroll {
VStack@log-list width="100%" gap="4px" {}
}
}
}
}
HStack.statusbar {
Text.status-accent@status-selection "Selected: npatches_y.png (Full)"
Spacer grow="1"
Text.status-item@status-split "Split: 26% / 74%"
Text.status-item@status-tab "Tab: Image Preview"
}
}
)zm";
namespace
{
struct CatalogNode
{
int id{0};
std::string kind;
std::string name;
std::vector<CatalogNode> children;
};
std::vector<CatalogNode> buildLargeCatalog()
{
std::vector<CatalogNode> roots;
roots.reserve(50);
int nextId = 1;
for (int m = 1; m <= 50; ++m)
{
CatalogNode mod{nextId++, "MOD", "Module_" + std::to_string(m), {}};
mod.children.reserve(10);
for (int g = 1; g <= 10; ++g)
{
CatalogNode grp{nextId++, "GRP", "Group_" + std::to_string(m) + "_" + std::to_string(g), {}};
grp.children.reserve(10);
for (int s = 1; s <= 10; ++s)
{
grp.children.push_back(CatalogNode{
nextId++,
"SYM",
"Asset_" + std::to_string(m) + "_" + std::to_string(g) + "_" + std::to_string(s),
{}});
}
mod.children.push_back(std::move(grp));
}
roots.push_back(std::move(mod));
}
return roots;
}
{
switch (fit)
{
}
return "fill";
}
struct WorkspaceState
{
bool cropEnabled{false};
bool lazyLoaded{false};
int logCounter{0};
std::vector<CatalogNode> catalogRoots;
bool vtreeDirty{true};
std::weak_ptr<UI::TreeItem> contextTarget;
std::shared_ptr<UI::Menu> itemContextMenu;
std::shared_ptr<UI::MenuItem> ctxToggleItem;
std::shared_ptr<UI::Menu> bgContextMenu;
WorkspaceState()
: catalogRoots(buildLargeCatalog()),
flatModel(
[](const CatalogNode &n) { return n.id; },
[](const CatalogNode &n) -> const auto & { return n.children; })
{
flatModel.
setRoots(catalogRoots,
false);
if (!catalogRoots.empty())
flatModel.
setExpanded(catalogRoots.front().id,
true,
false);
}
};
const std::shared_ptr<WorkspaceState> &state,
const std::shared_ptr<UI::TreeItem> &item)
{
if (!item)
return;
if (auto row = item->row())
{
std::weak_ptr<UI::TreeItem> weakItem = item;
row->onRightClick = [&ctx, state, uiWeak, weakItem]()
{
auto it = weakItem.lock();
if (!it)
return;
state->contextTarget = it;
if (auto locked = uiWeak.lock())
tv->selectItem(it, true);
if (state->bgContextMenu && state->bgContextMenu->isOpen())
state->bgContextMenu->close();
if (state->ctxToggleItem)
{
const bool canExpand = it->isExpandable();
state->ctxToggleItem->setEnabled(canExpand);
state->ctxToggleItem->setLabel(
canExpand ? (it->isExpanded() ? "Collapse" : "Expand") : "Expand / Collapse");
}
if (state->itemContextMenu)
state->itemContextMenu->openAt(ctx.
pointer.
pos);
};
}
for (const auto &ch : item->childItems())
wireItemContextMenu(ctx, state, uiWeak, ch);
}
}
int main()
{
cfg.
title =
"ZenitUI 14 — Desktop Workspace";
auto state = std::make_shared<WorkspaceState>();
std::weak_ptr<UI::VirtualView> vtreeWeak;
std::weak_ptr<UI::Text> vtreeStatsWeak;
auto flushVirtualTree = [state, &vtreeWeak, &vtreeStatsWeak]()
{
if (!state->vtreeDirty)
return;
state->vtreeDirty = false;
if (auto vt = vtreeWeak.lock())
{
const int count = static_cast<int>(state->flatModel.count());
vt->removeAllChildren();
if (vt->getItemCount() == count)
vt->setItemCount(0);
vt->setItemCount(count);
}
if (auto lbl = vtreeStatsWeak.lock())
{
std::string selInfo;
if (auto key = state->flatModel.selectedKey())
{
const int idx = state->flatModel.findRowByKey(*key);
if (idx >= 0)
selInfo = " | Selected: " + state->flatModel.at(static_cast<size_t>(idx)).node->name;
}
lbl->setText("Projected rows: " + std::to_string(state->flatModel.count()) +
" / 5,550" + selInfo);
}
};
return ZenitExample::runApp(
cfg,
[state, &vtreeWeak, &vtreeStatsWeak](
UIContext &ctx,
IBackend &backend) -> std::shared_ptr<Layout>
{
ZenitExample::loadDefaultFonts(ctx);
auto &assets = backend.
assets();
assets.
loadTexture(
"workspace_preview", ZenitExample::assetPath(
"assets/images/npatches_y.png"));
state->previewTex = assets.getTexture("workspace_preview");
for (
const auto &d : styleSink.
diagnostics())
std::fprintf(stderr, "[14_desktop_workspace][zstyle] %s\n", d.message.c_str());
auto ui = ZMarkup::build(kMarkup, ctx, &markupSink);
for (const auto &d : markupSink.diagnostics())
std::fprintf(stderr, "[14_desktop_workspace][zmarkup] %s\n", d.message.c_str());
ui.root()->retainObject(state);
auto appendLog = [uiWeak, state](const std::string &msg)
{
auto locked = uiWeak.
lock();
if (!locked)
return;
auto list = locked->ref("log-list");
if (!list)
return;
++state->logCounter;
auto line =
UI::Text::create(
"[" + std::to_string(state->logCounter) +
"] " + msg);
line->addClass("log-line");
line->setWrap(true);
list->addChild(line);
while (list->children.size() > 60)
list->removeChild(list->children.front().get());
if (scroll)
scroll->scrollToBottom();
};
if (previewImg && state->previewTex.valid())
auto syncImagePreview = [uiWeak, state]()
{
auto locked = uiWeak.lock();
if (!locked)
return;
{
img->setObjectFit(state->currentFit);
if (state->cropEnabled && state->previewTex.valid())
{
const float tw = static_cast<float>(state->previewTex.width);
const float th = static_cast<float>(state->previewTex.height);
img->setSourceRect({tw * 0.18f, th * 0.18f, tw * 0.64f, th * 0.64f});
}
else
{
img->clearSourceRect();
}
}
const std::pair<const char *, UI::ObjectFit> fitButtons[] = {
};
for (const auto &[refName, mode] : fitButtons)
{
b->setChecked(state->currentFit == mode);
}
if (
auto cropBtn = locked->ref<
UI::Button>(
"btn-toggle-crop"))
{
cropBtn->setChecked(state->cropEnabled);
cropBtn->setText(state->cropEnabled ? "sourceRect Crop: ON" : "sourceRect Crop: OFF");
}
cropMi->setItemChecked(state->cropEnabled, false);
std::string info = std::string("Mode: ") + fitModeName(state->currentFit) + " | sourceRect: ";
if (state->cropEnabled && state->previewTex.valid())
info += "center 64% crop";
else
info += "full texture (" + std::to_string(state->previewTex.width) + "x" +
std::to_string(state->previewTex.height) + ")";
locked->setTextRef("preview-info", info);
};
auto setFitMode = [state, syncImagePreview, appendLog](
UI::ObjectFit mode)
{
state->currentFit = mode;
syncImagePreview();
appendLog(std::string("ImageContainer ObjectFit -> ") + fitModeName(mode));
};
ui.onClickRef("btn-toggle-crop", [state, syncImagePreview, appendLog]()
{
state->cropEnabled = !state->cropEnabled;
syncImagePreview();
appendLog(state->cropEnabled ? "Enabled ImageContainer sourceRect crop"
: "Cleared ImageContainer sourceRect (full texture)");
});
auto updateSplitStatus = [uiWeak]()
{
auto locked = uiWeak.lock();
if (!locked)
return;
if (!hSplit || !vSplit)
return;
const int hr = static_cast<int>(std::lround(hSplit->getRatio() * 100.0f));
const int vr =
static_cast<int>(std::lround(vSplit->
getRatio() * 100.0f));
locked->setTextRef("status-split", "Split: " + std::to_string(hr) + "% / " + std::to_string(vr) + "%");
};
hSplit->onRatioChanged = [updateSplitStatus](float) { updateSplitStatus(); };
vSplit->
onRatioChanged = [updateSplitStatus](float) { updateSplitStatus(); };
if (tabs)
{
tabs->onTabChanged = [uiWeak, appendLog](int idx)
{
if (auto locked = uiWeak.lock())
{
{
const std::string title = tv->getTabTitle(idx);
locked->setTextRef("status-tab", "Tab: " + title);
appendLog("Switched active tab -> " + title);
}
}
};
}
UI::MenuEntry::action("Expand / Collapse", [state, appendLog]()
{
if (auto it = state->contextTarget.lock(); it && it->isExpandable())
{
it->toggleExpanded(true);
appendLog("Toggled branch '" + it->getLabel() + "' from ContextMenu");
}
}),
UI::MenuEntry::action("Log Item Path", [state, appendLog]()
{
if (auto it = state->contextTarget.lock())
appendLog("Context inspect -> label='" + it->getLabel() + "', value='" + it->getValue() + "'");
}),
UI::MenuEntry::separator(),
UI::MenuEntry::submenu("Tree Actions", {
UI::MenuEntry::action("Expand All", [uiWeak, appendLog]()
{
if (auto locked = uiWeak.lock())
tv->expandAll();
appendLog("Expanded entire project tree");
}),
UI::MenuEntry::action("Collapse All", [uiWeak, appendLog]()
{
if (auto locked = uiWeak.lock())
tv->collapseAll();
appendLog("Collapsed project tree");
}),
}),
});
if (!state->itemContextMenu->items().empty())
state->ctxToggleItem = state->itemContextMenu->items().front();
ui.root()->addChild(state->itemContextMenu);
UI::MenuEntry::action("Expand All", [uiWeak, appendLog]()
{
if (auto locked = uiWeak.lock())
tv->expandAll();
appendLog("Expanded entire project tree");
}),
UI::MenuEntry::action("Collapse All", [uiWeak, appendLog]()
{
if (auto locked = uiWeak.lock())
tv->collapseAll();
appendLog("Collapsed project tree");
}),
});
ui.root()->addChild(state->bgContextMenu);
if (tree)
{
for (const auto &r : tree->rootItems())
wireItemContextMenu(ctx, state, uiWeak, r);
tree->onRightClick = [&ctx, state]()
{
state->contextTarget.reset();
if (state->itemContextMenu && state->itemContextMenu->isOpen())
state->itemContextMenu->close();
if (state->bgContextMenu)
state->bgContextMenu->openAt(ctx.pointer.pos);
};
tree->onSelectionChanged = [uiWeak, state, syncImagePreview, appendLog](std::shared_ptr<UI::TreeItem> it)
{
auto locked = uiWeak.lock();
if (!locked || !it)
return;
locked->setTextRef("status-selection", "Selected: " + it->getLabel());
appendLog("Tree selected: " + it->getLabel() + " (" + it->getValue() + ")");
if (it->getValue() == "tex:full")
{
state->cropEnabled = false;
syncImagePreview();
if (tv) tv->setActiveTab(0, true);
}
else if (it->getValue() == "tex:crop")
{
state->cropEnabled = true;
syncImagePreview();
if (tv) tv->setActiveTab(0, true);
}
else if (it->getValue() == "tab:vtree")
{
if (tv) tv->setActiveTab(1, true);
}
else if (it->getValue() == "tab:info")
{
if (tv) tv->setActiveTab(2, true);
}
};
tree->onItemActivated = [appendLog](std::shared_ptr<UI::TreeItem> it)
{
if (it)
appendLog("Tree item activated (double-click / Enter): " + it->getLabel());
};
auto lazyRef = std::weak_ptr<UI::TreeItem>(ui.ref<
UI::TreeItem>(
"ti-lazy"));
tree->onItemToggled = [&ctx, state, uiWeak, lazyRef, appendLog](std::shared_ptr<UI::TreeItem> it, bool expanded)
{
if (!it)
return;
auto lazy = lazyRef.lock();
if (expanded && lazy && it.get() == lazy.get() && !state->lazyLoaded)
{
state->lazyLoaded = true;
auto a = it->addItem("Dungeon_Tileset.png", "remote:dungeon");
auto b = it->addItem("Tavern_Ambient.ogg", "remote:audio");
auto c = it->addItem("Campaign_Schema.json", "remote:schema");
wireItemContextMenu(ctx, state, uiWeak, a);
wireItemContextMenu(ctx, state, uiWeak, b);
wireItemContextMenu(ctx, state, uiWeak, c);
appendLog("Lazy-loaded 3 remote assets into 'Remote Assets (Lazy)'");
}
else
{
appendLog(std::string(expanded ? "Expanded" : "Collapsed") + " '" + it->getLabel() + "'");
}
};
}
ui.onClickRef("btn-tree-expand", [uiWeak, appendLog]()
{
if (auto locked = uiWeak.lock())
tv->expandAll();
appendLog("Expanded project tree");
});
ui.onClickRef("btn-tree-collapse", [uiWeak, appendLog]()
{
if (auto locked = uiWeak.lock())
tv->collapseAll();
appendLog("Collapsed project tree");
});
{
mi->onTriggered = [uiWeak, appendLog]()
{
if (auto locked = uiWeak.lock())
tv->expandAll();
appendLog("Menu: Expand Project Tree");
};
}
{
mi->onTriggered = [uiWeak, appendLog]()
{
if (auto locked = uiWeak.lock())
tv->collapseAll();
appendLog("Menu: Collapse Project Tree");
};
}
auto clearLog = [uiWeak, state]()
{
if (auto locked = uiWeak.lock())
{
if (auto list = locked->ref("log-list"))
list->removeAllChildren();
state->logCounter = 0;
}
};
ui.onClickRef("btn-clear-log", clearLog);
mi->onTriggered = clearLog;
{
mi->onToggle = [uiWeak, appendLog](bool bottom)
{
if (auto locked = uiWeak.lock())
appendLog(bottom ? "TabView bar moved to Bottom" : "TabView bar moved to Top");
};
}
{
mi->onToggle = [state, syncImagePreview, appendLog](bool crop)
{
state->cropEnabled = crop;
syncImagePreview();
appendLog(crop ? "Menu: Enabled sourceRect crop" : "Menu: Cleared sourceRect crop");
};
}
{
mi->onTriggered = [uiWeak, appendLog]()
{
if (auto locked = uiWeak.lock())
{
if (
auto h = locked->ref<
UI::SplitPane>(
"main-split")) h->setRatio(0.26f,
true);
if (
auto v = locked->ref<
UI::SplitPane>(
"right-split")) v->setRatio(0.74f,
true);
}
appendLog("SplitPane ratios reset to 26% / 74%");
};
}
for (int i = 0; i < 3; ++i)
{
if (
auto mi = ui.ref<
UI::MenuItem>(
"mi-tab-" + std::to_string(i)))
{
mi->onTriggered = [uiWeak, i]()
{
if (auto locked = uiWeak.lock())
tv->setActiveTab(i, true);
};
}
}
vtreeWeak = vtree;
vtreeStatsWeak = ui.ref<
UI::Text>(
"vtree-stats");
state->flatModel.onChanged = [state]() { state->vtreeDirty = true; };
state->flatModel.onSelectionChanged = [state, appendLog](const std::optional<int> &key)
{
state->vtreeDirty = true;
if (key)
{
const int idx = state->flatModel.findRowByKey(*key);
if (idx >= 0)
appendLog("VirtualTree selected: " + state->flatModel.at(static_cast<size_t>(idx)).node->name);
}
};
if (vtree)
{
vtree->setItemFactory([state](int index) -> std::shared_ptr<Layout>
{
if (index < 0 || index >= static_cast<int>(state->flatModel.count()))
return nullptr;
const auto &rowData = state->flatModel.at(static_cast<size_t>(index));
const int key = rowData.key;
row->addClass("vtree-row");
row->setInteractive(true);
row->setSize(Percent(100.0f), Px(30.0f));
row->getInlineBase().padding =
Spacing(
Px(3.0f), Px(10.0f), Px(3.0f), Px(8.0f + static_cast<float>(rowData.depth) * 18.0f));
row->setChecked(state->flatModel.isSelected(key));
toggle->addClass("vtree-toggle");
toggle->setFocusable(false);
toggle->setInteractive(rowData.hasChildren);
toggle->setText(rowData.hasChildren ? (rowData.expanded ? "v" : ">") : "");
if (rowData.hasChildren)
{
toggle->onClick = [state, key]() { state->flatModel.toggle(key); };
}
badge->addClass("vtree-badge");
badge->setInteractive(false);
name->setInteractive(false);
name->getInlineDefaults().grow = 1.0f;
row->addChild(toggle);
row->addChild(badge);
row->addChild(name);
row->onClick = [state, key]() { state->flatModel.select(key); };
return row;
});
}
ui.onClickRef("btn-vt-expand", [state, appendLog]()
{
state->flatModel.expandAll();
appendLog("FlatTreeModel: expanded all 5,550 nodes");
});
ui.onClickRef("btn-vt-collapse", [state, appendLog]()
{
state->flatModel.collapseAll();
appendLog("FlatTreeModel: collapsed to 50 root modules");
});
ui.onClickRef("btn-vt-top", [vtreeWeak]()
{
if (auto vt = vtreeWeak.lock())
vt->scrollToItem(0);
});
ui.onClickRef("btn-vt-bottom", [vtreeWeak, state]()
{
if (auto vt = vtreeWeak.lock(); vt && !state->flatModel.empty())
vt->scrollToItem(static_cast<int>(state->flatModel.count()) - 1);
});
syncImagePreview();
updateSplitStatus();
appendLog("Workspace initialized — try MenuBar, SplitPane drag, lazy TreeView, ContextMenu, and 5,550-node Virtual Tree.");
return ui.root();
},
{
flushVirtualTree();
});
}
Sink that accumulates diagnostics in insertion order.
Definition Diagnostics.hpp:151
virtual TextureHandle loadTexture(std::string_view, std::string_view)
Optional runtime hook to load a 2D texture from disk under name.
Definition UIContext.hpp:460
Unified window, frame-loop, and subsystem host for interchangeable backends.
Definition Backend.hpp:49
virtual IAssetProvider & assets()=0
Access the underlying asset provider.
std::string ref
@ref for UINode::ref / refAll lookup.
Definition Layout.hpp:943
static std::shared_ptr< Text > create(Args &&...args)
Definition Layout.hpp:1410
Maintains expanded state, selection, keyboard navigation, and a flat projection of visible rows ready...
Definition FlatTreeModel.hpp:64
void setRoots(const Range &roots, bool notify=true)
Set root nodes from any iterable range of NodeT or pointers to NodeT.
Definition FlatTreeModel.hpp:102
bool setExpanded(const KeyT &key, bool expanded, bool notify=true)
Expand or collapse key.
Definition FlatTreeModel.hpp:143
A single-texture node supporting sub-rect cropping (sourceRect) and ObjectFit.
Definition ImageContainer.hpp:47
void setTexture(TextureHandle t)
Replace the texture.
Definition ImageContainer.hpp:61
Container dividing its area between two resizable child panes.
Definition SplitPane.hpp:40
std::function< void(float)> onRatioChanged
Fired whenever the user drags, steps via keyboard, or calls setRatio(r, true).
Definition SplitPane.hpp:111
Container displaying a strip of selectable tabs and one active page at a time.
Definition TabView.hpp:63
A read-only text node.
Definition Text.hpp:32
Single hierarchical item inside a TreeView or another TreeItem.
Definition TreeView.hpp:38
Scrollable tree container with selection, expand/collapse, and keyboard navigation.
Definition TreeView.hpp:157
A virtualized list.
Definition VirtualView.hpp:55
Non-owning handle to a UINode, safe to capture inside child callbacks.
Definition ZMarkup.hpp:757
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.
Four-sided Value tuple used for padding, margin and border-width.
Definition Style.hpp:486
Opaque handle to a GPU/software texture owned by the asset provider.
Definition CoreTypes.hpp:127
Per-instance UI context: backends, theme, text engine, frame state, and routing.
Definition UIContext.hpp:725
ZMarkup::Registry & markupRegistry()
Return this context's isolated ZMarkup::Registry, lazily initialized with built-in widgets.
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