20#include <imgui_internal.h>
21#include <glm/mat4x4.hpp>
37std::vector<UIEvent> g_pending;
38std::vector<UIClick> g_clicks;
39std::vector<UIChange> g_changes;
40std::vector<UIDrop> g_drops;
41std::vector<std::string> g_pendingFileDrops;
42UIBackend *g_backend =
nullptr;
44float g_hudScale = 1.f;
45std::map<std::string, ViewportState> g_viewports;
47struct HostThemeScope {
53 explicit HostThemeScope(UIHost *
host) {
54 if (!
host || !
host->hasThemeOverride() || !
host->themeOverride())
return;
69 HostThemeScope(
const HostThemeScope &) =
delete;
70 HostThemeScope &operator=(
const HostThemeScope &) =
delete;
74constexpr auto hudMetrics = std::to_array<float UINode::*>(
80std::vector<std::array<float, hudMetrics.size()>> g_hudMetricScratch;
82struct HudCanvasScope {
93 auto meta =
host.meta();
94 if (!meta->canvas.enabled ||
host.worldAnchor()->enabled)
return;
95 const ImVec2 display = ImGui::GetIO().DisplaySize;
99 g_hudScale = transform.scale;
100 savedMeta = {meta->posX, meta->posY, meta->sizeX, meta->sizeY, meta->percentW, meta->percentH};
104 ImGui::GetStyle().ScaleAllSizes(transform.scale);
107 meta->posX = transform.x + meta->anchorX * (transform.width - display.x) + meta->posX * transform.scale;
108 meta->posY = transform.y + meta->anchorY * (transform.height - display.y) + meta->posY * transform.scale;
109 meta->sizeX *= transform.scale;
110 meta->sizeY *= transform.scale;
111 if (display.x > 0.f) meta->percentW *= transform.width / display.x;
112 if (display.y > 0.f) meta->percentH *= transform.height / display.y;
113 auto tree =
host.tree();
114 g_hudMetricScratch.resize(tree->nodes.size());
115 for (std::size_t i = 0; i < tree->nodes.size(); ++i) {
116 auto &
node = tree->nodes[i];
117 for (std::size_t
m = 0;
m < hudMetrics.size(); ++
m) {
119 g_hudMetricScratch[i][
m] =
value;
122 value *= transform.scale;
127 HudCanvasScope(
const HudCanvasScope &) =
delete;
128 HudCanvasScope &operator=(
const HudCanvasScope &) =
delete;
132 auto tree =
host.tree();
133 for (std::size_t i = 0; i < tree->nodes.size(); ++i)
134 for (std::size_t
m = 0;
m < hudMetrics.size(); ++
m)
135 tree->nodes[i].*hudMetrics[
m] = g_hudMetricScratch[i][
m];
136 auto meta =
host.meta();
144 ImGui::SetWindowFontScale(savedFontScale);
150struct ActiveDragPayload {
158std::optional<ActiveDragPayload> g_activeDrag;
159uint64_t g_nextDragSerial = 1;
161bool acceptsDropType(
const UINode &
node,
const std::string &
type) {
162 return node.dropTarget && (
node.acceptedDropType ==
"*" ||
node.acceptedDropType ==
type);
165void renderDragDrop(UIHost *
host,
const UINode &
node) {
169 const std::string hostName =
host->meta()->name;
170 if (
node.dragSource && !
node.dragPayloadType.empty() && ImGui::BeginDragDropSource()) {
171 if (!g_activeDrag || g_activeDrag->sourceHostName != hostName ||
172 g_activeDrag->sourceNodeId !=
node.id ||
173 g_activeDrag->payloadType !=
node.dragPayloadType ||
174 g_activeDrag->payloadText !=
node.dragPayloadText) {
175 g_activeDrag = ActiveDragPayload{g_nextDragSerial++, hostName,
node.id,
176 node.dragPayloadType,
node.dragPayloadText};
178 const uint64_t
serial = g_activeDrag->serial;
179 ImGui::SetDragDropPayload(
"EVE_UI_DND", &
serial,
sizeof(
serial), ImGuiCond_Once);
180 ImGui::TextUnformatted(
node.dragPayloadText.empty() ?
node.dragPayloadType.c_str()
181 :
node.dragPayloadText.c_str());
182 ImGui::EndDragDropSource();
185 if (
node.dropTarget && ImGui::BeginDragDropTarget()) {
186 const bool acceptsActive = g_activeDrag &&
187 acceptsDropType(
node, g_activeDrag->payloadType);
188 if (
const ImGuiPayload *
payload =
189 acceptsActive ? ImGui::AcceptDragDropPayload(
"EVE_UI_DND") : nullptr) {
190 if (
payload->IsDelivery() &&
payload->DataSize ==
int(
sizeof(uint64_t)) &&
192 const uint64_t
serial = *
static_cast<const uint64_t *
>(
payload->Data);
193 if (
serial == g_activeDrag->serial) {
195 g_activeDrag->sourceHostName,
196 g_activeDrag->sourceNodeId,
199 g_activeDrag->payloadType,
200 g_activeDrag->payloadText});
201 g_activeDrag.reset();
205 ImGui::EndDragDropTarget();
208 if (!g_pendingFileDrops.empty() && acceptsDropType(
node,
"file") &&
209 ImGui::IsItemHovered()) {
210 for (
auto &
path : g_pendingFileDrops) {
214 g_pendingFileDrops.clear();
218graphics::Camera3D *activeCamera() {
219 if (ecs::current()->getManager<graphics::Camera3D>() ==
nullptr)
return nullptr;
220 auto cameras = ecs::View<graphics::Camera3D, graphics::Camera3D::Data>();
221 for (
auto it = cameras.begin(); it != cameras.end(); ++it) {
223 if (data->active)
return data->entity;
228bool updateWorldAnchor(UIHost &
host, graphics::Camera3D *camera,
float width,
float height) {
229 auto anchor =
host.worldAnchor();
230 if (!anchor->enabled) {
238 const auto data =
camera->data();
239 const glm::vec3
eye(data->eyeX, data->eyeY, data->eyeZ);
240 const glm::vec3
target(data->targetX, data->targetY, data->targetZ);
241 const glm::vec3
up(data->upX, data->upY, data->upZ);
244 data->orthographic, glm::radians(data->fovYDeg), data->orthoHeight,
248 anchor->state = projected.state;
249 anchor->screenX = projected.screenX;
250 anchor->screenY = projected.screenY;
251 anchor->depth = projected.depth;
252 anchor->scale = projected.scale;
253 anchor->displacementX = 0.f;
254 anchor->displacementY = 0.f;
255 return projected.render;
258std::string viewportKey(UIHost *
host,
const UINode &
n) {
259 const std::string hostName =
260 host && !
host->meta()->name.empty() ?
host->meta()->name :
"?";
261 return hostName +
"/" + (
n.id.empty() ?
"viewport" :
n.id);
264void pushPending(UIHost *
host,
const UINode &
n,
const char *
kind, uint32_t handlerIndex,
265 bool toggleValue =
false,
float floatValue = 0.f, std::string textValue = {}) {
269 ev.host =
host->handle();
270 ev.hostName =
host ?
host->meta()->name :
"";
273 auto tree =
host->tree();
274 if (!tree->nodes.empty()) ev.nodeIndex = int(&
n - tree->nodes.data());
277 ev.handlerIndex = handlerIndex;
278 ev.toggleValue = toggleValue;
279 ev.floatValue = floatValue;
280 ev.textValue = std::move(textValue);
281 g_pending.push_back(std::move(ev));
284std::string nodeLabel(
const UINode &
node,
const char *fallback) {
285 std::string
label =
node.text.empty() ? fallback :
node.text;
290bool privateUseGlyph(
const std::string &
text, ImWchar *
out) {
291 if (
text.size() != 3)
return false;
292 const auto b0 =
static_cast<unsigned char>(
text[0]);
293 const auto b1 =
static_cast<unsigned char>(
text[1]);
294 const auto b2 =
static_cast<unsigned char>(
text[2]);
295 if ((b0 & 0xf0u) != 0xe0u || (b1 & 0xc0u) != 0x80u || (b2 & 0xc0u) != 0x80u)
297 const unsigned int codepoint =
298 ((b0 & 0x0fu) << 12u) | ((b1 & 0x3fu) << 6u) | (b2 & 0x3fu);
299 if (codepoint < 0xe000u || codepoint > 0xf8ffu)
return false;
300 if (
out) *
out =
static_cast<ImWchar
>(codepoint);
319 default:
return false;
323struct PaletteSwatch {
330void appendDefaultPaletteSwatches(std::vector<PaletteSwatch> &
out) {
331 static const PaletteSwatch kDefaults[] = {
332 {0.00f, 0.00f, 0.00f, 1.f}, {0.20f, 0.20f, 0.22f, 1.f},
333 {0.45f, 0.45f, 0.48f, 1.f}, {0.92f, 0.92f, 0.94f, 1.f},
334 {0.82f, 0.18f, 0.18f, 1.f}, {0.90f, 0.45f, 0.12f, 1.f},
335 {0.92f, 0.78f, 0.16f, 1.f}, {0.22f, 0.68f, 0.28f, 1.f},
336 {0.14f, 0.70f, 0.72f, 1.f}, {0.18f, 0.38f, 0.86f, 1.f},
337 {0.48f, 0.28f, 0.82f, 1.f}, {0.82f, 0.22f, 0.62f, 1.f},
338 {0.55f, 0.35f, 0.22f, 1.f}, {0.95f, 0.55f, 0.70f, 1.f},
339 {0.42f, 0.52f, 0.22f, 1.f}, {0.12f, 0.18f, 0.32f, 1.f},
341 out.insert(
out.end(), std::begin(kDefaults), std::end(kDefaults));
344bool parsePaletteSwatch(std::string
token, PaletteSwatch &
out) {
350 if (
token.empty())
return false;
351 if (
token[0] ==
'#') {
353 if (
token.size() == 7 && std::sscanf(
token.c_str() + 1,
"%06x", &
value) == 1) {
354 out.r = float((
value >> 16) & 0xff) / 255.f;
355 out.g = float((
value >> 8) & 0xff) / 255.f;
356 out.b = float(
value & 0xff) / 255.f;
360 if (
token.size() == 9 && std::sscanf(
token.c_str() + 1,
"%08x", &
value) == 1) {
361 out.r = float((
value >> 24) & 0xff) / 255.f;
362 out.g = float((
value >> 16) & 0xff) / 255.f;
363 out.b = float((
value >> 8) & 0xff) / 255.f;
364 out.a = float(
value & 0xff) / 255.f;
369 float r = 0.f,
g = 0.f,
b = 0.f,
a = 1.f;
370 const int n = std::sscanf(
token.c_str(),
"%f,%f,%f,%f", &
r, &
g, &
b, &
a);
371 if (
n < 3)
return false;
375 if (
n >= 4)
out.a =
a;
379std::vector<PaletteSwatch> paletteSwatches(
const UINode &
n) {
380 std::vector<PaletteSwatch> swatches;
381 const std::string &src =
n.valueText;
383 while (i < src.size()) {
384 size_t end = src.find_first_of(
";\n", i);
385 if (
end == std::string::npos)
end = src.size();
386 PaletteSwatch swatch;
387 if (parsePaletteSwatch(src.substr(i,
end - i), swatch)) swatches.push_back(swatch);
390 if (swatches.empty()) appendDefaultPaletteSwatches(swatches);
394void commitPaletteColor(UIHost *
host, UINode &
n,
const float col[4]) {
400 pushPending(
host,
n,
"value",
n.handlerValue,
false, col[0]);
403bool keyPressed(ImGuiKey
key) {
404 const int index = ImGui::GetKeyIndex(
key);
405 return index >= 0 && ImGui::IsKeyPressed(
index,
false);
408void routeExplicitFocusInput(UIHost *
host,
const UINode &
node) {
410 if (keyPressed(ImGuiKey_Tab)) {
411 const bool backwards = ImGui::GetIO().KeyShift;
412 const std::string &
target = backwards ?
node.focusPrevious :
node.focusNext;
417 if (ImGui::IsItemActive())
return;
418 if (!
node.focusLeft.empty() && keyPressed(ImGuiKey_LeftArrow))
420 else if (!
node.focusRight.empty() && keyPressed(ImGuiKey_RightArrow))
422 else if (!
node.focusUp.empty() && keyPressed(ImGuiKey_UpArrow))
424 else if (!
node.focusDown.empty() && keyPressed(ImGuiKey_DownArrow))
428void walkNode(UIHost *
host, UIHost::Tree *tree,
int index);
430void walkSiblings(UIHost *
host, UIHost::Tree *tree,
int index) {
431 while (
index >= 0 &&
index <
int(tree->nodes.size())) {
432 const int next = tree->nodes[size_t(
index)].nextSibling;
433 UINode &
node = tree->nodes[size_t(
index)];
438 next <
int(tree->nodes.size()) &&
440 const float oldY =
node.sizeY;
441 const float reserve = tree->nodes[size_t(next)].measuredH +
442 ImGui::GetStyle().ItemSpacing.y;
443 node.sizeY = std::max(1.f, ImGui::GetContentRegionAvail().
y - reserve);
453void walkPaneChild(UIHost *
host, UIHost::Tree *tree,
int index) {
454 if (index < 0 || index >=
int(tree->nodes.size()))
return;
456 const ImVec2 avail = ImGui::GetContentRegionAvail();
470bool hasDirectChildType(
const UIHost::Tree &tree,
const UINode &
parent,
NodeType type) {
472 child = tree.nodes[size_t(
child)].nextSibling) {
473 if (
child >=
int(tree.nodes.size()))
break;
474 if (tree.nodes[
size_t(
child)].type ==
type)
return true;
479void emitSpacer(
float main,
float cross,
bool row) {
481 if (cross < 0.f)
cross = 0.f;
483 if (
main <= 0.f && cross <= 0.f) {
484 ImGui::Dummy(ImVec2(0.f, 0.f));
486 ImGui::Dummy(ImVec2(
main, cross > 0.f ? cross : 1.f));
489 if (
main <= 0.f && cross <= 0.f) {
490 ImGui::Dummy(ImVec2(0.f, 0.f));
492 ImGui::Dummy(ImVec2(cross > 0.f ? cross : 1.f,
main));
498void drawNinePatch(
void *
handle,
const ImVec2 &
pos,
const ImVec2 &
size,
const ImVec2 &uv0,
499 const ImVec2 &uv1,
float bL,
float bT,
float bR,
float bB,
int texW,
int texH,
501 ImDrawList *dl = ImGui::GetWindowDrawList();
502 const auto draw = [&](
float x0,
float y0,
float x1,
float y1,
float u0,
float v0,
float u1,
504 dl->AddImage(
static_cast<ImTextureID
>(
handle), ImVec2(
pos.x + x0,
pos.y + y0),
505 ImVec2(
pos.x + x1,
pos.y + y1), ImVec2(u0, v0), ImVec2(u1, v1),
tint);
507 if (bL <= 0.f && bT <= 0.f && bR <= 0.f && bB <= 0.f) {
508 draw(0.f, 0.f,
size.x,
size.y, uv0.x, uv0.y, uv1.x, uv1.y);
511 if (texW <= 0 || texH <= 0) {
512 draw(0.f, 0.f,
size.x,
size.y, uv0.x, uv0.y, uv1.x, uv1.y);
517 const float bl =
x.nearSize, br =
x.farSize, bt =
y.nearSize, bb =
y.farSize;
518 const float uL =
x.nearUv, uR =
x.farUv, vT =
y.nearUv, vB =
y.farUv;
520 draw(0.f, 0.f, bl, bt, uv0.x, uv0.y, uL, vT);
521 draw(
size.x - br, 0.f,
size.x, bt, uR, uv0.y, uv1.x, vT);
522 draw(0.f,
size.y - bb, bl,
size.y, uv0.x, vB, uL, uv1.y);
525 draw(bl, 0.f,
size.x - br, bt, uL, uv0.y, uR, vT);
527 draw(0.f, bt, bl,
size.y - bb, uv0.x, vT, uL, vB);
534void queueNinePatch(uint64_t textureId,
const ImVec2 &
pos,
const ImVec2 &
size,
535 const ImVec2 &uv0,
const ImVec2 &uv1,
float bL,
float bT,
float bR,
536 float bB,
int texW,
int texH,
float r,
float g,
float b,
float a,
537 bool opaque =
false) {
538 if (!g_backend)
return;
539 const auto draw = [&](
float x0,
float y0,
float x1,
float y1,
float u0,
float v0,
540 float u1,
float v1) {
541 if (x1 <= x0 || y1 <= y0)
return;
542 g_backend->queueTextureDraw(textureId,
pos.x + x0,
pos.y + y0, x1 - x0, y1 - y0,
543 u0, v0, u1, v1,
r,
g,
b,
a, opaque);
545 if ((bL <= 0.f && bT <= 0.f && bR <= 0.f && bB <= 0.f) || texW <= 0 || texH <= 0) {
546 draw(0.f, 0.f,
size.x,
size.y, uv0.x, uv0.y, uv1.x, uv1.y);
551 const float bl =
x.nearSize, br =
x.farSize, bt =
y.nearSize, bb =
y.farSize;
552 const float uL =
x.nearUv, uR =
x.farUv, vT =
y.nearUv, vB =
y.farUv;
553 draw(0.f, 0.f, bl, bt, uv0.x, uv0.y, uL, vT);
554 draw(
size.x - br, 0.f,
size.x, bt, uR, uv0.y, uv1.x, vT);
555 draw(0.f,
size.y - bb, bl,
size.y, uv0.x, vB, uL, uv1.y);
557 draw(bl, 0.f,
size.x - br, bt, uL, uv0.y, uR, vT);
559 draw(0.f, bt, bl,
size.y - bb, uv0.x, vT, uL, vB);
564void walkFlex(UIHost *
host, UIHost::Tree *tree, UINode &
flex) {
566 const ImGuiStyle &style = ImGui::GetStyle();
567 const float legacyGap =
570 : (
flex.rowGap >= 0.f ?
flex.rowGap : legacyGap);
572 : (
flex.columnGap >= 0.f ?
flex.columnGap : style.ItemSpacing.
x);
576 const ImVec2 avail = ImGui::GetContentRegionAvail();
584 const float availMain = (
row ? flexW : flexH) - padMain;
585 const float availCross = (
row ? flexH : flexW) - padCross;
587 std::vector<int> kids;
588 std::vector<int> absKids;
589 std::vector<FlexItemSpec> specs;
590 for (
int c =
flex.firstChild;
c >= 0;
c = tree->nodes[size_t(
c)].nextSibling) {
591 if (
c >=
int(tree->nodes.size()))
break;
592 UINode &
child = tree->nodes[size_t(
c)];
595 absKids.push_back(
c);
623 const FlexResult res =
627 flex.layoutOverflowX = std::max(
628 0.f, res.contentW - std::max(0.f,
row ? availMain : availCross));
629 flex.layoutOverflowY = std::max(
630 0.f, res.contentH - std::max(0.f,
row ? availCross : availMain));
631 if (
row)
flex.layoutOverflowX = std::max(
flex.layoutOverflowX, res.overflowMain);
632 else flex.layoutOverflowY = std::max(
flex.layoutOverflowY, res.overflowMain);
635 ImGui::PushID(&
flex);
636 ImGui::BeginChild(
"layout-scroll", ImVec2(std::max(0.f, flexW), std::max(0.f, flexH)),
637 false, ImGuiWindowFlags_HorizontalScrollbar);
639 const ImVec2
cursor = ImGui::GetCursorScreenPos();
644 ImGui::Dummy(ImVec2(std::max(0.f, dummyW), std::max(0.f, dummyH)));
645 const ImVec2 flowEnd = ImGui::GetCursorScreenPos();
651 for (
size_t i = 0; i < kids.size(); ++i) {
652 UINode &
child = tree->nodes[size_t(kids[i])];
653 const FlexRect &
r = res.items[i];
654 ImGui::SetCursorScreenPos(ImVec2(
origin.x +
r.x,
origin.y +
r.y));
657 bool pushedWidth =
false;
660 if (
row ||
r.w > 0.f) {
661 ImGui::PushItemWidth(
r.w > 0.f ?
r.w : 1.f);
664 walkNode(
host, tree, kids[i]);
667 if (pushedWidth) ImGui::PopItemWidth();
671 for (
int c : absKids) {
672 UINode &
child = tree->nodes[size_t(
c)];
688 if (
w > 0.f) ImGui::PushItemWidth(
w);
689 walkNode(
host, tree,
c);
692 if (
w > 0.f) ImGui::PopItemWidth();
694 if (clipped) ImGui::PopClipRect();
695 ImGui::SetCursorScreenPos(flowEnd);
702void walkGrid(UIHost *
host, UIHost::Tree *tree, UINode &grid) {
703 const ImGuiStyle &style = ImGui::GetStyle();
710 const ImVec2 avail = ImGui::GetContentRegionAvail();
713 std::vector<int> kids;
714 std::vector<int> absKids;
715 std::vector<GridItemSpec> specs;
716 for (
int c =
grid.firstChild;
c >= 0;
c = tree->nodes[size_t(
c)].nextSibling) {
717 if (
c >=
int(tree->nodes.size()))
break;
718 UINode &
child = tree->nodes[size_t(
c)];
721 absKids.push_back(
c);
726 spec.basisW =
child.measuredW;
727 spec.basisH =
child.measuredH;
734 specs.push_back(spec);
741 grid.layoutOverflowY = std::max(0.f, naturalH - gridH);
744 ImGui::PushID(&grid);
745 ImGui::BeginChild(
"grid-scroll", ImVec2(std::max(0.f, gridW), std::max(0.f, gridH)),
746 false, ImGuiWindowFlags_HorizontalScrollbar);
748 const ImVec2
cursor = ImGui::GetCursorScreenPos();
749 ImGui::Dummy(ImVec2(std::max(0.f, gridW),
750 std::max(0.f, scrolling ? std::max(gridH, naturalH) : gridH)));
751 const ImVec2 flowEnd = ImGui::GetCursorScreenPos();
756 for (
size_t i = 0; i < kids.size(); ++i) {
757 UINode &
child = tree->nodes[size_t(kids[i])];
758 const FlexRect &rect =
result.items[i];
759 ImGui::SetCursorScreenPos(ImVec2(
origin.x + rect.x,
origin.y + rect.y));
764 if (rect.w > 0.f) ImGui::PushItemWidth(rect.w);
765 walkNode(
host, tree, kids[i]);
768 if (rect.w > 0.f) ImGui::PopItemWidth();
771 for (
int c : absKids) {
772 UINode &
child = tree->nodes[size_t(
c)];
788 if (
w > 0.f) ImGui::PushItemWidth(
w);
789 walkNode(
host, tree,
c);
792 if (
w > 0.f) ImGui::PopItemWidth();
794 if (clipped) ImGui::PopClipRect();
795 ImGui::SetCursorScreenPos(flowEnd);
802void walkNode(UIHost *
host, UIHost::Tree *tree,
int index) {
803 if (index < 0 || index >=
int(tree->nodes.size()))
return;
804 UINode &
n = tree->nodes[size_t(
index)];
805 if (!
n.visible)
return;
816 if (g_hudScale != 1.f) ImGui::GetStyle().ScaleAllSizes(g_hudScale);
819 int styleColorCount = 0;
820 int styleVarCount = 0;
821 if (
n.hasResolvedStyle) {
822 const StyleClass &style =
n.resolvedStyle;
823 const auto pushColor = [&](ImGuiCol
slot,
const float color[4]) {
827 if (style.hasTextColor) pushColor(ImGuiCol_Text, style.textColor);
828 if (style.hasBackgroundColor) {
829 pushColor(ImGuiCol_Button, style.backgroundColor);
830 pushColor(ImGuiCol_FrameBg, style.backgroundColor);
831 pushColor(ImGuiCol_Header, style.backgroundColor);
832 pushColor(ImGuiCol_ChildBg, style.backgroundColor);
834 if (style.hasBorderColor) pushColor(ImGuiCol_Border, style.borderColor);
835 if (style.hasAccentColor) {
836 pushColor(ImGuiCol_ButtonHovered, style.accentColor);
837 pushColor(ImGuiCol_ButtonActive, style.accentColor);
838 pushColor(ImGuiCol_HeaderHovered, style.accentColor);
839 pushColor(ImGuiCol_HeaderActive, style.accentColor);
840 pushColor(ImGuiCol_CheckMark, style.accentColor);
841 pushColor(ImGuiCol_SliderGrab, style.accentColor);
842 pushColor(ImGuiCol_SliderGrabActive, style.accentColor);
845 if (style.hasPadding) {
846 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding,
847 ImVec2(style.paddingX *
scale, style.paddingY *
scale));
850 if (style.hasRounding) {
851 ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, style.rounding *
scale);
854 if (style.hasAlpha) {
855 ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().
Alpha * style.alpha);
859 if (
n.opacity < 0.9999f) {
860 ImGui::PushStyleVar(ImGuiStyleVar_Alpha,
861 ImGui::GetStyle().
Alpha * std::clamp(
n.opacity, 0.f, 1.f));
865 const bool interactive = isInteractive(
n.type);
866 const bool disableItem = interactive && !
n.enabled;
867 const bool disableNavigation = interactive &&
n.focusMode !=
FocusMode::All;
869 ImGui::PushItemFlag(ImGuiItemFlags_Disabled,
true);
870 ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().
Alpha * 0.6f);
872 if (disableNavigation) ImGui::PushItemFlag(ImGuiItemFlags_NoNav,
true);
874 ImGui::SetKeyboardFocusHere();
878 const std::string visibleTitle =
n.text.empty() ?
"Window" :
n.text;
879 std::string
title = visibleTitle;
882 if (
host && !
host->meta()->name.empty())
883 title +=
"###" +
host->meta()->name +
"/" + visibleTitle;
884 const bool modal =
host &&
host->meta()->modal;
885 ImGuiWindowFlags
flags = 0;
887 const bool desktopChrome =
892 flags |= ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse;
895 if (
host &&
host->meta()->percentW > 0.f)
896 winW =
host->meta()->percentW * ImGui::GetIO().DisplaySize.x;
897 else if (
host &&
host->meta()->hasSize)
898 winW =
host->meta()->sizeX;
899 if (
host &&
host->meta()->percentH > 0.f)
900 winH =
host->meta()->percentH * ImGui::GetIO().DisplaySize.y;
901 else if (
host &&
host->meta()->hasSize)
902 winH =
host->meta()->sizeY;
903 const auto worldAnchor =
host ?
host->worldAnchor() :
nullptr;
904 if (worldAnchor->enabled) {
905 ImGui::SetNextWindowPos(ImVec2(worldAnchor->screenX, worldAnchor->screenY),
907 ImVec2(
host->meta()->pivotX,
host->meta()->pivotY));
908 flags |= ImGuiWindowFlags_NoMove;
909 if (!
host->meta()->hasSize && winW <= 0.f && winH <= 0.f)
910 flags |= ImGuiWindowFlags_AlwaysAutoResize;
911 }
else if (
host &&
host->meta()->hasPos) {
912 const ImVec2 display = ImGui::GetIO().DisplaySize;
916 const float x =
host->meta()->anchorX * display.x +
host->meta()->posX;
917 const float y =
host->meta()->anchorY * display.y +
host->meta()->posY;
918 const bool drivePos =
host->meta()->lockPos ||
host->meta()->animDrivePos;
919 ImGui::SetNextWindowPos(ImVec2(
x,
y), drivePos ? ImGuiCond_Always : ImGuiCond_FirstUseEver,
920 ImVec2(
host->meta()->pivotX,
host->meta()->pivotY));
921 if (
host->meta()->lockPos)
flags |= ImGuiWindowFlags_NoMove;
922 if (winW <= 0.f && winH <= 0.f)
flags |= ImGuiWindowFlags_AlwaysAutoResize;
924 if (winW > 0.f || winH > 0.f) {
925 const bool driveSize =
host && (
host->meta()->lockSize ||
host->meta()->animDriveSize);
926 ImGui::SetNextWindowSize(ImVec2(winW > 0.f ? winW : -1.f, winH > 0.f ? winH : -1.f),
927 driveSize ? ImGuiCond_Always : ImGuiCond_FirstUseEver);
928 }
else if (
n.measuredW > 0.f ||
n.measuredH > 0.f) {
930 ImGui::SetNextWindowContentSize(ImVec2(
n.measuredW,
n.measuredH));
932 if (
host &&
host->meta()->inputTransparent)
flags |= ImGuiWindowFlags_NoInputs;
933 if (
host &&
host->meta()->overlay) {
934 flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
935 ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse;
936 if (!
host->meta()->hasSize &&
host->meta()->percentW <= 0.f &&
937 host->meta()->percentH <= 0.f)
938 flags |= ImGuiWindowFlags_AlwaysAutoResize;
939 ImGui::SetNextWindowBgAlpha(
host->meta()->overlayBgAlpha);
943 const bool transparentOverlay =
host &&
host->meta()->overlay &&
host->meta()->overlayBgAlpha == 0.f;
944 const bool flushOverlay =
host &&
host->meta()->overlay && (
host->meta()->overlayFlush || transparentOverlay);
945 if (flushOverlay) ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.f, 0.f));
946 if (transparentOverlay) ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.f);
948 ImGui::OpenPopup(
title.c_str());
949 if (ImGui::BeginPopupModal(
title.c_str(),
nullptr,
950 ImGuiWindowFlags_AlwaysAutoResize |
flags)) {
951 if (worldAnchor->enabled)
952 ImGui::SetWindowFontScale(worldAnchor->scale);
953 if (
n.firstChild >= 0) walkSiblings(
host, tree,
n.firstChild);
958 ImGui::SetWindowFontScale(1.f);
959 if (
host &&
host->meta()->canvas.enabled && !worldAnchor->enabled) {
960 const ImVec2 display = ImGui::GetIO().DisplaySize;
963 if (worldAnchor->enabled)
964 ImGui::SetWindowFontScale(worldAnchor->scale);
965 if (
n.firstChild >= 0) walkSiblings(
host, tree,
n.firstChild);
968 if (transparentOverlay) ImGui::PopStyleVar();
969 if (flushOverlay) ImGui::PopStyleVar();
973 if (
n.fontSize > 0.f) {
974 const ImVec2
pos = ImGui::GetCursorScreenPos();
975 const ImVec2 measured = ImGui::GetFont()->CalcTextSizeA(
n.fontSize, FLT_MAX,
n.wrapWidth,
n.text.c_str());
976 const ImVec2
size(
n.sizeX > 0.f ?
n.sizeX : measured.
x,
n.sizeY > 0.f ?
n.sizeY : measured.
y);
977 const ImVec2
at(
pos.x + std::max(0.f,
size.x - measured.x) *
n.textAlignX,
978 pos.y + std::max(0.f,
size.y - measured.y) *
n.textAlignY);
980 ImGui::GetWindowDrawList()->AddText(ImGui::GetFont(),
n.fontSize,
at,
981 ImGui::GetColorU32(ImVec4(
n.textR,
n.textG,
n.textB,
n.textA)),
982 n.text.c_str(),
nullptr,
n.wrapWidth, &
clip);
984 }
else if (
n.wrapWidth > 0.f) {
985 ImGui::PushTextWrapPos(ImGui::GetCursorPosX() +
n.wrapWidth);
986 ImGui::TextUnformatted(
n.text.c_str());
987 ImGui::PopTextWrapPos();
989 ImGui::TextUnformatted(
n.text.c_str());
994 pushPending(
host,
n,
"click",
n.handlerClick);
998 ImWchar iconCodepoint = 0;
999 const bool iconOnly = privateUseGlyph(
n.text, &iconCodepoint);
1000 const std::string
label =
1001 iconOnly ?
"##iconButton" + (
n.id.empty() ? std::string(
"button") :
n.
id)
1002 : nodeLabel(
n,
"Button");
1003 const bool sized =
n.sizeX > 0.f ||
n.sizeY > 0.f;
1004 const float defaultSide = ImGui::GetFrameHeight();
1005 const ImVec2 buttonSize(iconOnly ? (
n.sizeX > 0.f ?
n.sizeX : defaultSide)
1006 : (
n.sizeX > 0.f ?
n.sizeX : 0.f),
1007 iconOnly ? (
n.sizeY > 0.f ?
n.sizeY : defaultSide)
1008 : (
n.sizeY > 0.f ?
n.sizeY : 0.f));
1010 ImGui::PushStyleColor(ImGuiCol_Button,
1011 ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive));
1012 ImGui::PushStyleColor(ImGuiCol_ButtonHovered,
1013 ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive));
1016 (sized || iconOnly) ? buttonSize.x : 0.f,
1017 (sized || iconOnly) ? buttonSize.
y : 0.f) ==
1019 if (
n.checked) ImGui::PopStyleColor(2);
1021 const ImVec2
rectMin = ImGui::GetItemRectMin();
1022 const ImVec2
rectMax = ImGui::GetItemRectMax();
1023 ImFont *font = ImGui::GetFont();
1024 const ImFontGlyph *
glyph = font ? font->FindGlyph(iconCodepoint) :
nullptr;
1026 const float fontSize = ImGui::GetFontSize();
1027 const float fontScale = fontSize / font->FontSize;
1028 const float glyphW = (
glyph->X1 -
glyph->X0) * fontScale;
1029 const float glyphH = (
glyph->Y1 -
glyph->Y0) * fontScale;
1030 const ImVec2 glyphOrigin(
1033 ImGui::GetWindowDrawList()->AddText(font, fontSize, glyphOrigin,
1034 ImGui::GetColorU32(ImGuiCol_Text),
1038 if (clicked) pushPending(
host,
n,
"click",
n.handlerClick);
1045 ImGui::BeginGroup();
1046 if (
n.firstChild >= 0) walkSiblings(
host, tree,
n.firstChild);
1057 pushPending(
host,
n,
"toggle",
n.handlerToggle, checked);
1063 const char *
label =
n.text.empty() ?
"Slider" :
n.text.c_str();
1067 pushPending(
host,
n,
"value",
n.handlerValue,
false,
v);
1072 const float swatch = ImGui::GetFrameHeight();
1073 const float gap = 4.f;
1075 float col[4] = {
n.tintR,
n.tintG,
n.tintB,
n.tintA};
1076 const std::string
label =
n.text.empty() ?
"Color" :
n.text;
1077 const std::string editId =
label +
"###palette-edit-" +
n.id;
1078 ImGui::BeginGroup();
1079 ImGui::PushID(
n.id.empty() ?
"color-palette" :
n.
id.c_str());
1080 ImGui::SetNextItemWidth(std::max(80.f,
n.measuredW > 0.f ?
n.measuredW : 220.f));
1081 const ImGuiColorEditFlags
flags =
1082 ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_AlphaPreviewHalf |
1083 ImGuiColorEditFlags_PickerHueBar | ImGuiColorEditFlags_DisplayRGB;
1084 if (ImGui::ColorEdit4(editId.c_str(), col,
flags)) commitPaletteColor(
host,
n, col);
1085 const std::vector<PaletteSwatch> swatches = paletteSwatches(
n);
1086 for (
size_t i = 0; i < swatches.size(); ++i) {
1087 if (i %
static_cast<size_t>(
cols) != 0) ImGui::SameLine(0.f,
gap);
1088 const PaletteSwatch &
s = swatches[i];
1090 const bool selected = std::fabs(
n.tintR -
s.r) < 0.004f &&
1091 std::fabs(
n.tintG -
s.g) < 0.004f &&
1092 std::fabs(
n.tintB -
s.b) < 0.004f &&
1093 std::fabs(
n.tintA -
s.a) < 0.004f;
1094 ImGui::PushID(
static_cast<int>(i));
1095 if (ImGui::ColorButton(
"##swatch",
color, ImGuiColorEditFlags_NoTooltip |
1096 ImGuiColorEditFlags_AlphaPreview,
1097 ImVec2(swatch, swatch))) {
1098 float picked[4] = {
s.r,
s.g,
s.b,
s.a};
1099 commitPaletteColor(
host,
n, picked);
1102 const ImVec2 p0 = ImGui::GetItemRectMin();
1103 const ImVec2 p1 = ImGui::GetItemRectMax();
1104 ImGui::GetWindowDrawList()->AddRect(
1105 p0, p1, ImGui::GetColorU32(ImGuiCol_Text), 0.f, 0, 1.5f);
1114 const char *overlay =
n.text.empty() ? nullptr :
n.text.c_str();
1115 ImGui::ProgressBar(
n.value, ImVec2(
n.sizeX > 0.f ?
n.sizeX : -1.f,
n.sizeY > 0.f ?
n.sizeY : 0.f), overlay);
1119 const ImVec2
pos = ImGui::GetCursorScreenPos();
1120 const ImVec2
size(
n.sizeX > 0.f ?
n.sizeX : 32.f,
n.sizeY > 0.f ?
n.sizeY : 32.f);
1122 const ImU32
color = ImGui::GetColorU32(ImVec4(
n.tintR,
n.tintG,
n.tintB,
n.tintA));
1124 auto *
list = ImGui::GetWindowDrawList();
1125 const auto savedFlags =
list->Flags;
1127 list->Flags &= ~ImDrawListFlags_AntiAliasedFill;
1128 const auto triangle = [&](ImVec2
a, ImVec2
b, ImVec2
c) {
1130 if (!
n.fillClockwise) std::swap(
b,
c);
1133 for (
int i = 0; i <
mesh.count; ++i) {
1134 const auto &
q =
mesh.quads[std::size_t(i)];
1136 if (
n.fillInnerRadius > 0.f)
1139 list->Flags = savedFlags;
1145 const float w =
n.sizeX > 0.f ?
n.sizeX : 32.f;
1146 const float h =
n.sizeY > 0.f ?
n.sizeY : 32.f;
1147 const ImVec2
pos = ImGui::GetCursorScreenPos();
1149 const ImU32
tint = ImGui::GetColorU32(ImVec4(
n.tintR,
n.tintG,
n.tintB,
n.tintA));
1152 const ImVec2 drawPos(
pos.x + fill.x *
w,
pos.y + fill.y *
h);
1153 const ImVec2 drawSize(fill.w *
w, fill.h *
h);
1154 const ImVec2 drawUv0(
n.uv0x + (
n.uv1x -
n.uv0x) * fill.u0,
n.uv0y + (
n.uv1y -
n.uv0y) * fill.v0);
1155 const ImVec2 drawUv1(
n.uv0x + (
n.uv1x -
n.uv0x) * fill.u1,
n.uv0y + (
n.uv1y -
n.uv0y) * fill.v1);
1156 if (fill.w <= 0.f || fill.h <= 0.f) {
1160 if (
n.textureId != 0 && g_backend) {
1162 g_backend->textureSize(
n.textureId, &tw, &th);
1163 if (g_backend->usesQueuedTextureDraws()) {
1164 queueNinePatch(
n.textureId, drawPos, drawSize, drawUv0, drawUv1,
1171 void *
handle = g_backend->textureHandle(
n.textureId);
1173 drawNinePatch(
handle, drawPos, drawSize, drawUv0, drawUv1,
1179 ImGui::GetWindowDrawList()->AddRectFilled(
1180 drawPos, ImVec2(drawPos.x + drawSize.x, drawPos.y + drawSize.y),
tint,
n.cornerRadius);
1184 ImGui::GetWindowDrawList()->AddRectFilled(drawPos, ImVec2(drawPos.x + drawSize.x, drawPos.y + drawSize.y),
1185 tint,
n.cornerRadius);
1191 const float w =
n.sizeX > 0.f ?
n.sizeX : 32.f;
1192 const float h =
n.sizeY > 0.f ?
n.sizeY : 32.f;
1194 const std::string sid =
n.id.empty() ?
"imgbtn" :
n.id;
1195 ImGui::PushID(sid.c_str());
1196 bool clicked =
false;
1197 bool itemCreated =
false;
1198 if (
n.textureId != 0 && g_backend) {
1199 if (g_backend->usesQueuedTextureDraws()) {
1200 clicked = ImGui::InvisibleButton(sid.c_str(),
size);
1202 const ImVec2 pmin = ImGui::GetItemRectMin();
1203 const float hover = ImGui::IsItemHovered() ? 1.12f : 1.f;
1204 g_backend->queueTextureDraw(
n.textureId, pmin.x, pmin.y,
size.x,
size.y,
1205 n.uv0x,
n.uv0y,
n.uv1x,
n.uv1y,
1206 std::min(1.f,
n.tintR * hover),
1207 std::min(1.f,
n.tintG * hover),
1208 std::min(1.f,
n.tintB * hover),
n.tintA,
false);
1210 void *
handle = g_backend->textureHandle(
n.textureId);
1212 clicked = ImGui::ImageButton(
1213 static_cast<ImTextureID
>(
handle),
size, ImVec2(
n.uv0x,
n.uv0y),
1214 ImVec2(
n.uv1x,
n.uv1y), -1, ImVec4(0.f, 0.f, 0.f, 0.f),
1215 ImVec4(
n.tintR,
n.tintG,
n.tintB,
n.tintA));
1221 clicked = ImGui::InvisibleButton(sid.c_str(),
size);
1222 const ImVec2 pmin = ImGui::GetItemRectMin();
1223 const ImVec2 pmax = ImGui::GetItemRectMax();
1224 ImU32 col = ImGui::GetColorU32(ImVec4(
n.tintR,
n.tintG,
n.tintB,
n.tintA));
1225 if (ImGui::IsItemHovered()) col = ImGui::GetColorU32(ImGuiCol_ButtonHovered);
1226 ImGui::GetWindowDrawList()->AddRectFilled(pmin, pmax, col,
n.cornerRadius);
1229 if (clicked) pushPending(
host,
n,
"click",
n.handlerClick);
1234 std::vector<std::string> storage;
1236 while (
start <=
n.valueText.size()) {
1237 const size_t end =
n.valueText.find(
'\n',
start);
1238 storage.push_back(
n.valueText.substr(
1240 if (
end == std::string::npos)
break;
1243 std::vector<const char *> items;
1244 items.reserve(storage.size());
1245 for (
const auto &
s : storage) items.push_back(
s.c_str());
1246 int idx = int(
n.value);
1247 const char *
label =
n.text.empty() ?
"Combo" :
n.text.c_str();
1249 n.value = float(
idx);
1250 pushPending(
host,
n,
"value",
n.handlerValue,
false,
float(
idx));
1255 const char *
label =
n.text.empty() ?
"Input" :
n.text.c_str();
1256 std::string edited =
n.valueText;
1259 n.valueText = std::move(edited);
1260 pushPending(
host,
n,
"text",
n.handlerText,
false, 0.f,
n.valueText);
1265 std::string edited =
n.valueText;
1266 const std::string
label =
"##search" + (
n.id.empty() ? std::string() :
"###" +
n.
id);
1267 const ImGuiStyle &style = ImGui::GetStyle();
1268 const std::string hint =
n.text.empty() ?
"Search" :
n.text;
1270 const ImVec2 iconSize = ImGui::CalcTextSize(
glyph);
1272 const float width =
n.sizeX > 0.f ?
n.sizeX : ImGui::GetContentRegionAvail().x;
1273 n.measuredW = std::max(1.f,
width);
1274 ImGui::PushItemWidth(std::max(1.f,
width));
1275 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding,
1276 ImVec2(style.FramePadding.x + iconSize.x +
gap,
1277 style.FramePadding.y));
1280 n.valueText = std::move(edited);
1281 pushPending(
host,
n,
"text",
n.handlerText,
false, 0.f,
n.valueText);
1283 ImGui::PopStyleVar();
1284 ImGui::PopItemWidth();
1285 const ImVec2
rectMin = ImGui::GetItemRectMin();
1286 const ImVec2
rectMax = ImGui::GetItemRectMax();
1287 ImGui::GetWindowDrawList()->AddText(
1288 ImVec2(
rectMin.x + style.FramePadding.x,
1290 ImGui::GetColorU32(ImGuiCol_TextDisabled),
glyph);
1295 const float height = ImGui::GetFrameHeight();
1296 const float trackH = std::max(16.f,
height * 0.68f);
1297 const float trackW =
height * 1.7f;
1298 const float radius = trackH * 0.5f;
1299 const std::string
id =
"##switch" + (
n.id.empty() ? std::string() :
"###" +
n.
id);
1300 ImGui::BeginGroup();
1301 const ImVec2
pos = ImGui::GetCursorScreenPos();
1302 if (ImGui::InvisibleButton(
id.c_str(), ImVec2(trackW,
height))) {
1303 n.checked = !
n.checked;
1304 pushPending(
host,
n,
"toggle",
n.handlerToggle,
n.checked);
1306 const bool hovered = ImGui::IsItemHovered();
1307 const ImU32 bg = ImGui::GetColorU32(
1308 n.checked ? ImGuiCol_CheckMark
1309 : (hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg));
1310 const float y =
pos.y + (
height - trackH) * 0.5f;
1311 ImDrawList *
draw = ImGui::GetWindowDrawList();
1312 draw->AddRectFilled(ImVec2(
pos.x,
y), ImVec2(
pos.x + trackW,
y + trackH), bg,
radius);
1313 const float knobR =
radius - 2.f;
1315 draw->AddCircleFilled(ImVec2(knobX,
y +
radius), knobR,
1316 ImGui::GetColorU32(ImGuiCol_Text));
1317 if (!
n.text.empty()) {
1318 ImGui::SameLine(0.f, ImGui::GetStyle().ItemInnerSpacing.x);
1319 ImGui::AlignTextToFramePadding();
1320 ImGui::TextUnformatted(
n.text.c_str());
1326 const ImVec2 textSize = ImGui::CalcTextSize(
n.text.c_str());
1327 const ImVec2 padding(ImGui::GetStyle().FramePadding.x, 3.f);
1328 const ImVec2
pos = ImGui::GetCursorScreenPos();
1329 const ImVec2
size(textSize.x + padding.x * 2.f, textSize.y + padding.y * 2.f);
1330 ImDrawList *
draw = ImGui::GetWindowDrawList();
1331 const ImU32 bg = ImGui::ColorConvertFloat4ToU32(
1332 ImVec4(
n.tintR,
n.tintG,
n.tintB,
n.tintA));
1333 const ImU32
border = ImGui::ColorConvertFloat4ToU32(
1334 ImVec4(
n.tintR,
n.tintG,
n.tintB, std::min(1.f,
n.tintA + 0.35f)));
1337 draw->AddText(ImVec2(
pos.x + padding.x,
pos.y + padding.y),
1338 ImGui::GetColorU32(ImGuiCol_Text),
n.text.c_str());
1343 ImGuiTreeNodeFlags
flags =
n.open ? ImGuiTreeNodeFlags_DefaultOpen : 0;
1344 const char *
label =
n.text.empty() ?
"Section" :
n.text.c_str();
1346 if (
n.firstChild >= 0) walkSiblings(
host, tree,
n.firstChild);
1351 ImVec2
size(
n.sizeX,
n.sizeY);
1352 const char *cid =
n.id.empty() ?
"child" :
n.id.c_str();
1353 if (ImGui::BeginChild(cid,
size,
true)) {
1354 if (
n.firstChild >= 0) walkSiblings(
host, tree,
n.firstChild);
1363 const float height =
n.sizeY > 0.f
1365 : std::max(ImGui::GetFrameHeight(),
1366 n.measuredH + padding.y * 2.f);
1367 const ImVec2
size(
n.sizeX > 0.f ?
n.sizeX : 0.f,
height);
1368 const std::string
id =
n.id.empty() ?
"card" :
n.id;
1369 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, padding);
1370 ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetStyleColorVec4(ImGuiCol_FrameBg));
1371 if (ImGui::BeginChild(
id.c_str(),
size,
true, ImGuiWindowFlags_AlwaysUseWindowPadding)) {
1372 if (
n.firstChild >= 0) walkSiblings(
host, tree,
n.firstChild);
1375 ImGui::PopStyleColor();
1376 ImGui::PopStyleVar();
1380 const float width =
n.sizeX > 0.f ?
n.sizeX : ImGui::GetContentRegionAvail().x;
1381 const float height =
n.sizeY > 0.f
1383 : std::max(
n.minSizeY,
1384 n.measuredH > 0.f ?
n.measuredH
1385 :
ImGui::GetFrameHeight());
1386 const ImVec2
pos = ImGui::GetCursorScreenPos();
1388 if (
n.textureId != 0 && g_backend) {
1390 g_backend->textureSize(
n.textureId, &tw, &th);
1391 if (g_backend->usesQueuedTextureDraws()) {
1392 queueNinePatch(
n.textureId,
pos,
size, ImVec2(
n.uv0x,
n.uv0y),
1393 ImVec2(
n.uv1x,
n.uv1y),
n.borderL,
n.borderT,
n.borderR,
1394 n.borderB, tw, th,
n.tintR,
n.tintG,
n.tintB,
n.tintA);
1395 }
else if (
void *
handle = g_backend->textureHandle(
n.textureId)) {
1396 const ImU32
tint = ImGui::ColorConvertFloat4ToU32(
1397 ImVec4(
n.tintR,
n.tintG,
n.tintB,
n.tintA));
1399 ImVec2(
n.uv1x,
n.uv1y),
n.borderL,
n.borderT,
n.borderR,
1400 n.borderB, tw, th,
tint);
1403 const std::string
id =
n.id.empty() ?
"ninePatchPanel" :
n.id;
1404 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.f, 0.f));
1405 ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.f, 0.f, 0.f, 0.f));
1406 if (ImGui::BeginChild(
id.c_str(),
size,
false,
1407 ImGuiWindowFlags_AlwaysUseWindowPadding)) {
1408 ImGui::SetCursorPos(ImVec2(
n.paddingL,
n.paddingT));
1409 const ImVec2 contentSize(std::max(1.f,
size.x -
n.paddingL -
n.paddingR),
1410 std::max(1.f,
size.y -
n.paddingT -
n.paddingB));
1411 const std::string contentId =
id +
"##content";
1412 if (ImGui::BeginChild(contentId.c_str(), contentSize,
false)) {
1413 if (
n.firstChild >= 0) walkSiblings(
host, tree,
n.firstChild);
1418 ImGui::PopStyleColor();
1419 ImGui::PopStyleVar();
1424 const ImVec2
pos = ImGui::GetCursorScreenPos();
1425 const float height = ImGui::GetFrameHeight();
1426 const float totalHeight = sectionGap +
height;
1427 const float width =
n.sizeX > 0.f ?
n.sizeX : ImGui::GetContentRegionAvail().x;
1428 const float headerY =
pos.y + sectionGap;
1429 ImDrawList *
draw = ImGui::GetWindowDrawList();
1430 draw->AddRectFilled(ImVec2(
pos.x, headerY + 4.f),
1431 ImVec2(
pos.x + 3.f, headerY +
height - 4.f),
1432 ImGui::GetColorU32(ImGuiCol_CheckMark), 1.f);
1433 draw->AddText(ImVec2(
pos.x + 10.f,
1434 headerY + (
height - ImGui::GetFontSize()) * 0.5f),
1435 ImGui::GetColorU32(ImGuiCol_Text),
n.text.c_str());
1436 const float separatorY =
pos.y + totalHeight - 1.f;
1437 draw->AddLine(ImVec2(
pos.x, separatorY), ImVec2(
pos.x +
width, separatorY),
1438 ImGui::GetColorU32(ImGuiCol_Separator));
1439 ImGui::Dummy(ImVec2(
width, totalHeight));
1443 if (ImGui::BeginMenuBar()) {
1444 if (
n.firstChild >= 0) walkSiblings(
host, tree,
n.firstChild);
1445 ImGui::EndMenuBar();
1449 const std::string
label = nodeLabel(
n,
"Menu");
1450 if (ImGui::BeginMenu(
label.c_str())) {
1451 if (
n.firstChild >= 0) walkSiblings(
host, tree,
n.firstChild);
1457 const std::string
label = nodeLabel(
n,
"Command");
1458 const char *shortcut =
n.valueText.empty() ? nullptr :
n.valueText.c_str();
1459 if (ImGui::MenuItem(
label.c_str(), shortcut,
n.checked,
true))
1460 pushPending(
host,
n,
"click",
n.handlerClick);
1468 const float defaultHeight =
1470 const float height =
n.sizeY > 0.f ?
n.sizeY : defaultHeight;
1471 const ImVec2
size(
n.sizeX > 0.f ?
n.sizeX : 0.f,
height);
1472 const std::string
id =
n.id.empty() ? (
status ?
"statusbar" :
"toolbar") :
n.
id;
1473 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding,
1475 ImGui::PushStyleColor(ImGuiCol_ChildBg,
1476 ImGui::GetStyleColorVec4(
status ? ImGuiCol_WindowBg
1477 : ImGuiCol_MenuBarBg));
1478 if (ImGui::BeginChild(
id.c_str(),
size,
false,
1479 ImGuiWindowFlags_AlwaysUseWindowPadding |
1480 ImGuiWindowFlags_NoScrollbar)) {
1481 walkFlex(
host, tree,
n);
1484 ImGui::PopStyleColor();
1485 ImGui::PopStyleVar();
1493 const float outerWidth =
n.sizeX > 0.f ?
n.sizeX : ImGui::GetContentRegionAvail().x;
1494 const float contentWidth = std::max(1.f, outerWidth - padding.x * 2.f);
1495 const float spacing = ImGui::GetStyle().ItemSpacing.x;
1497 const int requested = int(
n.value) > 0 ? int(
n.value) :
capacity;
1500 for (
int childIndex =
n.firstChild; childIndex >= 0;
1501 childIndex = tree->nodes[size_t(childIndex)].nextSibling) {
1502 if (tree->nodes[
size_t(childIndex)].visible) ++
count;
1505 const float autoHeight = std::max(
1507 ImGui::GetStyle().ItemSpacing.y + padding.y * 2.f);
1508 const ImVec2
size(
n.sizeX > 0.f ?
n.sizeX : 0.f,
n.sizeY > 0.f ?
n.sizeY : autoHeight);
1509 const std::string
id =
n.id.empty() ?
"toolbox" :
n.id;
1510 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, padding);
1511 ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetStyleColorVec4(ImGuiCol_ChildBg));
1512 if (ImGui::BeginChild(
id.c_str(),
size,
false, ImGuiWindowFlags_AlwaysUseWindowPadding)) {
1513 int visibleIndex = 0;
1514 for (
int childIndex =
n.firstChild; childIndex >= 0;
1515 childIndex = tree->nodes[size_t(childIndex)].nextSibling) {
1516 UINode &
child = tree->nodes[size_t(childIndex)];
1522 walkNode(
host, tree, childIndex);
1526 if (visibleIndex %
columns != 0) ImGui::SameLine();
1530 ImGui::PopStyleColor();
1531 ImGui::PopStyleVar();
1538 n.sizeY > 0.f ?
n.sizeY : 0.f);
1539 const std::string
id =
n.id.empty() ?
"sidebar" :
n.id;
1540 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding,
1542 ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetStyleColorVec4(ImGuiCol_ChildBg));
1543 if (ImGui::BeginChild(
id.c_str(),
size,
true, ImGuiWindowFlags_AlwaysUseWindowPadding)) {
1544 if (
n.firstChild >= 0) walkSiblings(
host, tree,
n.firstChild);
1547 ImGui::PopStyleColor();
1548 ImGui::PopStyleVar();
1553 const ImVec2 avail = ImGui::GetContentRegionAvail();
1554 const ImVec2
size(
n.sizeX > 0.f ?
n.sizeX : avail.
x,
n.sizeY > 0.f ?
n.sizeY : avail.
y);
1555 n.measuredW =
size.x;
1556 n.measuredH =
size.y;
1559 const float mainSize = std::max(1.f, (
row ?
size.x :
size.
y) - splitter);
1560 const float minPane = std::min(
layout.minPaneSize *
themeUiScale(), mainSize * 0.5f);
1561 const float ratioLo = std::max(
n.minValue, minPane / mainSize);
1562 const float ratioHi = std::min(
n.maxValue, 1.f - minPane / mainSize);
1563 const std::string
id =
n.id.empty() ?
"splitpane" :
n.id;
1564 ImGui::PushID(
id.c_str());
1565 const ImGuiID ratioStateId = ImGui::GetID(
"ratio");
1566 const float storedRatio = ImGui::GetStateStorage()->GetFloat(ratioStateId,
n.value);
1567 const float ratio = std::max(ratioLo, std::min(ratioHi, storedRatio));
1568 ImGui::GetStateStorage()->SetFloat(ratioStateId,
ratio);
1570 const float firstMain = std::floor(mainSize *
ratio);
1571 const float secondMain = std::max(1.f, mainSize - firstMain);
1572 const int first =
n.firstChild;
1573 const int second =
first >= 0 ? tree->nodes[size_t(
first)].nextSibling : -1;
1574 ImGui::BeginGroup();
1575 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.f, 0.f));
1578 if (ImGui::BeginChild(
"first", paneSize,
false,
1579 ImGuiWindowFlags_NoScrollbar |
1580 ImGuiWindowFlags_NoScrollWithMouse))
1584 if (
row) ImGui::SameLine(0.f, 0.f);
1586 ImGui::InvisibleButton(
"splitter", handleSize);
1587 const bool hovered = ImGui::IsItemHovered();
1588 const bool active = ImGui::IsItemActive();
1590 ImGui::SetMouseCursor(
row ? ImGuiMouseCursor_ResizeEW : ImGuiMouseCursor_ResizeNS);
1591 ImGui::GetWindowDrawList()->AddRectFilled(
1592 ImGui::GetItemRectMin(), ImGui::GetItemRectMax(),
1593 ImGui::GetColorU32(
active ? ImGuiCol_CheckMark
1594 : (hovered ? ImGuiCol_SeparatorHovered
1595 : ImGuiCol_Separator)));
1597 const float delta =
row ? ImGui::GetIO().MouseDelta.x : ImGui::GetIO().MouseDelta.y;
1598 const float next = std::max(ratioLo, std::min(ratioHi,
ratio + delta / mainSize));
1599 if (next !=
ratio) {
1601 ImGui::GetStateStorage()->SetFloat(ratioStateId, next);
1602 pushPending(
host,
n,
"value",
n.handlerValue,
false, next);
1605 if (
row) ImGui::SameLine(0.f, 0.f);
1607 const ImVec2 paneSize(
row ? secondMain :
size.
x,
row ?
size.
y : secondMain);
1608 if (ImGui::BeginChild(
"second", paneSize,
false,
1609 ImGuiWindowFlags_NoScrollbar |
1610 ImGuiWindowFlags_NoScrollWithMouse))
1614 ImGui::PopStyleVar();
1621 std::vector<int> kids;
1622 for (
int c =
n.firstChild;
c >= 0;
c = tree->nodes[size_t(
c)].nextSibling) {
1623 if (
c >=
int(tree->nodes.size()))
break;
1624 if (tree->nodes[
size_t(
c)].visible) kids.push_back(
c);
1626 const int total = int(kids.size());
1627 const char *cid =
n.id.empty() ?
"scrolllist" :
n.id.c_str();
1628 const ImVec2
size(
n.sizeX > 0.f ?
n.sizeX : 0.f,
1629 n.sizeY > 0.f ?
n.sizeY : 120.f);
1630 ImGui::BeginChild(cid,
size,
true);
1631 const float itemH =
n.itemHeight > 0.f ?
n.itemHeight : ImGui::GetFrameHeight();
1632 const float contentW = ImGui::GetContentRegionAvail().x;
1633 const float scrollY = ImGui::GetScrollY();
1634 const float viewH = ImGui::GetWindowHeight();
1635 if (total > 0 && itemH > 0.f) {
1636 int first = int(scrollY / itemH);
1639 int last = int(std::ceil((scrollY + viewH) / itemH));
1641 if (last > total) last = total;
1642 for (
int i =
first; i < last; ++i) {
1643 UINode &
child = tree->nodes[size_t(kids[
size_t(i)])];
1644 ImGui::SetCursorPos(ImVec2(0.f,
float(i) * itemH));
1648 if (contentW > 0.f) ImGui::PushItemWidth(contentW);
1649 walkNode(
host, tree, kids[
size_t(i)]);
1652 if (contentW > 0.f) ImGui::PopItemWidth();
1654 ImGui::SetCursorPosY(
float(i) * itemH + itemH);
1658 ImGui::SetCursorPosY(
float(total) * itemH);
1663 const float w =
n.sizeX > 0.f ?
n.sizeX : ImGui::GetContentRegionAvail().x;
1664 const float h =
n.sizeY > 0.f ?
n.sizeY : ImGui::GetContentRegionAvail().y;
1665 const ImVec2
size(std::max(1.f,
w), std::max(1.f,
h));
1666 const std::string
key = viewportKey(
host,
n);
1669 const ImVec2
rectMin = ImGui::GetCursorScreenPos();
1670 const std::string
label =
"##vp" + (
n.id.empty() ? std::string(
"viewport") :
n.
id);
1671 ImGui::InvisibleButton(
label.c_str(),
size);
1672 const bool hovered = ImGui::IsItemHovered();
1673 const bool active = ImGui::IsItemActive();
1674 const ImVec2 mouse = ImGui::GetMousePos();
1677 vs.hovered = hovered;
1679 vs.mouseX = mouse.x -
rectMin.x;
1680 vs.mouseY = mouse.y -
rectMin.y;
1682 vs.dragDX = ImGui::GetIO().MouseDelta.x;
1683 vs.dragDY = ImGui::GetIO().MouseDelta.y;
1688 vs.wheel = hovered ? ImGui::GetIO().MouseWheel : 0.f;
1690 if (vs.textureId && g_backend && g_backend->usesQueuedTextureDraws()) {
1691 g_backend->queueTextureDraw(vs.textureId,
rectMin.x,
rectMin.y,
size.x,
size.y, 0.f, 0.f, 1.f, 1.f, 1.f,
1692 1.f, 1.f, 1.f,
true);
1693 }
else if (vs.textureId && g_backend) {
1694 void *
handle = g_backend->textureHandle(vs.textureId);
1696 ImGui::SetCursorScreenPos(
rectMin);
1697 ImGui::Image(
static_cast<ImTextureID
>(
handle),
size);
1700 IM_COL32(10, 12, 16, 255));
1703 ImGui::GetWindowDrawList()->AddRectFilled(
1705 IM_COL32(10, 12, 16, 255));
1708 ImGui::GetWindowDrawList()->AddRectFilled(
1714 const std::string
label = nodeLabel(
n,
"Tab");
1718 ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(
theme.tabHovered[0],
theme.tabHovered[1],
1720 ImGui::PushStyleColor(ImGuiCol_ButtonActive,
1722 ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding,
theme.tabRounding *
themeUiScale());
1723 if (ImGui::Button(
label.c_str())) pushPending(
host,
n,
"click",
n.handlerClick);
1724 ImGui::PopStyleVar();
1725 ImGui::PopStyleColor(3);
1732 const ImVec2
size(
n.sizeX > 0.f ?
n.sizeX : 0.f,
height);
1733 const std::string
id =
n.id.empty() ?
"tabbar" :
n.id;
1734 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding,
1736 ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetStyleColorVec4(ImGuiCol_MenuBarBg));
1737 if (ImGui::BeginChild(
id.c_str(),
size,
false,
1738 ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_NoScrollbar)) {
1739 walkFlex(
host, tree,
n);
1742 ImGui::PopStyleColor();
1743 ImGui::PopStyleVar();
1747 const ImVec2 avail = ImGui::GetContentRegionAvail();
1748 const ImVec2
size(
n.sizeX > 0.f ?
n.sizeX : avail.
x,
n.sizeY > 0.f ?
n.sizeY : avail.
y);
1749 const std::string
id =
n.id.empty() ?
"tabcontainer" :
n.id;
1750 ImGui::PushID(
id.c_str());
1751 ImGui::BeginGroup();
1752 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.f, 0.f));
1753 if (ImGui::BeginChild(
"tabcontainer-body",
size,
false,
1754 ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
1755 int tabBarIndex = -1;
1756 std::vector<int> pageIndices;
1757 for (
int c =
n.firstChild;
c >= 0;
c = tree->nodes[size_t(
c)].nextSibling) {
1758 UINode &
child = tree->nodes[size_t(
c)];
1763 pageIndices.push_back(
c);
1765 if (
n.valueText.empty() && !pageIndices.empty()) {
1766 const UINode &
first = tree->nodes[size_t(pageIndices.front())];
1769 if (tabBarIndex >= 0) {
1770 UINode &bar = tree->nodes[size_t(tabBarIndex)];
1771 for (
int t = bar.firstChild;
t >= 0;
t = tree->nodes[size_t(
t)].nextSibling) {
1772 UINode &tabNode = tree->nodes[size_t(
t)];
1774 tabNode.checked = !
n.valueText.empty() && tabNode.valueText ==
n.valueText;
1776 const size_t pendingBefore = g_pending.size();
1777 walkNode(
host, tree, tabBarIndex);
1778 const size_t pendingAfter = g_pending.size();
1779 for (
size_t i = pendingBefore; i < pendingAfter; ++i) {
1780 const UIEvent &ev = g_pending[i];
1781 if (ev.kind !=
"click")
continue;
1782 for (
int t = bar.firstChild;
t >= 0;
t = tree->nodes[size_t(
t)].nextSibling) {
1783 UINode &tabNode = tree->nodes[size_t(
t)];
1784 if (tabNode.type !=
NodeType::Tab || ev.nodeId != tabNode.id)
continue;
1785 if (tabNode.valueText.empty() || tabNode.valueText ==
n.valueText)
continue;
1786 n.valueText = tabNode.valueText;
1787 pushPending(
host,
n,
"text",
n.handlerText,
false, 0.f,
n.valueText);
1788 for (
int u = bar.firstChild;
u >= 0;
u = tree->nodes[size_t(
u)].nextSibling) {
1789 UINode &sibling = tree->nodes[size_t(
u)];
1790 if (sibling.type ==
NodeType::Tab) sibling.checked = sibling.valueText ==
n.valueText;
1795 for (
int pageIndex : pageIndices) {
1796 UINode &page = tree->nodes[size_t(pageIndex)];
1797 const std::string pageId = page.id.empty() ? page.key : page.id;
1798 page.visible = !
n.valueText.empty() && pageId ==
n.valueText;
1799 if (!page.visible)
continue;
1800 const ImVec2 pageAvail = ImGui::GetContentRegionAvail();
1801 page.sizeX = pageAvail.x;
1802 page.sizeY = pageAvail.y;
1803 walkNode(
host, tree, pageIndex);
1807 ImGui::PopStyleVar();
1815 const ImVec2 avail = ImGui::GetContentRegionAvail();
1816 const ImVec2
size(
n.sizeX > 0.f ?
n.sizeX : avail.
x,
n.sizeY > 0.f ?
n.sizeY : avail.
y);
1817 const std::string
id =
n.id.empty() ?
"panelframe" :
n.id;
1818 const float headerH =
layout.panelHeaderHeight *
scale;
1819 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding,
1821 ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetStyleColorVec4(ImGuiCol_ChildBg));
1822 if (ImGui::BeginChild(
id.c_str(),
size,
true, ImGuiWindowFlags_AlwaysUseWindowPadding)) {
1823 if (!
n.text.empty()) {
1824 const ImVec2
pos = ImGui::GetCursorScreenPos();
1825 const float width = ImGui::GetContentRegionAvail().x;
1826 ImGui::GetWindowDrawList()->AddRectFilled(
pos, ImVec2(
pos.x +
width,
pos.y + headerH),
1827 ImGui::GetColorU32(ImGuiCol_MenuBarBg));
1828 ImGui::SetCursorScreenPos(
1829 ImVec2(
pos.x +
layout.barPaddingX *
scale,
pos.y + (headerH - ImGui::GetTextLineHeight()) * 0.5f));
1830 ImGui::TextUnformatted(
n.text.c_str());
1831 ImGui::SetCursorScreenPos(ImVec2(
pos.x,
pos.y + headerH +
layout.sectionSpacingY *
scale));
1833 if (
n.firstChild >= 0) walkSiblings(
host, tree,
n.firstChild);
1836 ImGui::PopStyleColor();
1837 ImGui::PopStyleVar();
1843 const ImVec2 avail = ImGui::GetContentRegionAvail();
1844 const ImVec2
size(
n.sizeX > 0.f ?
n.sizeX : avail.
x,
n.sizeY > 0.f ?
n.sizeY : avail.
y);
1845 const std::string
id =
n.id.empty() ?
"dockarea" :
n.id;
1846 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding,
1848 ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetStyleColorVec4(ImGuiCol_ChildBg));
1849 if (ImGui::BeginChild(
id.c_str(),
size,
false,
1850 ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_NoScrollbar)) {
1851 if (
n.firstChild >= 0) {
1853 if (
n.firstChild >= 0 && tree->nodes[
size_t(
n.firstChild)].nextSibling < 0) {
1854 UINode &
child = tree->nodes[size_t(
n.firstChild)];
1855 const ImVec2 childAvail = ImGui::GetContentRegionAvail();
1859 walkSiblings(
host, tree,
n.firstChild);
1863 ImGui::PopStyleColor();
1864 ImGui::PopStyleVar();
1868 const ImVec2 avail = ImGui::GetContentRegionAvail();
1869 n.sizeX =
n.sizeX > 0.f ?
n.sizeX : avail.x;
1870 n.sizeY =
n.sizeY > 0.f ?
n.sizeY : avail.y;
1872 walkFlex(
host, tree,
n);
1876 walkFlex(
host, tree,
n);
1879 walkGrid(
host, tree,
n);
1883 emitSpacer(
n.sizeX > 0.f ?
n.sizeX : 0.f,
n.sizeY > 0.f ?
n.sizeY : 0.f, true);
1888 n.focused = ImGui::IsItemFocused();
1889 routeExplicitFocusInput(
host,
n);
1890 n.focusRequested =
false;
1892 if (disableNavigation) ImGui::PopItemFlag();
1894 ImGui::PopStyleVar();
1895 ImGui::PopItemFlag();
1898 renderDragDrop(
host,
n);
1899 const std::string &
tip = !
n.enabled && !
n.disabledReason.empty() ?
n.disabledReason :
n.tooltip;
1900 if (!
tip.empty() && (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) ||
n.focused))
1901 ImGui::SetTooltip(
"%s",
tip.c_str());
1902 if (!
n.helpText.empty()) ImGui::TextDisabled(
"%s",
n.helpText.c_str());
1904 if (styleVarCount > 0) ImGui::PopStyleVar(styleVarCount);
1905 if (styleColorCount > 0) ImGui::PopStyleColor(styleColorCount);
1914void walk(UIHost *
host, UIHost::Tree *tree,
int index) { walkSiblings(
host, tree,
index); }
1924#if (defined(_WIN32) || defined(__APPLE__) || defined(__linux__)) && \
1925 !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
1934 g_pendingFileDrops.push_back(
path);
1938 if (g_drops.empty())
return std::nullopt;
1940 g_drops.erase(g_drops.begin());
1947 if (!g_backend)
return std::nullopt;
1948 return std::ref(*g_backend);
1954 if (
key.empty() ||
w <= 0 ||
h <= 0) {
1959 auto *gfx = eve::ModuleManager::getInstance<eve::graphics::Graphics>(
"Graphics");
1979 if (vs.
canvas && g_backend)
1982 return Return::success(std::ref(vs));
1986 const std::string &
nodeId) {
1987 auto it = g_viewports.find(hostName +
"/" +
nodeId);
1988 if (it == g_viewports.end())
return std::nullopt;
1989 return std::ref(it->second);
1993 if (
name.empty())
return {};
1994 if (ecs::current()->getManager<UIHost>() ==
nullptr)
return {};
1995 auto view = ecs::View<UIHost, UIHost::Meta, UIHost::Tree>();
1996 for (
auto it =
view.begin(); it !=
view.end(); ++it) {
1997 auto [meta, tree] = *it;
2005 if (ownerId == 0)
return {};
2006 if (ecs::current()->getManager<UIHost>() ==
nullptr)
return {};
2007 auto view = ecs::View<UIHost, UIHost::Meta, UIHost::Tree>();
2008 for (
auto it =
view.begin(); it !=
view.end(); ++it) {
2009 auto [meta, tree] = *it;
2011 if (meta->ownerId == ownerId &&
UIHost::resolve(meta->entity))
return meta->entity;
2019 if (ecs::current()->getManager<UIHost>() ==
nullptr)
return;
2029 std::vector<Item> items;
2032 const ImVec2 display = ImGui::GetIO().DisplaySize;
2033 auto view = ecs::View<UIHost, UIHost::Meta, UIHost::Tree>();
2034 for (
auto it =
view.begin(); it !=
view.end(); ++it) {
2035 auto [meta, tree] = *it;
2036 if (!meta->visible)
continue;
2038 if (!
host)
continue;
2039 if (!updateWorldAnchor(
host->get(),
camera, display.x, display.y))
continue;
2040 items.push_back(Item{&
host->get(), meta, tree,
true});
2043 std::stable_sort(items.begin(), items.end(),
2044 [](
const Item &
a,
const Item &
b) { return a.meta->layer < b.meta->layer; });
2046 g_stats.nodeCount = 0;
2047 g_stats.measureMs = 0.0;
2048 g_stats.walkMs = 0.0;
2049 for (
auto &item : items) {
2050 item.tree->dirty =
false;
2051 HostThemeScope
theme(item.host);
2052 HudCanvasScope canvas(*item.host);
2053 const auto m0 = std::chrono::steady_clock::now();
2055 const auto m1 = std::chrono::steady_clock::now();
2056 g_stats.nodeCount += int(item.tree->nodes.size());
2057 g_stats.measureMs +=
2058 std::chrono::duration<double, std::milli>(m1 - m0).count();
2061 std::vector<WorldAnchorLayoutItem> anchorItems;
2062 anchorItems.reserve(items.size());
2063 const ImGuiStyle &style = ImGui::GetStyle();
2064 for (std::size_t i = 0; i < items.size(); ++i) {
2065 auto &item = items[i];
2066 auto anchor = item.host->worldAnchor();
2067 if (!anchor->enabled)
continue;
2068 float width = item.meta->hasSize ? item.meta->sizeX : 0.f;
2069 float height = item.meta->hasSize ? item.meta->sizeY : 0.f;
2070 if (item.meta->percentW > 0.f)
width = item.meta->percentW * display.x;
2071 if (item.meta->percentH > 0.f)
height = item.meta->percentH * display.y;
2072 if (item.tree->root >= 0) {
2073 const auto &
root = item.tree->nodes[std::size_t(item.tree->root)];
2074 if (
width <= 0.f)
width =
root.measuredW + style.WindowPadding.x * 2.f;
2077 width *= anchor->scale;
2079 anchorItems.push_back({i,
2088 anchor->overlapPadding,
2089 anchor->maxDisplacement,
2090 anchor->overlapPriority,
2095 auto &item = items[
resolved.stableIndex];
2096 auto anchor = item.host->worldAnchor();
2097 anchor->screenX =
resolved.screenX;
2098 anchor->screenY =
resolved.screenY;
2099 anchor->displacementX =
resolved.displacementX;
2100 anchor->displacementY =
resolved.displacementY;
2105 g_stats.hostCount = int(std::count_if(items.begin(), items.end(),
2106 [](
const Item &item) { return item.render; }));
2107 for (
auto &item : items) {
2108 if (!item.render)
continue;
2109 HostThemeScope
theme(item.host);
2110 HudCanvasScope canvas(*item.host);
2111 const auto w0 = std::chrono::steady_clock::now();
2112 if (item.tree->root >= 0) walk(item.host, item.tree, item.tree->root);
2113 const auto w1 = std::chrono::steady_clock::now();
2114 g_stats.walkMs += std::chrono::duration<double, std::milli>(w1 - w0).count();
2118 for (
auto &item : items) {
2119 item.meta->animDrivePos =
false;
2120 item.meta->animDriveSize =
false;
2125 auto events = std::move(g_pending);
2127 for (
auto &ev :
events) {
2129 if (!resolvedHost)
continue;
2132 if (ev.kind ==
"click" && !ev.nodeId.empty()) {
2134 c.
hostName = ev.hostName.empty() ?
host->meta()->name : ev.hostName;
2135 c.nodeId = ev.nodeId;
2136 g_clicks.push_back(std::move(
c));
2139 if ((ev.kind ==
"toggle" || ev.kind ==
"value" || ev.kind ==
"text") && !ev.nodeId.empty()) {
2141 ch.
hostName = ev.hostName.empty() ?
host->meta()->name : ev.hostName;
2144 g_changes.push_back(std::move(ch));
2147 if (ev.kind ==
"click") {
2148 auto tree =
host->tree();
2149 int index = ev.nodeIndex;
2150 if (index < 0 || index >=
int(tree->nodes.size()) ||
2151 tree->nodes[
size_t(
index)].id != ev.nodeId) {
2153 index =
target && !tree->nodes.empty() ? int(&
target->get() - tree->nodes.data()) : -1;
2157 while (
index >= 0 &&
index <
int(tree->nodes.size())) {
2159 if (!
node.visible || !
node.enabled)
break;
2162 const size_t handlerSlot = size_t(
handler - 1);
2163 if (handlerSlot < tree->clickHandlers.size() &&
2164 tree->clickHandlers[handlerSlot])
2165 tree->clickHandlers[handlerSlot]();
2174 if (ev.kind ==
"toggle" && ev.handlerIndex != 0) {
2175 auto t =
host->tree();
2176 size_t idx = size_t(ev.handlerIndex - 1);
2177 if (idx < t->toggleHandlers.size() &&
t->toggleHandlers[
idx])
2178 t->toggleHandlers[
idx](ev.toggleValue);
2181 if (ev.kind ==
"value" && ev.handlerIndex != 0) {
2182 auto t =
host->tree();
2183 size_t idx = size_t(ev.handlerIndex - 1);
2184 if (idx < t->valueHandlers.size() &&
t->valueHandlers[
idx])
2185 t->valueHandlers[
idx](ev.floatValue);
2188 if (ev.kind ==
"text" && ev.handlerIndex != 0) {
2189 auto t =
host->tree();
2190 size_t idx = size_t(ev.handlerIndex - 1);
2191 if (idx < t->textHandlers.size() &&
t->textHandlers[
idx])
2192 t->textHandlers[
idx](ev.textValue);
2199 if (g_clicks.empty())
return {};
2200 UIClick c = std::move(g_clicks.front());
2201 g_clicks.erase(g_clicks.begin());
2202 if (
c.hostName.empty())
return c.nodeId;
2203 return c.hostName +
"/" +
c.nodeId;
2207 for (
auto it = g_clicks.begin(); it != g_clicks.end(); ++it) {
2208 if (it->hostName != hostName)
continue;
2209 std::string
id = std::move(it->nodeId);
2217 if (g_changes.empty())
return {};
2218 UIChange c = std::move(g_changes.front());
2219 g_changes.erase(g_changes.begin());
2220 if (
c.hostName.empty())
return c.nodeId;
2221 return c.hostName +
"/" +
c.nodeId;
wgpu::PopErrorScopeStatus status
std::array< double, 10 > q
const ColourScope * parent
std::array< float, 3 > scale
OceanRenderBackend backend
std::vector< particles::ParticleRecordEvent > events
#define EV_PROFILE_MODULE(module, name)
Profile the enclosing scope, tagged with a module for grouping.
ImGuiConfigFlags previousConfigFlags
std::array< float, 6 > savedMeta
std::string sourceHostName
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
static Status failure(StatusCode code, Diagnostic diagnostic)
Construct a failed status with one diagnostic.
EVENGINE_API_BACKENDS public API.
virtual Texture * getTexture()=0
Sampleable color buffer; screen Canvas returns nullptr.
Platform / renderer backend for declarative UI. Concrete implementations live under ui/<backend>/ (e....
ECS mount point for one UI panel/screen. Subclass to attach UI to game entities, e....
static eve::OptionalRef< UIHost > resolve(UIHostHandle handle) noexcept
Resolves a UI host handle with ECS generation checking.
static std::vector< UIDrop > & dropQueue()
Returns the owning completed-drop queue.
static const UIStats & stats()
static void setBackend(UIBackend &backend)
Sets the borrowed backend used for the current UI/render lifetime.
static void clearBackend() noexcept
Clears the backend association before the backend is shut down.
static eve::OptionalRef< ViewportState > viewportState(const std::string &hostName, const std::string &nodeId)
Returns viewport state for a host/node key when it exists.
static void enqueuePlatformFileDrop(const std::string &path)
Copies an OS file-drop path into UI-owned pending state.
static std::vector< UIClick > & clickQueue()
static std::string consumeChange()
Pop next change as "name/node"; empty if none.
static eve::OptionalRef< UIBackend > backend()
Returns the configured backend for the current synchronous operation.
static UIHostHandle findHost(const std::string &name)
Lookup by Meta.name across the UIHost View.
static std::vector< UIChange > & changeQueue()
Change queue.
static void dispatchEvents()
Dispatches events.
static eve::ResultRef< ViewportState > ensureViewport(const std::string &key, int w, int h)
Creates or refreshes offscreen state for a viewport key.
static DragDropSupport dragDropSupport() noexcept
Returns retained drag-and-drop availability for this build target.
static std::string consumeClick()
Pop next click as "name/node"; empty if none.
static void render()
Walk all UIHost (+ subclasses) via ECS View.
static UIHostHandle findHostByOwner(uint32_t ownerId)
Find the first host with Meta.ownerId equal to ownerId, or null.
static std::optional< UIDrop > consumeDrop()
Pops the oldest completed drop, or returns empty when none exists.
static std::string consumeClickFor(const std::string &hostName)
Pop next click for a specific host; returns node id only (or "").
static std::vector< UIEvent > & pendingEvents()
Pending events.
int main(int argc, char **argv)
glm::mat4 cameraProjectionVulkanRH_ZO(bool orthographic, float fovyRad, float orthoHeight, float aspect, float zNear, float zFar)
Camera projection shared by rendering, picking, and diagnostic passes.
constexpr HexDirection next(HexDirection d) noexcept
The next direction clockwise (NW wraps to NE).
Result< ForceVector > checked(ForceVector value)
V3 cross(V3 a, V3 b)
Module-private road bake implementation helper.
ControlEdit slider(const char *label, float &value, float minimum, float maximum, const char *format="%.3f")
Shared immediate renderer for scalar sliders.
ControlEdit button(const char *label, float width=0.f, float height=0.f)
Shared immediate renderer for retained and EditorHost buttons.
ControlEdit combo(const char *label, int &selected, const std::vector< const char * > &items)
Shared immediate renderer for indexed combo boxes.
ControlEdit inputText(const char *label, std::string &value, bool multiline=false, ImVec2 multilineSize=ImVec2(0.f, 96.f), bool readOnly=false, const char *hint="")
UTF-8 owning text editor with automatic buffer growth.
ControlEdit inputTextWithHint(const char *label, const char *hint, std::string &value)
UTF-8 owning single-line editor with placeholder text and automatic growth.
ControlEdit textLink(const char *label)
Render a keyboard-accessible text link without launching its target.
ControlEdit checkbox(const char *label, bool &value)
Shared immediate renderer for retained and EditorHost checkboxes.
ControlEdit
Result of drawing one immediate control in the current frame.
void flushPendingComponents()
Flush one batch of live dirty components before host traversal. @thread Owner thread; newly queued ed...
RadialFillMesh radialFillMesh(float fraction, float startDegrees, bool clockwise, float innerRadius)
Builds an elliptical sector/ring in [0,1] coordinates; zero degrees points right.
const char * iconGlyph(Icon icon)
Returns the UTF-8 glyph for an icon, or an empty string for None.
DragDropSupport
Build-target availability of retained drag-and-drop.
GridResult gridArrange(int columns, float columnGap, float rowGap, float availWidth, const std::vector< GridItemSpec > &items)
Places source-ordered items into equal-width fixed columns.
void measureTree(UIHost::Tree &tree)
Measure tree.
std::vector< WorldAnchorLayoutResult > resolveWorldAnchorOverlaps(std::vector< WorldAnchorLayoutItem > items, float viewportWidth, float viewportHeight)
Resolves projected host overlap with bounded deterministic vertical displacement.
LinearFillRect linearFillRect(float fraction, FillDirection direction, bool stretch)
Computes cropped geometry/UVs; stretch preserves the complete source UV rectangle.
WidgetDesc child(std::string id, std::vector< WidgetDesc > children, float width, float height)
Scrollable child region with an explicit size.
NodeType
Widget node kinds understood by the UI renderer.
FocusDirection
Logical focus movement understood by keyboard, gamepad and automation.
WidgetDesc grid(int columns, std::vector< WidgetDesc > children, std::string id)
Fixed-column grid; children are placed in source order.
WidgetDesc viewport(std::string id, float width, float height)
Viewport.
NinePatchAxis ninePatchAxis(float size, float nearBorder, float farBorder, float uv0, float uv1, float textureSize, float scale)
Scales border geometry while retaining source texel coverage; scale/textureSize must be positive.
WidgetDesc flex(FlexDirection direction, std::vector< WidgetDesc > children, std::string id)
Elastic layout container (row/column). Prefer row / column shorthands.
ecs::EntityHandle UIHostHandle
FillDirection
Direction of a linear image fill; geometry stays inside the original layout box.
WorldAnchorProjection projectWorldAnchor(const UIHost::WorldAnchor &anchor, const glm::mat4 &viewProjection, float cameraX, float cameraY, float cameraZ, float viewportWidth, float viewportHeight)
Projects one world-space UI anchor using a Vulkan RH-ZO view-projection matrix.
Theme & globalTheme()
Global theme.
WidgetDesc row(std::vector< WidgetDesc > children, std::string id)
Horizontal elastic layout row.
FlexResult flexArrange(bool row, float gap, float availMain, float availCross, FlexAlign containerAlign, FlexJustify justify, const std::vector< FlexItemSpec > &items, bool wrap, float crossGap)
Flex arrange.
void applyThemeToImGui(const Theme &theme)
Push tokens into ImGui style. Metrics are multiplied by uiScale (default: themeUiScale()).
float themeUiScale()
Theme ui scale.
WidgetDesc list(std::string listId, const std::vector< std::string > &items, const std::function< WidgetDesc(const std::string &, int)> &itemFn)
Expand a string list into a Group of item widgets. itemFn(label, index) builds each row; keys default...
HudCanvasTransform resolveHudCanvas(const HudCanvas &canvas, float width, float height)
Resolves fit scaling without letterboxing anchors; callers validate positive viewport dimensions.
static Theme dark()
Built-in presets with matching geometry; only colors differ.
Value/text/toggle change for script: "hostName/nodeId".
One script-facing click: "hostName/nodeId".
One completed desktop drop with no borrowed node or platform pointers.
Retained UI widget node (arena tree). Conceptual counterpart of eve::scene::SceneNode; built declarat...
ViewportState public API.
graphics::Canvas * canvas
std::map< std::string, ImVec2 > rectMin
std::map< std::string, ImVec2 > rectMax