载入中...
搜索中...
未找到
UISystem.cpp
浏览该文件的文档.
1// eve-hot-path
2#include "ui/UISystem.h"
3#include "ui/Component.h"
4
6#include "ui/HudGeometry.h"
7#include "ui/Icons.h"
8#include "ui/Layout.h"
9#include "ui/Theme.h"
10#include "ui/UIBackend.h"
12
13#include "common/Module.h"
14#include "common/Profile.h"
15#include "graphics/Graphics.h"
16#include "graphics/ClipSpace.h"
18
19#include <imgui.h>
20#include <imgui_internal.h>
21#include <glm/mat4x4.hpp>
22
23#include <algorithm>
24#include <cfloat>
25#include <chrono>
26#include <cmath>
27#include <cstdio>
28#include <cstring>
29#include <iterator>
30#include <map>
31#include <string>
32#include <vector>
33
34namespace eve::ui {
35namespace {
36
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;
43UIStats g_stats;
44float g_hudScale = 1.f;
45std::map<std::string, ViewportState> g_viewports;
46
47struct HostThemeScope {
48 bool active = false;
49 ImGuiStyle previousStyle;
50 float previousFontScale = 1.f;
51 ImGuiConfigFlags previousConfigFlags = ImGuiConfigFlags_None;
52
53 explicit HostThemeScope(UIHost *host) {
54 if (!host || !host->hasThemeOverride() || !host->themeOverride()) return;
55 previousStyle = ImGui::GetStyle();
56 previousFontScale = ImGui::GetIO().FontGlobalScale;
57 previousConfigFlags = ImGui::GetIO().ConfigFlags;
58 applyThemeToImGui(*host->themeOverride());
59 active = true;
60 }
61
62 ~HostThemeScope() {
63 if (!active) return;
64 ImGui::GetStyle() = previousStyle;
65 ImGui::GetIO().FontGlobalScale = previousFontScale;
66 ImGui::GetIO().ConfigFlags = previousConfigFlags;
67 }
68
69 HostThemeScope(const HostThemeScope &) = delete;
70 HostThemeScope &operator=(const HostThemeScope &) = delete;
71};
72
73// UI-thread-only scratch reused by sequential measure/walk passes. No callbacks run in these passes.
74constexpr auto hudMetrics = std::to_array<float UINode::*>(
80std::vector<std::array<float, hudMetrics.size()>> g_hudMetricScratch;
81
82struct HudCanvasScope {
83 UIHost &host;
84 bool active = false;
85 std::array<float, 6> savedMeta{};
86 ImGuiStyle savedStyle;
87 float savedFontScale = 1.f;
88 float savedHudScale = 1.f;
89
90 bool savedWriteAccessed = false;
91
92 explicit HudCanvasScope(UIHost &target) : host(target) {
93 auto meta = host.meta();
94 if (!meta->canvas.enabled || host.worldAnchor()->enabled) return;
95 const ImVec2 display = ImGui::GetIO().DisplaySize;
96 const auto transform = resolveHudCanvas(meta->canvas, display.x, display.y);
97 active = true;
98 savedHudScale = g_hudScale;
99 g_hudScale = transform.scale;
100 savedMeta = {meta->posX, meta->posY, meta->sizeX, meta->sizeY, meta->percentW, meta->percentH};
101 savedStyle = ImGui::GetStyle();
102 savedFontScale = ImGui::GetCurrentWindowRead()->FontWindowScale;
103 savedWriteAccessed = ImGui::GetCurrentWindowRead()->WriteAccessed;
104 ImGui::GetStyle().ScaleAllSizes(transform.scale);
105 ImGui::SetWindowFontScale(savedFontScale * transform.scale);
106 ImGui::GetCurrentWindowRead()->WriteAccessed = savedWriteAccessed;
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) {
118 auto &value = node.*hudMetrics[m];
119 g_hudMetricScratch[i][m] = value;
120 if (value >= 0.f || (hudMetrics[m] != &UINode::gap && hudMetrics[m] != &UINode::flexBasis &&
121 hudMetrics[m] != &UINode::columnGap && hudMetrics[m] != &UINode::rowGap))
122 value *= transform.scale; // negative metrics mean automatic/inherit
123 }
124 }
125 }
126
127 HudCanvasScope(const HudCanvasScope &) = delete;
128 HudCanvasScope &operator=(const HudCanvasScope &) = delete;
129
130 ~HudCanvasScope() {
131 if (!active) return;
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();
137 meta->posX = savedMeta[0];
138 meta->posY = savedMeta[1];
139 meta->sizeX = savedMeta[2];
140 meta->sizeY = savedMeta[3];
141 meta->percentW = savedMeta[4];
142 meta->percentH = savedMeta[5];
143 ImGui::GetStyle() = savedStyle;
144 ImGui::SetWindowFontScale(savedFontScale);
145 ImGui::GetCurrentWindowRead()->WriteAccessed = savedWriteAccessed;
146 g_hudScale = savedHudScale;
147 }
148};
149
150struct ActiveDragPayload {
151 uint64_t serial = 0;
152 std::string sourceHostName;
153 std::string sourceNodeId;
154 std::string payloadType;
155 std::string payloadText;
156};
157
158std::optional<ActiveDragPayload> g_activeDrag;
159uint64_t g_nextDragSerial = 1;
160
161bool acceptsDropType(const UINode &node, const std::string &type) {
162 return node.dropTarget && (node.acceptedDropType == "*" || node.acceptedDropType == type);
163}
164
165void renderDragDrop(UIHost *host, const UINode &node) {
167 !node.enabled)
168 return;
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};
177 }
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();
183 }
184
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)) &&
191 g_activeDrag) {
192 const uint64_t serial = *static_cast<const uint64_t *>(payload->Data);
193 if (serial == g_activeDrag->serial) {
194 g_drops.push_back({DragDropOrigin::Internal,
195 g_activeDrag->sourceHostName,
196 g_activeDrag->sourceNodeId,
197 hostName,
198 node.id,
199 g_activeDrag->payloadType,
200 g_activeDrag->payloadText});
201 g_activeDrag.reset();
202 }
203 }
204 }
205 ImGui::EndDragDropTarget();
206 }
207
208 if (!g_pendingFileDrops.empty() && acceptsDropType(node, "file") &&
209 ImGui::IsItemHovered()) {
210 for (auto &path : g_pendingFileDrops) {
211 g_drops.push_back({DragDropOrigin::OperatingSystemFile, "", "", hostName,
212 node.id, "file", std::move(path)});
213 }
214 g_pendingFileDrops.clear();
215 }
216}
217
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) {
222 auto [data] = *it;
223 if (data->active) return data->entity;
224 }
225 return nullptr;
226}
227
228bool updateWorldAnchor(UIHost &host, graphics::Camera3D *camera, float width, float height) {
229 auto anchor = host.worldAnchor();
230 if (!anchor->enabled) {
231 anchor->state = WorldAnchorState::Disabled;
232 return true;
233 }
234 if (!camera || width <= 0.f || height <= 0.f) {
235 anchor->state = WorldAnchorState::NoCamera;
236 return false;
237 }
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);
242 const glm::mat4 view = glm::lookAtRH(eye, target, up);
243 const glm::mat4 projection = graphics::cameraProjectionVulkanRH_ZO(
244 data->orthographic, glm::radians(data->fovYDeg), data->orthoHeight,
245 width / height, data->nearZ, data->farZ);
246 const auto projected = projectWorldAnchor(*anchor, projection * view, data->eyeX,
247 data->eyeY, data->eyeZ, width, height);
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;
256}
257
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);
262}
263
264void pushPending(UIHost *host, const UINode &n, const char *kind, uint32_t handlerIndex,
265 bool toggleValue = false, float floatValue = 0.f, std::string textValue = {}) {
266 if (!n.enabled || n.mouseFilter == MouseFilter::Ignore) return;
267 UIEvent ev;
268 if (!host) return;
269 ev.host = host->handle();
270 ev.hostName = host ? host->meta()->name : "";
271 ev.nodeId = n.id;
272 if (host) {
273 auto tree = host->tree();
274 if (!tree->nodes.empty()) ev.nodeIndex = int(&n - tree->nodes.data());
275 }
276 ev.kind = kind;
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));
282}
283
284std::string nodeLabel(const UINode &node, const char *fallback) {
285 std::string label = node.text.empty() ? fallback : node.text;
286 if (!node.id.empty()) label += "###" + node.id;
287 return label;
288}
289
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)
296 return false;
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);
301 return true;
302}
303
304bool isInteractive(NodeType type) {
305 switch (type) {
306 case NodeType::Link:
307 case NodeType::Button:
309 case NodeType::Slider:
312 case NodeType::Combo:
315 case NodeType::Switch:
318 case NodeType::Tab: return true;
319 default: return false;
320 }
321}
322
323struct PaletteSwatch {
324 float r = 1.f;
325 float g = 1.f;
326 float b = 1.f;
327 float a = 1.f;
328};
329
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},
340 };
341 out.insert(out.end(), std::begin(kDefaults), std::end(kDefaults));
342}
343
344bool parsePaletteSwatch(std::string token, PaletteSwatch &out) {
345 while (!token.empty() && (token.back() == ' ' || token.back() == '\r' || token.back() == '\t'))
346 token.pop_back();
347 size_t start = 0;
348 while (start < token.size() && (token[start] == ' ' || token[start] == '\t')) ++start;
349 token = token.substr(start);
350 if (token.empty()) return false;
351 if (token[0] == '#') {
352 unsigned value = 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;
357 out.a = 1.f;
358 return true;
359 }
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;
365 return true;
366 }
367 return false;
368 }
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;
372 out.r = r;
373 out.g = g;
374 out.b = b;
375 if (n >= 4) out.a = a;
376 return true;
377}
378
379std::vector<PaletteSwatch> paletteSwatches(const UINode &n) {
380 std::vector<PaletteSwatch> swatches;
381 const std::string &src = n.valueText;
382 size_t i = 0;
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);
388 i = end + 1;
389 }
390 if (swatches.empty()) appendDefaultPaletteSwatches(swatches);
391 return swatches;
392}
393
394void commitPaletteColor(UIHost *host, UINode &n, const float col[4]) {
395 n.tintR = col[0];
396 n.tintG = col[1];
397 n.tintB = col[2];
398 n.tintA = col[3];
399 n.value = col[0];
400 pushPending(host, n, "value", n.handlerValue, false, col[0]);
401}
402
403bool keyPressed(ImGuiKey key) {
404 const int index = ImGui::GetKeyIndex(key);
405 return index >= 0 && ImGui::IsKeyPressed(index, false);
406}
407
408void routeExplicitFocusInput(UIHost *host, const UINode &node) {
409 if (!host || !node.focused || node.focusMode != FocusMode::All) return;
410 if (keyPressed(ImGuiKey_Tab)) {
411 const bool backwards = ImGui::GetIO().KeyShift;
412 const std::string &target = backwards ? node.focusPrevious : node.focusNext;
413 if (!target.empty())
414 host->moveFocus(backwards ? FocusDirection::Previous : FocusDirection::Next);
415 return;
416 }
417 if (ImGui::IsItemActive()) return;
418 if (!node.focusLeft.empty() && keyPressed(ImGuiKey_LeftArrow))
419 host->moveFocus(FocusDirection::Left);
420 else if (!node.focusRight.empty() && keyPressed(ImGuiKey_RightArrow))
421 host->moveFocus(FocusDirection::Right);
422 else if (!node.focusUp.empty() && keyPressed(ImGuiKey_UpArrow))
423 host->moveFocus(FocusDirection::Up);
424 else if (!node.focusDown.empty() && keyPressed(ImGuiKey_DownArrow))
425 host->moveFocus(FocusDirection::Down);
426}
427
428void walkNode(UIHost *host, UIHost::Tree *tree, int index);
429
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)];
434 // Desktop composition behaves like CSS grid rows: menu/toolbar and
435 // status bar keep their intrinsic height while the workspace consumes
436 // the remaining block size. An explicit split height still wins.
437 if (node.type == NodeType::SplitPane && node.sizeY <= 0.f && next >= 0 &&
438 next < int(tree->nodes.size()) &&
439 tree->nodes[size_t(next)].type == NodeType::StatusBar) {
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);
444 walkNode(host, tree, index);
445 node.sizeY = oldY;
446 } else {
447 walkNode(host, tree, index);
448 }
449 index = next;
450 }
451}
452
453void walkPaneChild(UIHost *host, UIHost::Tree *tree, int index) {
454 if (index < 0 || index >= int(tree->nodes.size())) return;
455 UINode &child = tree->nodes[size_t(index)];
456 const ImVec2 avail = ImGui::GetContentRegionAvail();
457 const float oldX = child.sizeX;
458 const float oldY = child.sizeY;
459 // A direct SplitPane child fills its allocated pane. Descendants can still
460 // specialize their own dimensions through normal widget layout props.
461 child.sizeX = std::max(1.f, avail.x);
462 child.sizeY = std::max(1.f, avail.y);
463 child.measuredW = child.sizeX;
464 child.measuredH = child.sizeY;
465 walkNode(host, tree, index);
466 child.sizeX = oldX;
467 child.sizeY = oldY;
468}
469
470bool hasDirectChildType(const UIHost::Tree &tree, const UINode &parent, NodeType type) {
471 for (int child = parent.firstChild; child >= 0;
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;
475 }
476 return false;
477}
478
479void emitSpacer(float main, float cross, bool row) {
480 if (main < 0.f) main = 0.f;
481 if (cross < 0.f) cross = 0.f;
482 if (row) {
483 if (main <= 0.f && cross <= 0.f) {
484 ImGui::Dummy(ImVec2(0.f, 0.f));
485 } else {
486 ImGui::Dummy(ImVec2(main, cross > 0.f ? cross : 1.f));
487 }
488 } else {
489 if (main <= 0.f && cross <= 0.f) {
490 ImGui::Dummy(ImVec2(0.f, 0.f));
491 } else {
492 ImGui::Dummy(ImVec2(cross > 0.f ? cross : 1.f, main));
493 }
494 }
495}
496
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,
500 ImU32 tint) {
501 ImDrawList *dl = ImGui::GetWindowDrawList();
502 const auto draw = [&](float x0, float y0, float x1, float y1, float u0, float v0, float u1,
503 float v1) {
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);
506 };
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);
509 return;
510 }
511 if (texW <= 0 || texH <= 0) {
512 draw(0.f, 0.f, size.x, size.y, uv0.x, uv0.y, uv1.x, uv1.y);
513 return;
514 }
515 const auto x = ninePatchAxis(size.x, bL, bR, uv0.x, uv1.x, float(texW), g_hudScale);
516 const auto y = ninePatchAxis(size.y, bT, bB, uv0.y, uv1.y, float(texH), g_hudScale);
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;
519 // Corners
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);
523 draw(size.x - br, size.y - bb, size.x, size.y, uR, vB, uv1.x, uv1.y);
524 // Edges
525 draw(bl, 0.f, size.x - br, bt, uL, uv0.y, uR, vT);
526 draw(bl, size.y - bb, size.x - br, size.y, uL, vB, uR, uv1.y);
527 draw(0.f, bt, bl, size.y - bb, uv0.x, vT, uL, vB);
528 draw(size.x - br, bt, size.x, size.y - bb, uR, vT, uv1.x, vB);
529 // Center
530 draw(bl, bt, size.x - br, size.y - bb, uL, vT, uR, vB);
531}
532
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);
544 };
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);
547 return;
548 }
549 const auto x = ninePatchAxis(size.x, bL, bR, uv0.x, uv1.x, float(texW), g_hudScale);
550 const auto y = ninePatchAxis(size.y, bT, bB, uv0.y, uv1.y, float(texH), g_hudScale);
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);
556 draw(size.x - br, size.y - bb, size.x, size.y, uR, vB, uv1.x, uv1.y);
557 draw(bl, 0.f, size.x - br, bt, uL, uv0.y, uR, vT);
558 draw(bl, size.y - bb, size.x - br, size.y, uL, vB, uR, uv1.y);
559 draw(0.f, bt, bl, size.y - bb, uv0.x, vT, uL, vB);
560 draw(size.x - br, bt, size.x, size.y - bb, uR, vT, uv1.x, vB);
561 draw(bl, bt, size.x - br, size.y - bb, uL, vT, uR, vB);
562}
563
564void walkFlex(UIHost *host, UIHost::Tree *tree, UINode &flex) {
566 const ImGuiStyle &style = ImGui::GetStyle();
567 const float legacyGap =
568 flex.gap >= 0.f ? flex.gap : (row ? style.ItemSpacing.x : style.ItemSpacing.y);
569 const float gap = row ? (flex.columnGap >= 0.f ? flex.columnGap : legacyGap)
570 : (flex.rowGap >= 0.f ? flex.rowGap : legacyGap);
571 const float crossGap = row ? (flex.rowGap >= 0.f ? flex.rowGap : style.ItemSpacing.y)
572 : (flex.columnGap >= 0.f ? flex.columnGap : style.ItemSpacing.x);
573
574 // Own content box: an explicit size (set by the parent's arrange) wins;
575 // otherwise use the available region (root flex inside a window/child).
576 const ImVec2 avail = ImGui::GetContentRegionAvail();
577 const bool fillsContainer = flex.type == NodeType::Toolbar || flex.type == NodeType::StatusBar ||
579 const float flexW = flex.sizeX > 0.f ? flex.sizeX : avail.x;
580 const float flexH =
581 flex.sizeY > 0.f ? flex.sizeY : (fillsContainer ? avail.y : flex.measuredH);
582 const float padMain = row ? flex.paddingL + flex.paddingR : flex.paddingT + flex.paddingB;
583 const float padCross = row ? flex.paddingT + flex.paddingB : flex.paddingL + flex.paddingR;
584 const float availMain = (row ? flexW : flexH) - padMain;
585 const float availCross = (row ? flexH : flexW) - padCross;
586
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)];
593 if (!child.visible) continue;
594 if (child.absolute) {
595 absKids.push_back(c);
596 continue;
597 }
598 kids.push_back(c);
599 FlexItemSpec s;
600 s.basisMain = row ? child.measuredW : child.measuredH;
601 s.basisCross = row ? child.measuredH : child.measuredW;
602 s.marginBefore = row ? child.marginL : child.marginT;
603 s.marginAfter = row ? child.marginR : child.marginB;
604 s.marginCrossBefore = row ? child.marginT : child.marginL;
605 s.marginCrossAfter = row ? child.marginB : child.marginR;
606 s.flexGrow = child.flexGrow;
607 s.flexShrink = child.flexShrink;
608 s.flexBasis = child.flexBasis;
609 s.alignSelf = child.alignSelf;
610 s.aspectRatio = child.aspectRatio;
611 s.isSpacer = child.type == NodeType::Spacer;
612 s.minMain = row ? child.minSizeX : child.minSizeY;
613 s.maxMain = row ? child.maxSizeX : child.maxSizeY;
614 s.minCross = row ? child.minSizeY : child.minSizeX;
615 s.maxCross = row ? child.maxSizeY : child.maxSizeX;
616 s.percentMain = row ? child.percentW : child.percentH;
617 s.percentCross = row ? child.percentH : child.percentW;
618 s.explicitMain = row ? child.sizeX : child.sizeY;
619 s.explicitCross = row ? child.sizeY : child.sizeX;
620 specs.push_back(s);
621 }
622
623 const FlexResult res =
624 flexArrange(row, gap, std::max(0.f, availMain), std::max(0.f, availCross),
626 flex.flexWrap == FlexWrap::Wrap, crossGap);
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);
633 const bool scrolling = flex.overflow == OverflowMode::Scroll;
634 if (scrolling) {
635 ImGui::PushID(&flex);
636 ImGui::BeginChild("layout-scroll", ImVec2(std::max(0.f, flexW), std::max(0.f, flexH)),
637 false, ImGuiWindowFlags_HorizontalScrollbar);
638 }
639 const ImVec2 cursor = ImGui::GetCursorScreenPos();
640 const float dummyW = scrolling ? std::max(flexW, res.contentW + flex.paddingL + flex.paddingR)
641 : flexW;
642 const float dummyH = scrolling ? std::max(flexH, res.contentH + flex.paddingT + flex.paddingB)
643 : flexH;
644 ImGui::Dummy(ImVec2(std::max(0.f, dummyW), std::max(0.f, dummyH)));
645 const ImVec2 flowEnd = ImGui::GetCursorScreenPos();
646 const ImVec2 origin = ImVec2(cursor.x + flex.paddingL, cursor.y + flex.paddingT);
647 const bool clipped = flex.overflow == OverflowMode::Clip;
648 if (clipped)
649 ImGui::PushClipRect(cursor, ImVec2(cursor.x + flexW, cursor.y + flexH), true);
650
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));
655 const float oldX = child.sizeX;
656 const float oldY = child.sizeY;
657 bool pushedWidth = false;
658 if (r.w > 0.f) child.sizeX = r.w;
659 if (r.h > 0.f) child.sizeY = r.h;
660 if (row || r.w > 0.f) {
661 ImGui::PushItemWidth(r.w > 0.f ? r.w : 1.f);
662 pushedWidth = true;
663 }
664 walkNode(host, tree, kids[i]);
665 child.sizeX = oldX;
666 child.sizeY = oldY;
667 if (pushedWidth) ImGui::PopItemWidth();
668 }
669
670 // Absolutely placed children are excluded from flow; draw on top of it.
671 for (int c : absKids) {
672 UINode &child = tree->nodes[size_t(c)];
673 float w = child.percentW > 0.f ? child.percentW * flexW : child.measuredW;
674 float h = child.percentH > 0.f ? child.percentH * flexH : child.measuredH;
675 if (child.sizeX > 0.f) w = child.sizeX;
676 if (child.sizeY > 0.f) h = child.sizeY;
677 if (child.minSizeX > 0.f) w = std::max(w, child.minSizeX);
678 if (child.minSizeY > 0.f) h = std::max(h, child.minSizeY);
679 if (child.maxSizeX > 0.f) w = std::min(w, child.maxSizeX);
680 if (child.maxSizeY > 0.f) h = std::min(h, child.maxSizeY);
681 const float x = child.anchorX * flexW + child.posX - child.anchorX * w;
682 const float y = child.anchorY * flexH + child.posY - child.anchorY * h;
683 ImGui::SetCursorScreenPos(ImVec2(origin.x + x, origin.y + y));
684 const float oldX = child.sizeX;
685 const float oldY = child.sizeY;
686 child.sizeX = w;
687 child.sizeY = h;
688 if (w > 0.f) ImGui::PushItemWidth(w);
689 walkNode(host, tree, c);
690 child.sizeX = oldX;
691 child.sizeY = oldY;
692 if (w > 0.f) ImGui::PopItemWidth();
693 }
694 if (clipped) ImGui::PopClipRect();
695 ImGui::SetCursorScreenPos(flowEnd);
696 if (scrolling) {
697 ImGui::EndChild();
698 ImGui::PopID();
699 }
700}
701
702void walkGrid(UIHost *host, UIHost::Tree *tree, UINode &grid) {
703 const ImGuiStyle &style = ImGui::GetStyle();
704 const float columnGap = grid.columnGap >= 0.f
706 : (grid.gap >= 0.f ? grid.gap : style.ItemSpacing.x);
707 const float rowGap = grid.rowGap >= 0.f
708 ? grid.rowGap
709 : (grid.gap >= 0.f ? grid.gap : style.ItemSpacing.y);
710 const ImVec2 avail = ImGui::GetContentRegionAvail();
711 const float gridW = grid.sizeX > 0.f ? grid.sizeX : avail.x;
712 const float contentW = std::max(0.f, gridW - grid.paddingL - grid.paddingR);
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)];
719 if (!child.visible) continue;
720 if (child.absolute) {
721 absKids.push_back(c);
722 continue;
723 }
724 kids.push_back(c);
725 GridItemSpec spec;
726 spec.basisW = child.measuredW;
727 spec.basisH = child.measuredH;
728 spec.marginL = child.marginL;
729 spec.marginT = child.marginT;
730 spec.marginR = child.marginR;
731 spec.marginB = child.marginB;
732 spec.aspectRatio = child.aspectRatio;
733 spec.columnSpan = child.gridColumnSpan;
734 specs.push_back(spec);
735 }
736 const GridResult result =
737 gridArrange(grid.gridColumns, columnGap, rowGap, contentW, specs);
738 const float naturalH = result.contentH + grid.paddingT + grid.paddingB;
739 const float gridH = grid.sizeY > 0.f ? grid.sizeY : naturalH;
740 grid.layoutOverflowX = result.overflowX;
741 grid.layoutOverflowY = std::max(0.f, naturalH - gridH);
742 const bool scrolling = grid.overflow == OverflowMode::Scroll;
743 if (scrolling) {
744 ImGui::PushID(&grid);
745 ImGui::BeginChild("grid-scroll", ImVec2(std::max(0.f, gridW), std::max(0.f, gridH)),
746 false, ImGuiWindowFlags_HorizontalScrollbar);
747 }
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();
752 const ImVec2 origin(cursor.x + grid.paddingL, cursor.y + grid.paddingT);
753 const bool clipped = grid.overflow == OverflowMode::Clip;
754 if (clipped)
755 ImGui::PushClipRect(cursor, ImVec2(cursor.x + gridW, cursor.y + gridH), true);
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));
760 const float oldX = child.sizeX;
761 const float oldY = child.sizeY;
762 child.sizeX = rect.w;
763 child.sizeY = rect.h;
764 if (rect.w > 0.f) ImGui::PushItemWidth(rect.w);
765 walkNode(host, tree, kids[i]);
766 child.sizeX = oldX;
767 child.sizeY = oldY;
768 if (rect.w > 0.f) ImGui::PopItemWidth();
769 }
770 // Absolutely placed children are excluded from grid flow; draw on top (Flex parity).
771 for (int c : absKids) {
772 UINode &child = tree->nodes[size_t(c)];
773 float w = child.percentW > 0.f ? child.percentW * gridW : child.measuredW;
774 float h = child.percentH > 0.f ? child.percentH * gridH : child.measuredH;
775 if (child.sizeX > 0.f) w = child.sizeX;
776 if (child.sizeY > 0.f) h = child.sizeY;
777 if (child.minSizeX > 0.f) w = std::max(w, child.minSizeX);
778 if (child.minSizeY > 0.f) h = std::max(h, child.minSizeY);
779 if (child.maxSizeX > 0.f) w = std::min(w, child.maxSizeX);
780 if (child.maxSizeY > 0.f) h = std::min(h, child.maxSizeY);
781 const float x = child.anchorX * gridW + child.posX - child.anchorX * w;
782 const float y = child.anchorY * gridH + child.posY - child.anchorY * h;
783 ImGui::SetCursorScreenPos(ImVec2(origin.x + x, origin.y + y));
784 const float oldX = child.sizeX;
785 const float oldY = child.sizeY;
786 child.sizeX = w;
787 child.sizeY = h;
788 if (w > 0.f) ImGui::PushItemWidth(w);
789 walkNode(host, tree, c);
790 child.sizeX = oldX;
791 child.sizeY = oldY;
792 if (w > 0.f) ImGui::PopItemWidth();
793 }
794 if (clipped) ImGui::PopClipRect();
795 ImGui::SetCursorScreenPos(flowEnd);
796 if (scrolling) {
797 ImGui::EndChild();
798 ImGui::PopID();
799 }
800}
801
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;
806
807 const bool scopedTheme = n.themePreset != ThemePreset::Inherit;
808 ImGuiStyle previousStyle;
809 float previousFontScale = 1.f;
810 ImGuiConfigFlags previousConfigFlags = ImGuiConfigFlags_None;
811 if (scopedTheme) {
812 previousStyle = ImGui::GetStyle();
813 previousFontScale = ImGui::GetIO().FontGlobalScale;
814 previousConfigFlags = ImGui::GetIO().ConfigFlags;
815 applyThemeToImGui(n.themePreset == ThemePreset::Dark ? Theme::dark() : Theme::light());
816 if (g_hudScale != 1.f) ImGui::GetStyle().ScaleAllSizes(g_hudScale);
817 }
818
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]) {
824 ImGui::PushStyleColor(slot, ImVec4(color[0], color[1], color[2], color[3]));
825 ++styleColorCount;
826 };
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);
833 }
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);
843 }
844 const float scale = themeUiScale() * g_hudScale;
845 if (style.hasPadding) {
846 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding,
847 ImVec2(style.paddingX * scale, style.paddingY * scale));
848 ++styleVarCount;
849 }
850 if (style.hasRounding) {
851 ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, style.rounding * scale);
852 ++styleVarCount;
853 }
854 if (style.hasAlpha) {
855 ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * style.alpha);
856 ++styleVarCount;
857 }
858 }
859 if (n.opacity < 0.9999f) {
860 ImGui::PushStyleVar(ImGuiStyleVar_Alpha,
861 ImGui::GetStyle().Alpha * std::clamp(n.opacity, 0.f, 1.f));
862 ++styleVarCount;
863 }
864
865 const bool interactive = isInteractive(n.type);
866 const bool disableItem = interactive && !n.enabled;
867 const bool disableNavigation = interactive && n.focusMode != FocusMode::All;
868 if (disableItem) {
869 ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
870 ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.6f);
871 }
872 if (disableNavigation) ImGui::PushItemFlag(ImGuiItemFlags_NoNav, true);
873 if (interactive && n.focusRequested && n.enabled && n.focusMode != FocusMode::None)
874 ImGui::SetKeyboardFocusHere();
875
876 switch (n.type) {
877 case NodeType::Window: {
878 const std::string visibleTitle = n.text.empty() ? "Window" : n.text;
879 std::string title = visibleTitle;
880 // Keep the host name in ImGui's stable ID without exposing internal
881 // paths such as "inventory/Inspector" in the visible title bar.
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;
886 if (hasDirectChildType(*tree, n, NodeType::MenuBar)) flags |= ImGuiWindowFlags_MenuBar;
887 const bool desktopChrome =
888 hasDirectChildType(*tree, n, NodeType::AppFrame) ||
889 ((hasDirectChildType(*tree, n, NodeType::SplitPane) || hasDirectChildType(*tree, n, NodeType::DockArea)) &&
890 (hasDirectChildType(*tree, n, NodeType::Toolbar) || hasDirectChildType(*tree, n, NodeType::StatusBar)));
891 if (desktopChrome)
892 flags |= ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse;
893 float winW = 0.f;
894 float winH = 0.f;
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),
906 ImGuiCond_Always,
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;
913 // SetNextWindowPos applies the pivot itself. Passing an already
914 // pivot-adjusted top-left position shifts the window by its pivot
915 // a second time (a centered window moves half its width left).
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;
923 }
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) {
929 // Real measured size → stable auto-resize instead of ImGui's guess.
930 ImGui::SetNextWindowContentSize(ImVec2(n.measuredW, n.measuredH));
931 }
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);
940 }
941 // A transparent overlay delegates its surface to its content (for example
942 // a nine-patch skin). Do not leave desktop chrome around that surface.
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);
947 if (modal) {
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);
954 ImGui::EndPopup();
955 }
956 } else {
957 ImGui::Begin(title.c_str(), nullptr, flags);
958 ImGui::SetWindowFontScale(1.f);
959 if (host && host->meta()->canvas.enabled && !worldAnchor->enabled) {
960 const ImVec2 display = ImGui::GetIO().DisplaySize;
961 ImGui::SetWindowFontScale(resolveHudCanvas(host->meta()->canvas, display.x, display.y).scale);
962 }
963 if (worldAnchor->enabled)
964 ImGui::SetWindowFontScale(worldAnchor->scale);
965 if (n.firstChild >= 0) walkSiblings(host, tree, n.firstChild);
966 ImGui::End();
967 }
968 if (transparentOverlay) ImGui::PopStyleVar();
969 if (flushOverlay) ImGui::PopStyleVar();
970 break;
971 }
972 case NodeType::Text:
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);
979 const ImVec4 clip(pos.x, pos.y, pos.x + size.x, pos.y + size.y);
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);
983 ImGui::Dummy(size);
984 } else if (n.wrapWidth > 0.f) {
985 ImGui::PushTextWrapPos(ImGui::GetCursorPosX() + n.wrapWidth);
986 ImGui::TextUnformatted(n.text.c_str());
987 ImGui::PopTextWrapPos();
988 } else {
989 ImGui::TextUnformatted(n.text.c_str());
990 }
991 break;
992 case NodeType::Link: {
993 if (controls::textLink(nodeLabel(n, "Link").c_str()) == controls::ControlEdit::Changed)
994 pushPending(host, n, "click", n.handlerClick);
995 break;
996 }
997 case NodeType::Button: {
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));
1009 if (n.checked) {
1010 ImGui::PushStyleColor(ImGuiCol_Button,
1011 ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive));
1012 ImGui::PushStyleColor(ImGuiCol_ButtonHovered,
1013 ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive));
1014 }
1015 const bool clicked = controls::button(label.c_str(),
1016 (sized || iconOnly) ? buttonSize.x : 0.f,
1017 (sized || iconOnly) ? buttonSize.y : 0.f) ==
1018 controls::ControlEdit::Changed;
1019 if (n.checked) ImGui::PopStyleColor(2);
1020 if (iconOnly) {
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;
1025 if (glyph) {
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(
1031 (rectMin.x + rectMax.x - glyphW) * 0.5f - glyph->X0 * fontScale,
1032 (rectMin.y + rectMax.y - glyphH) * 0.5f - glyph->Y0 * fontScale);
1033 ImGui::GetWindowDrawList()->AddText(font, fontSize, glyphOrigin,
1034 ImGui::GetColorU32(ImGuiCol_Text),
1035 n.text.c_str());
1036 }
1037 }
1038 if (clicked) pushPending(host, n, "click", n.handlerClick);
1039 break;
1040 }
1041 case NodeType::SameLine:
1042 ImGui::SameLine();
1043 break;
1044 case NodeType::Group:
1045 ImGui::BeginGroup();
1046 if (n.firstChild >= 0) walkSiblings(host, tree, n.firstChild);
1047 ImGui::EndGroup();
1048 break;
1050 ImGui::Separator();
1051 break;
1052 case NodeType::Checkbox: {
1053 bool checked = n.checked;
1054 if (controls::checkbox(n.text.empty() ? "Check" : n.text.c_str(), checked) ==
1055 controls::ControlEdit::Changed) {
1056 n.checked = checked;
1057 pushPending(host, n, "toggle", n.handlerToggle, checked);
1058 }
1059 break;
1060 }
1061 case NodeType::Slider: {
1062 float v = n.value;
1063 const char *label = n.text.empty() ? "Slider" : n.text.c_str();
1064 if (controls::slider(label, v, n.minValue, n.maxValue) ==
1066 n.value = v;
1067 pushPending(host, n, "value", n.handlerValue, false, v);
1068 }
1069 break;
1070 }
1072 const float swatch = ImGui::GetFrameHeight();
1073 const float gap = 4.f;
1074 const int cols = 8;
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];
1089 const ImVec4 color(s.r, s.g, s.b, s.a);
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);
1100 }
1101 if (selected) {
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);
1106 }
1107 ImGui::PopID();
1108 }
1109 ImGui::PopID();
1110 ImGui::EndGroup();
1111 break;
1112 }
1113 case NodeType::Progress: {
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);
1116 break;
1117 }
1118 case NodeType::RadialFill: {
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);
1121 const auto mesh = radialFillMesh(n.value, n.fillStartDegrees, n.fillClockwise, n.fillInnerRadius);
1122 const ImU32 color = ImGui::GetColorU32(ImVec4(n.tintR, n.tintG, n.tintB, n.tintA));
1123 auto point = [&](float x, float y) { return ImVec2(pos.x + x * size.x, pos.y + y * size.y); };
1124 auto *list = ImGui::GetWindowDrawList();
1125 const auto savedFlags = list->Flags;
1126 // No alpha fringes along the internal edges of a translucent sector.
1127 list->Flags &= ~ImDrawListFlags_AntiAliasedFill;
1128 const auto triangle = [&](ImVec2 a, ImVec2 b, ImVec2 c) {
1129 // ImGui anti-aliased convex paths require clockwise winding in screen coordinates.
1130 if (!n.fillClockwise) std::swap(b, c);
1131 list->AddTriangleFilled(a, b, c, color);
1132 };
1133 for (int i = 0; i < mesh.count; ++i) {
1134 const auto &q = mesh.quads[std::size_t(i)];
1135 triangle(point(q.innerX0, q.innerY0), point(q.outerX0, q.outerY0), point(q.outerX1, q.outerY1));
1136 if (n.fillInnerRadius > 0.f)
1137 triangle(point(q.innerX0, q.innerY0), point(q.outerX1, q.outerY1), point(q.innerX1, q.innerY1));
1138 }
1139 list->Flags = savedFlags;
1140 ImGui::Dummy(size);
1141 break;
1142 }
1144 case NodeType::Image: {
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();
1148 const ImVec2 size(w, h);
1149 const ImU32 tint = ImGui::GetColorU32(ImVec4(n.tintR, n.tintG, n.tintB, n.tintA));
1150 const auto fill = n.type == NodeType::FilledImage ? linearFillRect(n.value, n.fillDirection, n.fillStretch)
1151 : linearFillRect(1.f, FillDirection::Right, false);
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) {
1157 ImGui::Dummy(size);
1158 break;
1159 }
1160 if (n.textureId != 0 && g_backend) {
1161 int tw = 0, th = 0;
1162 g_backend->textureSize(n.textureId, &tw, &th);
1163 if (g_backend->usesQueuedTextureDraws()) {
1164 queueNinePatch(n.textureId, drawPos, drawSize, drawUv0, drawUv1,
1165 n.type == NodeType::FilledImage ? 0.f : n.borderL,
1166 n.type == NodeType::FilledImage ? 0.f : n.borderT,
1167 n.type == NodeType::FilledImage ? 0.f : n.borderR,
1168 n.type == NodeType::FilledImage ? 0.f : n.borderB, tw, th, n.tintR, n.tintG, n.tintB,
1169 n.tintA * ImGui::GetStyle().Alpha);
1170 } else {
1171 void *handle = g_backend->textureHandle(n.textureId);
1172 if (handle) {
1173 drawNinePatch(handle, drawPos, drawSize, drawUv0, drawUv1,
1174 n.type == NodeType::FilledImage ? 0.f : n.borderL,
1175 n.type == NodeType::FilledImage ? 0.f : n.borderT,
1176 n.type == NodeType::FilledImage ? 0.f : n.borderR,
1177 n.type == NodeType::FilledImage ? 0.f : n.borderB, tw, th, tint);
1178 } else {
1179 ImGui::GetWindowDrawList()->AddRectFilled(
1180 drawPos, ImVec2(drawPos.x + drawSize.x, drawPos.y + drawSize.y), tint, n.cornerRadius);
1181 }
1182 }
1183 } else {
1184 ImGui::GetWindowDrawList()->AddRectFilled(drawPos, ImVec2(drawPos.x + drawSize.x, drawPos.y + drawSize.y),
1185 tint, n.cornerRadius);
1186 }
1187 ImGui::Dummy(size);
1188 break;
1189 }
1190 case NodeType::ImageButton: {
1191 const float w = n.sizeX > 0.f ? n.sizeX : 32.f;
1192 const float h = n.sizeY > 0.f ? n.sizeY : 32.f;
1193 const ImVec2 size(w, h);
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);
1201 itemCreated = true;
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);
1209 } else {
1210 void *handle = g_backend->textureHandle(n.textureId);
1211 if (handle) {
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));
1216 itemCreated = true;
1217 }
1218 }
1219 }
1220 if (!itemCreated) {
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);
1227 }
1228 ImGui::PopID();
1229 if (clicked) pushPending(host, n, "click", n.handlerClick);
1230 break;
1231 }
1232 case NodeType::Combo: {
1233 // Options are newline-separated in valueText; selected index in value.
1234 std::vector<std::string> storage;
1235 size_t start = 0;
1236 while (start <= n.valueText.size()) {
1237 const size_t end = n.valueText.find('\n', start);
1238 storage.push_back(n.valueText.substr(
1239 start, end == std::string::npos ? std::string::npos : end - start));
1240 if (end == std::string::npos) break;
1241 start = end + 1;
1242 }
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));
1251 }
1252 break;
1253 }
1254 case NodeType::InputText: {
1255 const char *label = n.text.empty() ? "Input" : n.text.c_str();
1256 std::string edited = n.valueText;
1257 if (controls::inputText(label, edited, n.multiline, ImVec2(n.sizeX, n.sizeY > 0.f ? n.sizeY : 96.f), n.readOnly,
1258 n.placeholder.c_str()) == controls::ControlEdit::Changed) {
1259 n.valueText = std::move(edited);
1260 pushPending(host, n, "text", n.handlerText, false, 0.f, n.valueText);
1261 }
1262 break;
1263 }
1264 case NodeType::SearchField: {
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;
1269 const char *glyph = iconGlyph(Icon::Search);
1270 const ImVec2 iconSize = ImGui::CalcTextSize(glyph);
1271 const float gap = globalTheme().layout.searchIconGap * themeUiScale();
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));
1278 if (controls::inputTextWithHint(label.c_str(), hint.c_str(), edited) ==
1280 n.valueText = std::move(edited);
1281 pushPending(host, n, "text", n.handlerText, false, 0.f, n.valueText);
1282 }
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,
1289 rectMin.y + (rectMax.y - rectMin.y - iconSize.y) * 0.5f),
1290 ImGui::GetColorU32(ImGuiCol_TextDisabled), glyph);
1291 n.measuredH = rectMax.y - rectMin.y;
1292 break;
1293 }
1294 case NodeType::Switch: {
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);
1305 }
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;
1314 const float knobX = n.checked ? pos.x + trackW - radius : pos.x + radius;
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());
1321 }
1322 ImGui::EndGroup();
1323 break;
1324 }
1325 case NodeType::Badge: {
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)));
1335 draw->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + size.y), bg, size.y * 0.5f);
1336 draw->AddRect(pos, ImVec2(pos.x + size.x, pos.y + size.y), border, size.y * 0.5f);
1337 draw->AddText(ImVec2(pos.x + padding.x, pos.y + padding.y),
1338 ImGui::GetColorU32(ImGuiCol_Text), n.text.c_str());
1339 ImGui::Dummy(size);
1340 break;
1341 }
1343 ImGuiTreeNodeFlags flags = n.open ? ImGuiTreeNodeFlags_DefaultOpen : 0;
1344 const char *label = n.text.empty() ? "Section" : n.text.c_str();
1345 if (ImGui::CollapsingHeader(label, flags)) {
1346 if (n.firstChild >= 0) walkSiblings(host, tree, n.firstChild);
1347 }
1348 break;
1349 }
1350 case NodeType::Child: {
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);
1355 }
1356 ImGui::EndChild();
1357 break;
1358 }
1359 case NodeType::Card: {
1360 const ThemeLayout &layout = globalTheme().layout;
1361 const ImVec2 padding(layout.cardPaddingX * themeUiScale(),
1362 layout.cardPaddingY * themeUiScale());
1363 const float height = n.sizeY > 0.f
1364 ? n.sizeY
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);
1373 }
1374 ImGui::EndChild();
1375 ImGui::PopStyleColor();
1376 ImGui::PopStyleVar();
1377 break;
1378 }
1380 const float width = n.sizeX > 0.f ? n.sizeX : ImGui::GetContentRegionAvail().x;
1381 const float height = n.sizeY > 0.f
1382 ? n.sizeY
1383 : std::max(n.minSizeY,
1384 n.measuredH > 0.f ? n.measuredH
1385 : ImGui::GetFrameHeight());
1386 const ImVec2 pos = ImGui::GetCursorScreenPos();
1387 const ImVec2 size(std::max(n.minSizeX, width), height);
1388 if (n.textureId != 0 && g_backend) {
1389 int tw = 0, th = 0;
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));
1398 drawNinePatch(handle, pos, size, ImVec2(n.uv0x, n.uv0y),
1399 ImVec2(n.uv1x, n.uv1y), n.borderL, n.borderT, n.borderR,
1400 n.borderB, tw, th, tint);
1401 }
1402 }
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);
1414 }
1415 ImGui::EndChild();
1416 }
1417 ImGui::EndChild();
1418 ImGui::PopStyleColor();
1419 ImGui::PopStyleVar();
1420 break;
1421 }
1423 const float sectionGap = globalTheme().layout.sectionSpacingY * themeUiScale();
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));
1440 break;
1441 }
1442 case NodeType::MenuBar:
1443 if (ImGui::BeginMenuBar()) {
1444 if (n.firstChild >= 0) walkSiblings(host, tree, n.firstChild);
1445 ImGui::EndMenuBar();
1446 }
1447 break;
1448 case NodeType::Menu: {
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);
1452 ImGui::EndMenu();
1453 }
1454 break;
1455 }
1456 case NodeType::MenuItem: {
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);
1461 break;
1462 }
1463 case NodeType::Toolbar:
1464 case NodeType::StatusBar: {
1465 const bool status = n.type == NodeType::StatusBar;
1466 const ThemeLayout &layout = globalTheme().layout;
1467 const float scale = themeUiScale() * g_hudScale;
1468 const float defaultHeight =
1469 (status ? layout.statusBarHeight : layout.toolbarHeight) * scale;
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,
1474 ImVec2(layout.barPaddingX * scale, layout.barPaddingY * scale));
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);
1482 }
1483 ImGui::EndChild();
1484 ImGui::PopStyleColor();
1485 ImGui::PopStyleVar();
1486 break;
1487 }
1488 case NodeType::Toolbox: {
1489 const ThemeLayout &layout = globalTheme().layout;
1490 const float scale = themeUiScale() * g_hudScale;
1491 const float cell = n.itemHeight > 0.f ? n.itemHeight : layout.toolboxCellSize * scale;
1492 const ImVec2 padding(layout.panelPaddingX * scale, layout.panelPaddingY * scale);
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;
1496 const int capacity = std::max(1, int((contentWidth + spacing) / (cell + spacing)));
1497 const int requested = int(n.value) > 0 ? int(n.value) : capacity;
1498 const int columns = std::max(1, std::min(requested, capacity));
1499 int count = 0;
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;
1503 }
1504 const int rows = (count + columns - 1) / columns;
1505 const float autoHeight = std::max(
1506 cell, float(rows) * cell + float(std::max(0, rows - 1)) *
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)];
1517 if (!child.visible) continue;
1518 const float oldX = child.sizeX;
1519 const float oldY = child.sizeY;
1520 child.sizeX = cell;
1521 child.sizeY = cell;
1522 walkNode(host, tree, childIndex);
1523 child.sizeX = oldX;
1524 child.sizeY = oldY;
1525 ++visibleIndex;
1526 if (visibleIndex % columns != 0) ImGui::SameLine();
1527 }
1528 }
1529 ImGui::EndChild();
1530 ImGui::PopStyleColor();
1531 ImGui::PopStyleVar();
1532 break;
1533 }
1534 case NodeType::Sidebar: {
1535 const ThemeLayout &layout = globalTheme().layout;
1536 const float scale = themeUiScale() * g_hudScale;
1537 const ImVec2 size(n.sizeX > 0.f ? n.sizeX : layout.sidebarWidth * scale,
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,
1541 ImVec2(layout.panelPaddingX * scale, layout.panelPaddingY * scale));
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);
1545 }
1546 ImGui::EndChild();
1547 ImGui::PopStyleColor();
1548 ImGui::PopStyleVar();
1549 break;
1550 }
1551 case NodeType::SplitPane: {
1552 const bool row = n.flexDirection == FlexDirection::Row;
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;
1557 const ThemeLayout &layout = globalTheme().layout;
1558 const float splitter = layout.splitterSize * themeUiScale();
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);
1569 n.value = 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));
1576 if (first >= 0) {
1577 const ImVec2 paneSize(row ? firstMain : size.x, row ? size.y : firstMain);
1578 if (ImGui::BeginChild("first", paneSize, false,
1579 ImGuiWindowFlags_NoScrollbar |
1580 ImGuiWindowFlags_NoScrollWithMouse))
1581 walkPaneChild(host, tree, first);
1582 ImGui::EndChild();
1583 }
1584 if (row) ImGui::SameLine(0.f, 0.f);
1585 const ImVec2 handleSize(row ? splitter : size.x, row ? size.y : splitter);
1586 ImGui::InvisibleButton("splitter", handleSize);
1587 const bool hovered = ImGui::IsItemHovered();
1588 const bool active = ImGui::IsItemActive();
1589 if (hovered || active)
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)));
1596 if (active) {
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) {
1600 n.value = next;
1601 ImGui::GetStateStorage()->SetFloat(ratioStateId, next);
1602 pushPending(host, n, "value", n.handlerValue, false, next);
1603 }
1604 }
1605 if (row) ImGui::SameLine(0.f, 0.f);
1606 if (second >= 0) {
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))
1611 walkPaneChild(host, tree, second);
1612 ImGui::EndChild();
1613 }
1614 ImGui::PopStyleVar();
1615 ImGui::EndGroup();
1616 ImGui::PopID();
1617 break;
1618 }
1619 case NodeType::ScrollList: {
1620 // Virtualized list: only the rows intersecting the viewport are drawn.
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);
1625 }
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);
1637 if (first < 0) first = 0;
1638 if (first > total) first = total;
1639 int last = int(std::ceil((scrollY + viewH) / itemH));
1640 if (last < first) last = first;
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));
1645 const float oldX = child.sizeX;
1646 const float oldY = child.sizeY;
1647 if (contentW > 0.f) child.sizeX = contentW;
1648 if (contentW > 0.f) ImGui::PushItemWidth(contentW);
1649 walkNode(host, tree, kids[size_t(i)]);
1650 child.sizeX = oldX;
1651 child.sizeY = oldY;
1652 if (contentW > 0.f) ImGui::PopItemWidth();
1653 // Force the row to occupy exactly itemH so rows stay uniform.
1654 ImGui::SetCursorPosY(float(i) * itemH + itemH);
1655 }
1656 }
1657 // Establish the full scrollable extent (scrollbar reflects total rows).
1658 ImGui::SetCursorPosY(float(total) * itemH);
1659 ImGui::EndChild();
1660 break;
1661 }
1662 case NodeType::Viewport: {
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);
1667 auto viewport = UISystem::ensureViewport(key, int(size.x), int(size.y));
1668
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();
1675 if (viewport.ok()) {
1676 ViewportState &vs = viewport.value().get();
1677 vs.hovered = hovered;
1678 vs.active = active;
1679 vs.mouseX = mouse.x - rectMin.x;
1680 vs.mouseY = mouse.y - rectMin.y;
1681 if (active) {
1682 vs.dragDX = ImGui::GetIO().MouseDelta.x;
1683 vs.dragDY = ImGui::GetIO().MouseDelta.y;
1684 } else {
1685 vs.dragDX = 0.f;
1686 vs.dragDY = 0.f;
1687 }
1688 vs.wheel = hovered ? ImGui::GetIO().MouseWheel : 0.f;
1689
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);
1695 if (handle) {
1696 ImGui::SetCursorScreenPos(rectMin);
1697 ImGui::Image(static_cast<ImTextureID>(handle), size);
1698 } else {
1699 ImGui::GetWindowDrawList()->AddRectFilled(rectMin, ImVec2(rectMin.x + size.x, rectMin.y + size.y),
1700 IM_COL32(10, 12, 16, 255));
1701 }
1702 } else {
1703 ImGui::GetWindowDrawList()->AddRectFilled(
1704 rectMin, ImVec2(rectMin.x + size.x, rectMin.y + size.y),
1705 IM_COL32(10, 12, 16, 255));
1706 }
1707 } else {
1708 ImGui::GetWindowDrawList()->AddRectFilled(
1709 rectMin, ImVec2(rectMin.x + size.x, rectMin.y + size.y), IM_COL32(10, 12, 16, 255));
1710 }
1711 break;
1712 }
1713 case NodeType::Tab: {
1714 const std::string label = nodeLabel(n, "Tab");
1715 const Theme &theme = globalTheme();
1716 const float *color = n.checked ? theme.tabActive : theme.tab;
1717 ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(color[0], color[1], color[2], color[3]));
1718 ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(theme.tabHovered[0], theme.tabHovered[1],
1719 theme.tabHovered[2], theme.tabHovered[3]));
1720 ImGui::PushStyleColor(ImGuiCol_ButtonActive,
1721 ImVec4(theme.tabActive[0], theme.tabActive[1], theme.tabActive[2], theme.tabActive[3]));
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);
1726 break;
1727 }
1728 case NodeType::TabBar: {
1729 const ThemeLayout &layout = globalTheme().layout;
1730 const float scale = themeUiScale();
1731 const float height = n.sizeY > 0.f ? n.sizeY : layout.tabBarHeight * scale;
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,
1735 ImVec2(layout.barPaddingX * scale, layout.barPaddingY * scale));
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);
1740 }
1741 ImGui::EndChild();
1742 ImGui::PopStyleColor();
1743 ImGui::PopStyleVar();
1744 break;
1745 }
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)];
1759 if (child.type == NodeType::TabBar) {
1760 tabBarIndex = c;
1761 continue;
1762 }
1763 pageIndices.push_back(c);
1764 }
1765 if (n.valueText.empty() && !pageIndices.empty()) {
1766 const UINode &first = tree->nodes[size_t(pageIndices.front())];
1767 n.valueText = first.id.empty() ? first.key : first.id;
1768 }
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)];
1773 if (tabNode.type != NodeType::Tab) continue;
1774 tabNode.checked = !n.valueText.empty() && tabNode.valueText == n.valueText;
1775 }
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;
1791 }
1792 }
1793 }
1794 }
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);
1804 }
1805 }
1806 ImGui::EndChild();
1807 ImGui::PopStyleVar();
1808 ImGui::EndGroup();
1809 ImGui::PopID();
1810 break;
1811 }
1812 case NodeType::PanelFrame: {
1813 const ThemeLayout &layout = globalTheme().layout;
1814 const float scale = themeUiScale();
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,
1820 ImVec2(layout.panelPaddingX * scale, layout.panelPaddingY * scale));
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));
1832 }
1833 if (n.firstChild >= 0) walkSiblings(host, tree, n.firstChild);
1834 }
1835 ImGui::EndChild();
1836 ImGui::PopStyleColor();
1837 ImGui::PopStyleVar();
1838 break;
1839 }
1840 case NodeType::DockArea: {
1841 const ThemeLayout &layout = globalTheme().layout;
1842 const float scale = themeUiScale();
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,
1847 ImVec2(layout.panelPaddingX * scale, layout.panelPaddingY * scale));
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) {
1852 // Single growing child fills the dock slot.
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();
1856 child.sizeX = childAvail.x;
1857 child.sizeY = childAvail.y;
1858 }
1859 walkSiblings(host, tree, n.firstChild);
1860 }
1861 }
1862 ImGui::EndChild();
1863 ImGui::PopStyleColor();
1864 ImGui::PopStyleVar();
1865 break;
1866 }
1867 case NodeType::AppFrame: {
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;
1871 n.flexDirection = FlexDirection::Column;
1872 walkFlex(host, tree, n);
1873 break;
1874 }
1875 case NodeType::Flex:
1876 walkFlex(host, tree, n);
1877 break;
1878 case NodeType::Grid:
1879 walkGrid(host, tree, n);
1880 break;
1881 case NodeType::Spacer:
1882 // Outside Flex: honor explicit size, otherwise a tiny dummy.
1883 emitSpacer(n.sizeX > 0.f ? n.sizeX : 0.f, n.sizeY > 0.f ? n.sizeY : 0.f, true);
1884 break;
1885 }
1886
1887 if (interactive) {
1888 n.focused = ImGui::IsItemFocused();
1889 routeExplicitFocusInput(host, n);
1890 n.focusRequested = false;
1891 }
1892 if (disableNavigation) ImGui::PopItemFlag();
1893 if (disableItem) {
1894 ImGui::PopStyleVar();
1895 ImGui::PopItemFlag();
1896 }
1897
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());
1903
1904 if (styleVarCount > 0) ImGui::PopStyleVar(styleVarCount);
1905 if (styleColorCount > 0) ImGui::PopStyleColor(styleColorCount);
1906
1907 if (scopedTheme) {
1908 ImGui::GetStyle() = previousStyle;
1909 ImGui::GetIO().FontGlobalScale = previousFontScale;
1910 ImGui::GetIO().ConfigFlags = previousConfigFlags;
1911 }
1912}
1913
1914void walk(UIHost *host, UIHost::Tree *tree, int index) { walkSiblings(host, tree, index); }
1915
1916} // namespace
1917
1918std::vector<UIEvent> &UISystem::pendingEvents() { return g_pending; }
1919std::vector<UIClick> &UISystem::clickQueue() { return g_clicks; }
1920std::vector<UIChange> &UISystem::changeQueue() { return g_changes; }
1921std::vector<UIDrop> &UISystem::dropQueue() { return g_drops; }
1922
1924#if (defined(_WIN32) || defined(__APPLE__) || defined(__linux__)) && \
1925 !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
1927#else
1929#endif
1930}
1931
1932void UISystem::enqueuePlatformFileDrop(const std::string &path) {
1933 if (dragDropSupport() == DragDropSupport::Supported && !path.empty())
1934 g_pendingFileDrops.push_back(path);
1935}
1936
1937std::optional<UIDrop> UISystem::consumeDrop() {
1938 if (g_drops.empty()) return std::nullopt;
1939 UIDrop result = std::move(g_drops.front());
1940 g_drops.erase(g_drops.begin());
1941 return result;
1942}
1943
1945void UISystem::clearBackend() noexcept { g_backend = nullptr; }
1946std::optional<std::reference_wrapper<UIBackend>> UISystem::backend() {
1947 if (!g_backend) return std::nullopt;
1948 return std::ref(*g_backend);
1949}
1950const UIStats &UISystem::stats() { return g_stats; }
1951
1954 if (key.empty() || w <= 0 || h <= 0) {
1955 return Return::failure(eve::Status::failure(
1957 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "viewport key and dimensions must be valid")));
1958 }
1959 auto *gfx = eve::ModuleManager::getInstance<eve::graphics::Graphics>("Graphics");
1960 if (!gfx) {
1961 return Return::failure(eve::Status::failure(
1963 eve::Diagnostic::error(eve::DiagnosticCode::Unsupported, "viewport requires the Graphics module")));
1964 }
1965 ViewportState &vs = g_viewports[key];
1966 vs.key = key;
1967 if (!vs.canvas || vs.width != w || vs.height != h) {
1968 graphics::Canvas *canvas = gfx->newCanvas(w, h);
1969 if (!canvas) {
1970 return Return::failure(eve::Status::failure(
1972 eve::Diagnostic::error(eve::DiagnosticCode::Failed, "Graphics could not create the viewport canvas")));
1973 }
1974 if (vs.textureId && g_backend) g_backend->unregisterTexture(vs.textureId);
1975 vs.textureId = 0;
1976 vs.canvas = canvas;
1977 vs.width = w;
1978 vs.height = h;
1979 if (vs.canvas && g_backend)
1980 vs.textureId = g_backend->registerTexture(vs.canvas->getTexture());
1981 }
1982 return Return::success(std::ref(vs));
1983}
1984
1985std::optional<std::reference_wrapper<ViewportState>> UISystem::viewportState(const std::string &hostName,
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);
1990}
1991
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;
1998 (void)tree;
1999 if (meta->name == name && UIHost::resolve(meta->entity)) return meta->entity;
2000 }
2001 return {};
2002}
2003
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;
2010 (void)tree;
2011 if (meta->ownerId == ownerId && UIHost::resolve(meta->entity)) return meta->entity;
2012 }
2013 return {};
2014}
2015
2018 EV_PROFILE_MODULE("ui", "UISystem::render");
2019 if (ecs::current()->getManager<UIHost>() == nullptr) return;
2020
2022
2023 struct Item {
2024 UIHost *host;
2025 UIHost::Meta *meta;
2026 UIHost::Tree *tree;
2027 bool render = true;
2028 };
2029 std::vector<Item> items;
2030
2031 graphics::Camera3D *camera = activeCamera();
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;
2037 auto host = UIHost::resolve(meta->entity);
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});
2041 }
2042
2043 std::stable_sort(items.begin(), items.end(),
2044 [](const Item &a, const Item &b) { return a.meta->layer < b.meta->layer; });
2045
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();
2054 measureTree(*item.tree);
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();
2059 }
2060
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;
2075 if (height <= 0.f) height = root.measuredH + style.WindowPadding.y * 2.f;
2076 }
2077 width *= anchor->scale;
2078 height *= anchor->scale;
2079 anchorItems.push_back({i,
2080 anchor->screenX,
2081 anchor->screenY,
2082 width,
2083 height,
2084 item.meta->pivotX,
2085 item.meta->pivotY,
2086 anchor->depth,
2087 anchor->safeMargin,
2088 anchor->overlapPadding,
2089 anchor->maxDisplacement,
2090 anchor->overlapPriority,
2091 anchor->overlapPolicy == WorldAnchorOverlapPolicy::Avoid});
2092 }
2093 for (const auto &resolved :
2094 resolveWorldAnchorOverlaps(std::move(anchorItems), display.x, display.y)) {
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;
2101 item.render = resolved.render;
2102 if (!resolved.render) anchor->state = WorldAnchorState::Crowded;
2103 }
2104
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();
2115 }
2116 // Animation overrides are one-frame: Motion/tweens re-assert them before the
2117 // next render. Clearing here restores movable/resizable hosts after the sample.
2118 for (auto &item : items) {
2119 item.meta->animDrivePos = false;
2120 item.meta->animDriveSize = false;
2121 }
2122}
2123
2125 auto events = std::move(g_pending);
2126 g_pending.clear();
2127 for (auto &ev : events) {
2128 auto resolvedHost = UIHost::resolve(ev.host);
2129 if (!resolvedHost) continue;
2130 UIHost *host = &resolvedHost->get();
2131
2132 if (ev.kind == "click" && !ev.nodeId.empty()) {
2133 UIClick c;
2134 c.hostName = ev.hostName.empty() ? host->meta()->name : ev.hostName;
2135 c.nodeId = ev.nodeId;
2136 g_clicks.push_back(std::move(c));
2137 }
2138
2139 if ((ev.kind == "toggle" || ev.kind == "value" || ev.kind == "text") && !ev.nodeId.empty()) {
2140 UIChange ch;
2141 ch.hostName = ev.hostName.empty() ? host->meta()->name : ev.hostName;
2142 ch.nodeId = ev.nodeId;
2143 ch.kind = ev.kind;
2144 g_changes.push_back(std::move(ch));
2145 }
2146
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) {
2152 auto target = host->findById(ev.nodeId);
2153 index = target && !tree->nodes.empty() ? int(&target->get() - tree->nodes.data()) : -1;
2154 }
2155
2156 bool first = true;
2157 while (index >= 0 && index < int(tree->nodes.size())) {
2158 const UINode &node = tree->nodes[size_t(index)];
2159 if (!node.visible || !node.enabled) break;
2160 const uint32_t handler = first ? ev.handlerIndex : node.handlerClick;
2161 if (node.mouseFilter != MouseFilter::Ignore && handler != 0) {
2162 const size_t handlerSlot = size_t(handler - 1);
2163 if (handlerSlot < tree->clickHandlers.size() &&
2164 tree->clickHandlers[handlerSlot])
2165 tree->clickHandlers[handlerSlot]();
2166 }
2167 if (node.mouseFilter == MouseFilter::Stop) break;
2168 index = node.parent;
2169 first = false;
2170 }
2171 continue;
2172 }
2173
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);
2179 continue;
2180 }
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);
2186 continue;
2187 }
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);
2193 continue;
2194 }
2195 }
2196}
2197
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;
2204}
2205
2206std::string UISystem::consumeClickFor(const std::string &hostName) {
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);
2210 g_clicks.erase(it);
2211 return id;
2212 }
2213 return {};
2214}
2215
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;
2222}
2223
2224} // namespace eve::ui
double y
double m[16]
double x
LogicalId target
Value::Object payload
Duration start
bool & active
float w
Definition AnimClip.cpp:738
int tip
Definition AnimSmr.cpp:121
int root
Definition AnimSmr.cpp:119
std::string selected
std::size_t cursor
const std::string & s
float gap
std::string title
std::string nodeId
SQObjectPtr key
Definition ECS.cpp:155
std::string name
Definition ECS.cpp:154
int rows
int cols
std::string layout
int triangle
Definition FluidSdf.cpp:554
tensor::Graph g
Definition GpuGraph.cpp:7
float camera[2]
std::uint32_t capacity
wgpu::PopErrorScopeStatus status
glm::vec4 clip
glm::vec4 tint
float u
Definition Grass.cpp:233
glm::vec3 n
Definition Grass.cpp:63
std::array< double, 10 > q
double r
bool border
float v
HexVec3 up
std::int32_t second
std::int32_t c
std::int32_t first
const char * glyph
Definition Icons.cpp:13
int h
std::uint32_t height
std::uint32_t width
float ratio
const ColourScope * parent
std::array< float, 3 > scale
std::string label
std::string id
Poco::JSON::Object::Ptr result
HSQOBJECT handler
bool readOnly
MeleePoint3 b
Definition MeleeHit.cpp:41
double radius
Definition MeleeHit.cpp:42
MeleePoint3 a
Definition MeleeHit.cpp:40
MeshVfxBatchedDraw draw
OceanGpuFrameToken token
OceanMeshSettings mesh
OceanRenderBackend backend
glm::dvec3 origin
OceanSprayView view
std::vector< particles::ParticleRecordEvent > events
int idx
std::string path
Definition PlayHost.cpp:111
uint64_t serial
Definition Plugins.cpp:26
PrimitiveHandle handle
#define EV_PROFILE_MODULE(module, name)
Profile the enclosing scope, tagged with a module for grouping.
Definition Profile.h:158
Object::Ptr value
float t
std::string slot
glm::vec3 eye
RoadNetwork resolved
const RoadNode * node
std::string text
ScriptStructure out
size_t end
std::string kind
Light3D::Data * light
Definition Shadow.cpp:147
int count
Cell cell
int spacing
int columns
float size
Definition TreeMesh.cpp:158
UIHostHandle host
float savedHudScale
Definition UISystem.cpp:88
ImGuiConfigFlags previousConfigFlags
Definition UISystem.cpp:51
std::array< float, 6 > savedMeta
Definition UISystem.cpp:85
std::string payloadType
Definition UISystem.cpp:154
bool savedWriteAccessed
Definition UISystem.cpp:90
std::string payloadText
Definition UISystem.cpp:155
float previousFontScale
Definition UISystem.cpp:50
ImGuiStyle previousStyle
Definition UISystem.cpp:49
std::string sourceNodeId
Definition UISystem.cpp:153
std::string sourceHostName
Definition UISystem.cpp:152
ImGuiStyle savedStyle
Definition UISystem.cpp:86
float savedFontScale
Definition UISystem.cpp:87
std::size_t at
uint32_t index
glm::vec3 point
uint32_t flags
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.
Definition Result.h:176
static Status failure(StatusCode code, Diagnostic diagnostic)
Construct a failed status with one diagnostic.
Definition Status.cpp:28
EVENGINE_API_BACKENDS public API.
Canvas public API.
Definition Canvas.h:17
virtual Texture * getTexture()=0
Sampleable color buffer; screen Canvas returns nullptr.
Platform / renderer backend for declarative UI. Concrete implementations live under ui/<backend>/ (e....
Definition UIBackend.h:20
ECS mount point for one UI panel/screen. Subclass to attach UI to game entities, e....
Definition UIHost.h:284
static eve::OptionalRef< UIHost > resolve(UIHostHandle handle) noexcept
Resolves a UI host handle with ECS generation checking.
Definition UIHost.cpp:62
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)
Definition main.cpp:46
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.
Definition ClipSpace.h:38
constexpr HexDirection next(HexDirection d) noexcept
The next direction clockwise (NW wraps to NE).
Definition HexMetrics.h:76
Result< ForceVector > checked(ForceVector value)
Definition ForceMath.h:21
V3 cross(V3 a, V3 b)
Module-private road bake implementation helper.
Definition RoadBake.cpp:29
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...
Definition Component.cpp:18
RadialFillMesh radialFillMesh(float fraction, float startDegrees, bool clockwise, float innerRadius)
Builds an elliptical sector/ring in [0,1] coordinates; zero degrees points right.
Definition HudGeometry.h:76
const char * iconGlyph(Icon icon)
Returns the UTF-8 glyph for an icon, or an empty string for None.
Definition Icons.cpp:86
DragDropSupport
Build-target availability of retained drag-and-drop.
Definition UISystem.h:53
GridResult gridArrange(int columns, float columnGap, float rowGap, float availWidth, const std::vector< GridItemSpec > &items)
Places source-ordered items into equal-width fixed columns.
Definition Layout.cpp:277
void measureTree(UIHost::Tree &tree)
Measure tree.
Definition Layout.cpp:729
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.
Definition HudGeometry.h:23
WidgetDesc child(std::string id, std::vector< WidgetDesc > children, float width, float height)
Scrollable child region with an explicit size.
Definition Widget.cpp:826
NodeType
Widget node kinds understood by the UI renderer.
Definition UIHost.h:32
FocusDirection
Logical focus movement understood by keyboard, gamepad and automation.
Definition UIHost.h:104
WidgetDesc grid(int columns, std::vector< WidgetDesc > children, std::string id)
Fixed-column grid; children are placed in source order.
Definition Widget.cpp:878
WidgetDesc viewport(std::string id, float width, float height)
Viewport.
Definition Widget.cpp:523
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.
Definition HudGeometry.h:55
WidgetDesc flex(FlexDirection direction, std::vector< WidgetDesc > children, std::string id)
Elastic layout container (row/column). Prefer row / column shorthands.
Definition Widget.cpp:860
ecs::EntityHandle UIHostHandle
Definition UIHost.h:20
FillDirection
Direction of a linear image fill; geometry stays inside the original layout box.
Definition HudGeometry.h:11
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.
Definition Theme.cpp:277
WidgetDesc row(std::vector< WidgetDesc > children, std::string id)
Horizontal elastic layout row.
Definition Widget.cpp:870
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.
Definition Layout.cpp:202
void applyThemeToImGui(const Theme &theme)
Push tokens into ImGui style. Metrics are multiplied by uiScale (default: themeUiScale()).
Definition Theme.cpp:313
float themeUiScale()
Theme ui scale.
Definition Theme.cpp:305
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...
Definition Widget.cpp:906
HudCanvasTransform resolveHudCanvas(const HudCanvas &canvas, float width, float height)
Resolves fit scaling without letterboxing anchors; callers validate positive viewport dimensions.
Definition HudCanvas.h:21
float searchIconGap
Definition Theme.h:31
float toolboxCellSize
Definition Theme.h:20
float sectionSpacingY
Definition Theme.h:29
ThemeLayout layout
Definition Theme.h:43
static Theme dark()
Built-in presets with matching geometry; only colors differ.
Definition Theme.cpp:174
Value/text/toggle change for script: "hostName/nodeId".
Definition UISystem.h:43
std::string kind
Definition UISystem.h:46
std::string nodeId
Definition UISystem.h:45
std::string hostName
Definition UISystem.h:44
One script-facing click: "hostName/nodeId".
Definition UISystem.h:37
std::string hostName
Definition UISystem.h:38
One completed desktop drop with no borrowed node or platform pointers.
Definition UISystem.h:56
Meta public API.
Definition UIHost.h:293
Retained UI widget node (arena tree). Conceptual counterpart of eve::scene::SceneNode; built declarat...
Definition UIHost.h:151
float fontSize
Definition UIHost.h:242
float marginR
Definition UIHost.h:204
float wrapWidth
Definition UIHost.h:245
float paddingB
Definition UIHost.h:209
float paddingT
Definition UIHost.h:207
float minSizeX
Definition UIHost.h:210
float marginB
Definition UIHost.h:205
float maxSizeY
Definition UIHost.h:213
float minSizeY
Definition UIHost.h:211
uint32_t handlerClick
Definition UIHost.h:271
float marginL
Definition UIHost.h:202
float itemHeight
Definition UIHost.h:246
float columnGap
Definition UIHost.h:255
float maxSizeX
Definition UIHost.h:212
float paddingR
Definition UIHost.h:208
float paddingL
Definition UIHost.h:206
float cornerRadius
Definition UIHost.h:241
float marginT
Definition UIHost.h:203
float flexBasis
Definition UIHost.h:263
UIStats public API.
Definition UISystem.h:68
ViewportState public API.
Definition UISystem.h:81
graphics::Canvas * canvas
Definition UISystem.h:83
NodeType type
Definition Widget.h:16
FlexWrap flexWrap
Definition Widget.h:117
std::string valueText
Definition Widget.h:21
FlexDirection flexDirection
Definition Widget.h:107
FlexJustify justifyContent
Definition Widget.h:109
FlexAlign alignItems
Definition Widget.h:108
OverflowMode overflow
Definition Widget.h:118
std::map< std::string, ImVec2 > rectMin
Object::Ptr theme
std::map< std::string, ImVec2 > rectMax
glm::vec4 color