载入中...
搜索中...
未找到
UI.cpp
浏览该文件的文档.
1#include "ui/UI.h"
2#include "ui/DatabasePanel.h"
4#include "ui/EditorShell.h"
5#include "ui/EventSinkOwner.h"
6#include "ui/ObjectRegistry.h"
10#include "ui/PcgLoadingScreen.h"
20#include "ui/PcgTooltip.h"
22
23#include "ui/Inspector.h"
24#include "ui/ParentScaler.h"
25#include "ui/ScenePanel.h"
26#include "ui/Theme.h"
27#include "ui/UISystem.h"
28#include "ui/Widget.h"
29
30#include "common/Capability.h"
31#include "common/Json.h"
32#include "common/Module.h"
35#include "common/Value.h"
36#include "common/config.h"
37#include "graphics/Graphics.h"
38#include "image/Image.h"
39#include "image/ImageData.h"
41#include "window/Window.h"
42#include "window/sdl/Window.h"
43
44#include <SDL2/SDL_events.h>
45#include <squirrel.h>
46#include <simplesquirrel/simplesquirrel.hpp>
47
48#if !(defined(EVENGINE_WEBGPU) && defined(__EMSCRIPTEN__))
49#include <Poco/JSON/Array.h>
50#include <Poco/JSON/Object.h>
51#include <Poco/JSON/Parser.h>
52#include <Poco/JSON/Stringifier.h>
53#endif
54
55#include <algorithm>
56#include <cmath>
57#include <cstdio>
58#include <cstring>
59#include <iterator>
60#include <sstream>
61#include <stdexcept>
62
63namespace eve::ui {
64namespace detail {
65// Internal module binding entry point; no cross-module callers.
66void injectUIComponentClass(ssq::Table &eveTable);
67} // namespace detail
68namespace {
69
70bool validHudFields(const WidgetDesc &node) {
71 return int(node.fillDirection) <= 3 && std::isfinite(node.fillStartDegrees) &&
72 std::isfinite(node.fillInnerRadius) && node.fillInnerRadius >= 0.f && node.fillInnerRadius <= 1.f &&
73 std::isfinite(node.fontSize) && node.fontSize >= 0.f && std::isfinite(node.textAlignX) &&
74 node.textAlignX >= 0.f && node.textAlignX <= 1.f && std::isfinite(node.textAlignY) &&
75 node.textAlignY >= 0.f && node.textAlignY <= 1.f;
76}
77
78UI *uiFromStack(HSQUIRRELVM vm) {
79 UI *self = nullptr;
80 if (SQ_FAILED(sq_getinstanceup(vm, 1, reinterpret_cast<SQUserPointer *>(&self), nullptr)) || !self) return nullptr;
81 return self;
82}
83
84std::string optionalEase(HSQUIRRELVM vm, SQInteger idx, SQInteger n) {
85 if (n < idx) return "smoothstep";
86 const SQChar *ease = nullptr;
87 if (SQ_FAILED(sq_getstring(vm, idx, &ease)) || !ease) return "smoothstep";
88 return ease;
89}
90
91float optionalDelay(HSQUIRRELVM vm, SQInteger idx, SQInteger n) {
92 if (n < idx) return 0.f;
93 SQFloat delay = 0.f;
94 if (SQ_FAILED(sq_getfloat(vm, idx, &delay))) return 0.f;
95 return float(delay);
96}
97
99SQInteger sqAnimateHostPos(HSQUIRRELVM vm) {
100 const SQInteger n = sq_gettop(vm);
101 if (n < 4 || n > 6) return sq_throwerror(vm, "UI.animateHostPos expects (x, y, durationMs [, ease [, delayMs]])");
102 UI *self = uiFromStack(vm);
103 if (!self) return sq_throwerror(vm, "invalid UI");
104 SQFloat x = 0.f, y = 0.f, durationMs = 0.f;
105 if (SQ_FAILED(sq_getfloat(vm, 2, &x)) || SQ_FAILED(sq_getfloat(vm, 3, &y)) ||
106 SQ_FAILED(sq_getfloat(vm, 4, &durationMs)))
107 return sq_throwerror(vm, "UI.animateHostPos expects float x/y/durationMs");
108 self->animateHostPos(float(x), float(y), float(durationMs), optionalEase(vm, 5, n), optionalDelay(vm, 6, n));
109 return 0;
110}
111
113SQInteger sqAnimateHostSize(HSQUIRRELVM vm) {
114 const SQInteger n = sq_gettop(vm);
115 if (n < 4 || n > 6) return sq_throwerror(vm, "UI.animateHostSize expects (w, h, durationMs [, ease [, delayMs]])");
116 UI *self = uiFromStack(vm);
117 if (!self) return sq_throwerror(vm, "invalid UI");
118 SQFloat w = 0.f, h = 0.f, durationMs = 0.f;
119 if (SQ_FAILED(sq_getfloat(vm, 2, &w)) || SQ_FAILED(sq_getfloat(vm, 3, &h)) ||
120 SQ_FAILED(sq_getfloat(vm, 4, &durationMs)))
121 return sq_throwerror(vm, "UI.animateHostSize expects float w/h/durationMs");
122 self->animateHostSize(float(w), float(h), float(durationMs), optionalEase(vm, 5, n), optionalDelay(vm, 6, n));
123 return 0;
124}
125
127SQInteger sqAnimateHostOverlayAlpha(HSQUIRRELVM vm) {
128 const SQInteger n = sq_gettop(vm);
129 if (n < 3 || n > 5)
130 return sq_throwerror(vm, "UI.animateHostOverlayAlpha expects (alpha, durationMs [, ease [, delayMs]])");
131 UI *self = uiFromStack(vm);
132 if (!self) return sq_throwerror(vm, "invalid UI");
133 SQFloat alpha = 0.f, durationMs = 0.f;
134 if (SQ_FAILED(sq_getfloat(vm, 2, &alpha)) || SQ_FAILED(sq_getfloat(vm, 3, &durationMs)))
135 return sq_throwerror(vm, "UI.animateHostOverlayAlpha expects float alpha/durationMs");
136 self->animateHostOverlayAlpha(float(alpha), float(durationMs), optionalEase(vm, 4, n), optionalDelay(vm, 5, n));
137 return 0;
138}
139
141SQInteger sqAnimateItemOpacity(HSQUIRRELVM vm) {
142 const SQInteger n = sq_gettop(vm);
143 if (n < 4 || n > 6)
144 return sq_throwerror(vm, "UI.animateItemOpacity expects (id, opacity, durationMs [, ease [, delayMs]])");
145 UI *self = uiFromStack(vm);
146 if (!self) return sq_throwerror(vm, "invalid UI");
147 const SQChar *id = nullptr;
148 SQFloat opacity = 0.f, durationMs = 0.f;
149 if (SQ_FAILED(sq_getstring(vm, 2, &id)) || SQ_FAILED(sq_getfloat(vm, 3, &opacity)) ||
150 SQ_FAILED(sq_getfloat(vm, 4, &durationMs)))
151 return sq_throwerror(vm, "UI.animateItemOpacity expects (string id, float opacity, float durationMs)");
152 self->animateItemOpacity(id ? id : "", float(opacity), float(durationMs), optionalEase(vm, 5, n),
153 optionalDelay(vm, 6, n));
154 return 0;
155}
156
158SQInteger sqAnimateItemValue(HSQUIRRELVM vm) {
159 const SQInteger n = sq_gettop(vm);
160 if (n < 4 || n > 6)
161 return sq_throwerror(vm, "UI.animateItemValue expects (id, value, durationMs [, ease [, delayMs]])");
162 UI *self = uiFromStack(vm);
163 if (!self) return sq_throwerror(vm, "invalid UI");
164 const SQChar *id = nullptr;
165 SQFloat value = 0.f, durationMs = 0.f;
166 if (SQ_FAILED(sq_getstring(vm, 2, &id)) || SQ_FAILED(sq_getfloat(vm, 3, &value)) ||
167 SQ_FAILED(sq_getfloat(vm, 4, &durationMs)))
168 return sq_throwerror(vm, "UI.animateItemValue expects (string id, float value, float durationMs)");
169 if (!std::isfinite(float(value)) || !std::isfinite(float(durationMs)) || !std::isfinite(optionalDelay(vm, 6, n)))
170 return sq_throwerror(vm, "UI.animateItemValue expects finite value/duration/delay");
171 self->animateItemValue(id ? id : "", float(value), float(durationMs), optionalEase(vm, 5, n),
172 optionalDelay(vm, 6, n));
173 return 0;
174}
175
177SQInteger sqAnimateItemPos(HSQUIRRELVM vm) {
178 const SQInteger n = sq_gettop(vm);
179 if (n < 5 || n > 7)
180 return sq_throwerror(vm, "UI.animateItemPos expects (id, x, y, durationMs [, ease [, delayMs]])");
181 UI *self = uiFromStack(vm);
182 if (!self) return sq_throwerror(vm, "invalid UI");
183 const SQChar *id = nullptr;
184 SQFloat x = 0.f, y = 0.f, durationMs = 0.f;
185 if (SQ_FAILED(sq_getstring(vm, 2, &id)) || SQ_FAILED(sq_getfloat(vm, 3, &x)) || SQ_FAILED(sq_getfloat(vm, 4, &y)) ||
186 SQ_FAILED(sq_getfloat(vm, 5, &durationMs)))
187 return sq_throwerror(vm, "UI.animateItemPos expects (string id, float x/y/durationMs)");
188 self->animateItemPos(id ? id : "", float(x), float(y), float(durationMs), optionalEase(vm, 6, n),
189 optionalDelay(vm, 7, n));
190 return 0;
191}
192
194SQInteger sqCancelItemTweens(HSQUIRRELVM vm) {
195 const SQInteger n = sq_gettop(vm);
196 if (n < 1 || n > 2) return sq_throwerror(vm, "UI.cancelItemTweens expects ([id])");
197 UI *self = uiFromStack(vm);
198 if (!self) return sq_throwerror(vm, "invalid UI");
199 if (n < 2) {
200 self->cancelItemTweens("");
201 return 0;
202 }
203 const SQChar *id = nullptr;
204 if (SQ_FAILED(sq_getstring(vm, 2, &id))) return sq_throwerror(vm, "UI.cancelItemTweens id must be a string");
205 self->cancelItemTweens(id ? id : "");
206 return 0;
207}
208
209void addOptionalTweenFunc(ssq::Class &cls, const char *name, SQFUNCTION func, SQInteger minParams,
210 const SQChar *typemask) {
211 HSQUIRRELVM vm = cls.getHandle();
212 sq_pushobject(vm, cls.getRaw());
213 sq_pushstring(vm, name, -1);
214 sq_newclosure(vm, func, 0);
215 sq_setparamscheck(vm, -minParams, typemask);
216 sq_newslot(vm, -3, SQFalse);
217 sq_poptop(vm);
218}
219
220std::string jsonQuoted(const std::string &value) {
221 std::string out = "\"";
222 for (const unsigned char ch : value) {
223 switch (ch) {
224 case '\"': out += "\\\""; break;
225 case '\\': out += "\\\\"; break;
226 case '\n': out += "\\n"; break;
227 case '\r': out += "\\r"; break;
228 case '\t': out += "\\t"; break;
229 default:
230 if (ch >= 0x20) out += static_cast<char>(ch);
231 break;
232 }
233 }
234 out += '\"';
235 return out;
236}
237
239void callScriptHandler(ssq::Function &fn, const std::string &kind, const UIEvent &ev) {
240 HSQUIRRELVM vm = fn.getHandle();
241 if (!vm) return;
242 const SQInteger top = sq_gettop(vm);
243 sq_pushobject(vm, fn.getRaw());
244 sq_pushroottable(vm); // env
245 if (kind != "click") {
246 sq_pushstring(vm, kind.c_str(), -1);
247 if (kind == "toggle") sq_pushbool(vm, ev.toggleValue ? SQTrue : SQFalse);
248 else if (kind == "value") sq_pushfloat(vm, ev.floatValue);
249 else sq_pushstring(vm, ev.textValue.c_str(), -1);
250 }
251 // The payload is a runtime variant (bool / float / string), so the shared helper's
252 // typed-argument form does not fit; the count is derived instead, which is the same
253 // rule (R-FACE-7). A handler that throws used to be dropped without a word -- the
254 // two branches below each turned the failure into a bare `return`.
255 const SQInteger params = sq_gettop(vm) - top - 1; // receiver + arguments
256 if (SQ_FAILED(sq_call(vm, params, SQFalse, SQTrue))) {
257 script::reportScriptCallFailure(vm, "ui.handler");
258 }
259 sq_settop(vm, top);
260}
261
262#if !(defined(EVENGINE_WEBGPU) && defined(__EMSCRIPTEN__))
263// JSON UI asset helpers (defined below saveTreeJson/loadTreeJson).
264void nodeToJson(const UIHost::Tree &tree, const UINode &n, Poco::JSON::Object &o);
265WidgetDesc descFromJson(const Poco::JSON::Object &o);
266#endif
267
268
269class UiRootReleaser final : public eve::script::ISquirrelRootReleaser {
270public:
271 void releaseSquirrelRoots() noexcept override {
272 if (auto* ui = ModuleManager::getInstance<UI>("UI")) ui->releaseSquirrelRoots();
273 }
274};
275
276struct RegisterUiRoots {
277 RegisterUiRoots() {
278 static UiRootReleaser releaser;
279 eve::cap::addListener<eve::script::ISquirrelRootReleaser>(&releaser);
280 }
281} g_uiRoots;
282
283} // namespace
284
286
298
300 databasePanel_.reset();
301 if (!ModuleManager::runtime()) return;
302 try {
304 } catch (...) {
305 }
306}
307
308bool UI::isBackendReady() const { return backend_ && backend_->isInitialized(); }
309
311 if (!backend_) backend_ = createImGuiBackend();
312 if (backend_->isInitialized()) return true;
313 auto *win = eve::ModuleManager::getInstance<eve::window::Window>("Window");
314 auto *gfx = eve::ModuleManager::getInstance<eve::graphics::Graphics>("Graphics");
315 if (!win || !gfx) return false;
316 auto *sdlWin = dynamic_cast<eve::window::sdl::Window *>(win);
317 if (!sdlWin) return false;
318 auto *native = static_cast<SDL_Window *>(sdlWin->getHandle());
319 if (!native) return false;
320 const bool ok = backend_->init(native, gfx);
321 if (ok) UISystem::setBackend(*backend_);
322 return ok;
323}
324
327 releaseNinePatches();
329 if (backend_) backend_->shutdown();
330}
331
332void UI::processEvent(const SDL_Event *event) {
334 event->type == SDL_DROPFILE && event->drop.file)
335 UISystem::enqueuePlatformFileDrop(event->drop.file);
336 if (backend_) backend_->processEvent(event);
337}
338
340 if (!isBackendReady()) {
341 if (!initBackend()) return;
342 }
344 if (inspector_ && inspector_->isOpen()) inspector_->sync();
345 if (databasePanel_ && databasePanel_->isOpen()) databasePanel_->sync();
346 backend_->newFrame();
348}
349
350void UI::tickTweens(double nowMs) { tweens_.tick(nowMs); }
351
352std::size_t UI::getHostTweenCount() const { return tweens_.hostTweenCount(); }
353
354std::size_t UI::getItemTweenCount() const { return tweens_.itemTweenCount(); }
355
357 // Copy before dispatch: UISystem::dispatchEvents() consumes the pending list.
358 const std::vector<UIEvent> events = UISystem::pendingEvents();
360 for (const auto &ev : events) {
361 if (!UIHost::resolve(ev.host)) continue;
362 fireScriptHandlers(ev);
363 }
364}
365
366void UI::fireScriptHandlers(const UIEvent &ev) {
367 for (const auto &h : scriptHandlers_) {
368 if (h.hostName != ev.hostName || h.nodeId != ev.nodeId) continue;
369 if (h.kind == "click" && ev.kind == "click") {
370 ssq::Function fn = h.fn;
371 callScriptHandler(fn, "click", ev);
372 } else if (h.kind == ev.kind &&
373 (ev.kind == "toggle" || ev.kind == "value" || ev.kind == "text")) {
374 ssq::Function fn = h.fn;
375 callScriptHandler(fn, ev.kind, ev);
376 }
377 }
378}
379
380void UI::onClick(const std::string &id, ssq::Function fn) {
381 auto host = resolveSelected();
382 if (!host || id.empty()) return;
383 scriptHandlers_.push_back(ScriptHandler(host->get().getName(), id, "click", std::move(fn)));
384}
385
386void UI::onChange(const std::string &id, ssq::Function fn) {
387 auto host = resolveSelected();
388 if (!host || id.empty()) return;
389 for (const char *kind : {"toggle", "value", "text"}) {
390 scriptHandlers_.push_back(ScriptHandler(host->get().getName(), id, kind, fn));
391 }
392}
393
394void UI::componentOnClick(uint64_t owner, const std::string &id, ssq::Function fn) {
395 auto host = resolveSelected();
396 if (!host || owner == 0 || id.empty()) return;
397 scriptHandlers_.push_back(
398 ScriptHandler(host->get().getName(), id, "click", std::move(fn), owner));
399}
400
401void UI::componentOnChange(uint64_t owner, const std::string &id, ssq::Function fn) {
402 auto host = resolveSelected();
403 if (!host || owner == 0 || id.empty()) return;
404 for (const char *kind : {"toggle", "value", "text"}) {
405 scriptHandlers_.push_back(ScriptHandler(host->get().getName(), id, kind, fn, owner));
406 }
407}
408
410 if (owner == 0) return;
411 std::erase_if(scriptHandlers_, [owner](const ScriptHandler &handler) {
412 return handler.owner == owner;
413 });
414}
415
417 return backend_ ? backend_->wantCaptureMouse() : false;
418}
419
421 return backend_ ? backend_->wantCaptureKeyboard() : false;
422}
423
424UIHostHandle UI::findHost(const std::string &name) const { return UISystem::findHost(name); }
425
426UIHostHandle UI::findHostByOwner(uint32_t ownerId) const { return UISystem::findHostByOwner(ownerId); }
427
428bool UI::select(const std::string &name) {
429 const UIHostHandle h = findHost(name);
430 if (!UIHost::resolve(h)) return false;
431 selected_ = h;
432 return true;
433}
434
435void UI::bindOwner(uint32_t ownerId) {
436 if (auto host = resolveSelected()) host->get().setOwnerId(ownerId);
437}
438
439UIHostHandle UI::ensureSelected(const std::string &preferredName) {
440 if (UIHost::resolve(selected_)) return selected_;
441 selected_ = {};
442 if (!preferredName.empty()) {
443 const UIHostHandle h = findHost(preferredName);
444 if (UIHost::resolve(h)) {
445 selected_ = h;
446 return selected_;
447 }
448 selected_ = UIHost::createHost(preferredName);
449 return selected_;
450 }
451 selected_ = UIHost::createHost("default");
452 return selected_;
453}
454
458 if (!host) {
461 } else {
462 host->get().setName(name);
463 }
464 if (!host) return {};
465 host->get().setTree(std::move(root));
466 selected_ = handle;
467 return handle;
468}
469
471 if (auto host = resolveSelected()) {
472 host->get().setTree(std::move(root));
473 return selected_;
474 }
475 return mountAs("default", std::move(root));
476}
477
479 const UIHostHandle handle = ensureSelected();
480 if (auto host = UIHost::resolve(handle)) host->get().setTree(std::move(root));
481 return handle;
482}
483
485 const UIHostHandle handle = ensureSelected();
486 if (auto host = UIHost::resolve(handle)) host->get().setTreeReconcile(std::move(root));
487 return handle;
488}
489
490UIHostHandle UI::remountAs(const std::string &name, WidgetDesc root) { return mountAs(name, std::move(root)); }
491
492eve::OptionalRef<UIHost> UI::resolveSelected() const noexcept { return UIHost::resolve(selected_); }
493
495 openStack_.clear();
496 hasBuiltRoot_ = false;
497 builtRoot_ = WidgetDesc{};
498}
499
500void UI::pushOpen(WidgetDesc d) { openStack_.push_back(std::move(d)); }
501
502WidgetDesc &UI::currentParent() {
503 if (openStack_.empty()) throw std::runtime_error("ui: widget outside beginWindow/beginGroup");
504 return openStack_.back();
505}
506
507void UI::beginWindow(const std::string &title, const std::string &id) {
508 if (openStack_.empty() && hasBuiltRoot_) beginBuild();
509 pushOpen(window(title, {}, id));
510}
511
512void UI::beginGroup(const std::string &id) { pushOpen(group({}, id)); }
513
514void UI::beginList(const std::string &id) { pushOpen(group({}, id)); }
515
516void UI::beginCollapsing(const std::string &label, const std::string &id, bool open) {
517 pushOpen(collapsingHeader(label, {}, id, open));
518}
519
520void UI::beginChild(const std::string &id, float width, float height) {
521 pushOpen(child(id, {}, width, height));
522}
523
524void UI::beginCard(const std::string &id) { pushOpen(card({}, id)); }
525
526bool UI::beginNinePatch(const std::string &path, const std::string &id, float width,
527 float height) {
528 auto *asset = loadNinePatch(path);
529 if (!asset) return false;
530 WidgetDesc d = ninePatchPanel({}, id, asset->textureId);
531 d.sizeX = width;
532 d.sizeY = height;
533 d.minSizeX = float(asset->info.width);
534 d.minSizeY = float(asset->info.height);
535 d.borderL = float(asset->info.borderLeft);
536 d.borderT = float(asset->info.borderTop);
537 d.borderR = float(asset->info.borderRight);
538 d.borderB = float(asset->info.borderBottom);
539 d.paddingL = float(asset->info.paddingLeft);
540 d.paddingT = float(asset->info.paddingTop);
541 d.paddingR = float(asset->info.paddingRight);
542 d.paddingB = float(asset->info.paddingBottom);
543 pushOpen(std::move(d));
544 return true;
545}
546
547void UI::beginMenuBar(const std::string &id) { pushOpen(menuBar({}, id)); }
548
549void UI::beginMenu(const std::string &label, const std::string &id) {
550 pushOpen(menu(label, {}, id));
551}
552
553void UI::beginToolbar(const std::string &id) { pushOpen(toolbar({}, id)); }
554
555void UI::beginToolbox(const std::string &id, float cellSize, int columns) {
556 pushOpen(toolbox({}, id, cellSize, columns));
557}
558
559void UI::beginSidebar(const std::string &id, float width) {
560 pushOpen(sidebar({}, id, width));
561}
562
563void UI::beginStatusBar(const std::string &id) { pushOpen(statusBar({}, id)); }
564
565void UI::beginTabBar(const std::string &id) { pushOpen(tabBar({}, id)); }
566
567void UI::beginTabContainer(const std::string &activePageId, const std::string &id) {
570 d.id = id;
571 d.key = id;
572 d.valueText = activePageId;
573 d.flexDirection = FlexDirection::Column;
574 d.flexGrow = 1.f;
575 pushOpen(std::move(d));
576}
577
578void UI::beginPanelFrame(const std::string &title, const std::string &id) { pushOpen(panelFrame(title, {}, id)); }
579
580void UI::beginDockArea(const std::string &region, const std::string &id) { pushOpen(dockArea(region, {}, id)); }
581
582void UI::beginAppFrame(const std::string &id) {
585 d.id = id;
586 d.key = id;
587 d.flexDirection = FlexDirection::Column;
588 d.flexGrow = 1.f;
589 d.percentW = 1.f;
590 d.percentH = 1.f;
591 pushOpen(std::move(d));
592}
593
594void UI::addTab(const std::string &label, const std::string &pageId, bool selected, const std::string &id) {
595 currentParent().children.push_back(tab(label, pageId, selected, id));
596}
597
598void UI::beginScrollList(const std::string &id, float height, float itemHeight) {
599 pushOpen(scrollList(id, {}, height, itemHeight));
600}
601
602namespace {
603
604std::string toLowerCopy(std::string s) {
605 for (char &c : s) {
606 if (c >= 'A' && c <= 'Z') c = char(c - 'A' + 'a');
607 }
608 return s;
609}
610
611FlexDirection parseFlexDirection(const std::string &direction) {
612 const std::string d = toLowerCopy(direction);
613 if (d == "column" || d == "col" || d == "vertical" || d == "v") return FlexDirection::Column;
614 return FlexDirection::Row;
615}
616
617FlexAlign parseFlexAlign(const std::string &align) {
618 const std::string a = toLowerCopy(align);
619 if (a == "center") return FlexAlign::Center;
620 if (a == "end" || a == "right" || a == "bottom") return FlexAlign::End;
621 if (a == "stretch") return FlexAlign::Stretch;
622 return FlexAlign::Start;
623}
624
625FlexJustify parseFlexJustify(const std::string &justify) {
626 const std::string j = toLowerCopy(justify);
627 if (j == "center") return FlexJustify::Center;
628 if (j == "end" || j == "right" || j == "bottom") return FlexJustify::End;
629 if (j == "spacebetween" || j == "space-between" || j == "between")
631 if (j == "spacearound" || j == "space-around" || j == "around") return FlexJustify::SpaceAround;
632 return FlexJustify::Start;
633}
634
635OverflowMode parseOverflowMode(const std::string &overflow) {
636 const std::string value = toLowerCopy(overflow);
637 if (value == "clip" || value == "hidden") return OverflowMode::Clip;
638 if (value == "scroll" || value == "auto") return OverflowMode::Scroll;
640}
641
642FocusMode parseFocusMode(const std::string &mode) {
643 const std::string value = toLowerCopy(mode);
644 if (value == "none") return FocusMode::None;
645 if (value == "click") return FocusMode::Click;
646 return FocusMode::All;
647}
648
649MouseFilter parseMouseFilter(const std::string &filter) {
650 const std::string value = toLowerCopy(filter);
651 if (value == "pass") return MouseFilter::Pass;
652 if (value == "ignore") return MouseFilter::Ignore;
653 return MouseFilter::Stop;
654}
655
656ThemePreset parseThemePreset(const std::string &theme) {
657 const std::string value = toLowerCopy(theme);
658 if (value == "dark") return ThemePreset::Dark;
659 if (value == "light") return ThemePreset::Light;
661}
662
663AccessibilityRole parseAccessibilityRole(const std::string &role) {
664 const std::string value = toLowerCopy(role);
665 if (value == "button") return AccessibilityRole::Button;
666 if (value == "checkbox") return AccessibilityRole::Checkbox;
667 if (value == "slider") return AccessibilityRole::Slider;
668 if (value == "text") return AccessibilityRole::Text;
669 if (value == "link") return AccessibilityRole::Link;
670 if (value == "textinput" || value == "text-input") return AccessibilityRole::TextInput;
671 if (value == "list") return AccessibilityRole::List;
672 if (value == "listitem" || value == "list-item") return AccessibilityRole::ListItem;
673 if (value == "menu") return AccessibilityRole::Menu;
674 if (value == "menuitem" || value == "menu-item") return AccessibilityRole::MenuItem;
675 if (value == "progress") return AccessibilityRole::Progress;
676 if (value == "region") return AccessibilityRole::Region;
677 if (value == "tab") return AccessibilityRole::Tab;
678 if (value == "window") return AccessibilityRole::Window;
680}
681
682bool parseFocusDirection(const std::string &direction, FocusDirection *out) {
683 if (!out) return false;
684 const std::string value = toLowerCopy(direction);
685 if (value == "next") *out = FocusDirection::Next;
686 else if (value == "previous" || value == "prev") *out = FocusDirection::Previous;
687 else if (value == "left") *out = FocusDirection::Left;
688 else if (value == "right") *out = FocusDirection::Right;
689 else if (value == "up") *out = FocusDirection::Up;
690 else if (value == "down") *out = FocusDirection::Down;
691 else return false;
692 return true;
693}
694
695} // namespace
696
697void UI::beginFlex(const std::string &direction, const std::string &id, float gap) {
698 WidgetDesc d = flex(parseFlexDirection(direction), {}, id);
699 d.gap = gap;
700 pushOpen(std::move(d));
701}
702
703void UI::beginRow(const std::string &id, float gap) { beginFlex("row", id, gap); }
704
705void UI::beginColumn(const std::string &id, float gap) { beginFlex("column", id, gap); }
706
707void UI::beginGrid(int columns, const std::string &id, float columnGap, float rowGap) {
708 WidgetDesc d = grid(columns, {}, id);
709 d.columnGap = columnGap;
710 d.rowGap = rowGap;
711 pushOpen(std::move(d));
712}
713
714void UI::beginSplitPane(const std::string &direction, float ratio, const std::string &id) {
717 d.id = id;
718 d.key = id;
719 d.flexDirection = parseFlexDirection(direction);
720 d.value = std::max(0.1f, std::min(0.9f, ratio));
721 d.minValue = 0.1f;
722 d.maxValue = 0.9f;
723 pushOpen(std::move(d));
724}
725
726void UI::end() {
727 if (openStack_.empty()) throw std::runtime_error("ui: end() without begin");
728 WidgetDesc finished = std::move(openStack_.back());
729 openStack_.pop_back();
730 if (openStack_.empty()) {
731 builtRoot_ = std::move(finished);
732 hasBuiltRoot_ = true;
733 } else {
734 openStack_.back().children.push_back(std::move(finished));
735 }
736}
737
738void UI::addText(const std::string &content, const std::string &id) {
739 currentParent().children.push_back(text(content, id));
740}
741
742void UI::addTextWrapped(const std::string &content, float width, const std::string &id) {
743 WidgetDesc d = text(content, id);
744 d.wrapWidth = width;
745 currentParent().children.push_back(std::move(d));
746}
747
748void UI::addButton(const std::string &label, const std::string &id) {
749 currentParent().children.push_back(button(label, id));
750}
751
752void UI::addIcon(const std::string &name, const std::string &id) {
755 currentParent().children.push_back(icon(value, id));
756}
757
758void UI::addIconButton(const std::string &name, const std::string &label, const std::string &id) {
761 currentParent().children.push_back(iconButton(value, label, id));
762}
763
764void UI::addSameLine(const std::string &id) { currentParent().children.push_back(sameLine(id)); }
765
766void UI::addSeparator(const std::string &id) {
767 currentParent().children.push_back(separator(id));
768}
769
770void UI::addCheckbox(const std::string &label, bool checked, const std::string &id) {
771 currentParent().children.push_back(checkbox(label, checked, id));
772}
773
774void UI::addSlider(const std::string &label, float value, float minV, float maxV,
775 const std::string &id) {
776 currentParent().children.push_back(slider(label, value, minV, maxV, id));
777}
778
779void UI::addColorPalette(const std::string &label, float r, float g, float b, float a,
780 const std::string &id) {
781 currentParent().children.push_back(colorPalette(label, r, g, b, a, id));
782}
783
784void UI::addProgress(float fraction, const std::string &id, const std::string &overlay) {
785 currentParent().children.push_back(progress(fraction, id, overlay));
786}
787
788void UI::addFilledImage(const std::string &id, float width, float height, float fraction) {
789 currentParent().children.push_back(filledImage(id, width, height, fraction));
790}
791
792void UI::addResourceBar(const std::string &id, float width, float height, float fraction) {
793 currentParent().children.push_back(resourceBar(id, width, height, fraction));
794}
795
796void UI::addSkillSlot(const std::string &id, float size, uint64_t iconTexture, float cooldown, const std::string &key) {
797 currentParent().children.push_back(skillSlot(id, size, iconTexture, cooldown, key));
798}
799
800void UI::addRadialFill(const std::string &id, float width, float height, float fraction) {
801 currentParent().children.push_back(radialFill(id, width, height, fraction));
802}
803
804void UI::setItemFillDirection(const std::string &direction, bool stretch) {
806 if (direction == "right")
808 else if (direction == "left")
810 else if (direction == "down")
812 else if (direction == "up")
814 else
815 throw std::invalid_argument("UI fill direction must be right, left, down or up");
816 if (currentParent().children.empty()) throw std::logic_error("UI fill options require a built item");
817 auto &item = currentParent().children.back();
818 item.fillDirection = value;
819 item.fillStretch = stretch;
820}
821
822void UI::setItemRadialFill(float startDegrees, bool clockwise, float innerRadius) {
823 if (!std::isfinite(startDegrees) || !std::isfinite(innerRadius) || innerRadius < 0.f || innerRadius > 1.f)
824 throw std::invalid_argument("UI radial fill requires finite degrees and inner radius in [0,1]");
825 if (currentParent().children.empty()) throw std::logic_error("UI fill options require a built item");
826 auto &item = currentParent().children.back();
827 item.fillStartDegrees = startDegrees;
828 item.fillClockwise = clockwise;
829 item.fillInnerRadius = innerRadius;
830}
831
832void UI::addImage(const std::string &id, float width, float height) {
833 currentParent().children.push_back(image(id, width, height));
834}
835
836bool UI::addNinePatch(const std::string &path, const std::string &id, float width,
837 float height) {
838 auto *asset = loadNinePatch(path);
839 if (!asset) return false;
840 WidgetDesc d = image(id, width > 0.f ? width : float(asset->info.width),
841 height > 0.f ? height : float(asset->info.height));
842 d.textureId = asset->textureId;
843 d.borderL = float(asset->info.borderLeft);
844 d.borderT = float(asset->info.borderTop);
845 d.borderR = float(asset->info.borderRight);
846 d.borderB = float(asset->info.borderBottom);
847 currentParent().children.push_back(std::move(d));
848 return true;
849}
850
851void UI::addImageButton(const std::string &id, float width, float height) {
852 currentParent().children.push_back(imageButton(id, width, height));
853}
854
855void UI::addViewport(const std::string &id, float width, float height) {
856 currentParent().children.push_back(viewport(id, width, height));
857}
858
859void UI::addCombo(const std::string &label, const std::string &options, int selected,
860 const std::string &id) {
861 std::vector<std::string> items;
862 size_t start = 0;
863 while (start <= options.size()) {
864 const size_t end = options.find('\n', start);
865 items.push_back(options.substr(start, end == std::string::npos ? std::string::npos
866 : end - start));
867 if (end == std::string::npos) break;
868 start = end + 1;
869 }
870 currentParent().children.push_back(combo(label, items, selected, id));
871}
872
873void UI::addLink(const std::string &label, const std::string &target, const std::string &id) {
874 currentParent().children.push_back(link(label, target, id));
875}
876
877void UI::setItemTextInput(bool multiline, bool readOnly, const std::string &placeholder) {
878 auto &children = currentParent().children;
879 if (!children.empty()) children.back().withTextInput(multiline, readOnly, placeholder);
880}
881
882void UI::setItemHelp(const std::string &help, const std::string &disabledReason) {
883 auto &children = currentParent().children;
884 if (!children.empty()) children.back().withHelp(help, disabledReason);
885}
886
887void UI::addInputText(const std::string &label, const std::string &value, const std::string &id) {
888 currentParent().children.push_back(inputText(label, value, id));
889}
890
891void UI::addSearchField(const std::string &hint, const std::string &value,
892 const std::string &id) {
893 currentParent().children.push_back(searchField(hint, value, id));
894}
895
896void UI::addSwitch(const std::string &label, bool checked, const std::string &id) {
897 currentParent().children.push_back(toggleSwitch(label, checked, id));
898}
899
900void UI::addBadge(const std::string &label, const std::string &id) {
901 currentParent().children.push_back(badge(label, id));
902}
903
904void UI::addSectionHeader(const std::string &label, const std::string &id) {
905 currentParent().children.push_back(sectionHeader(label, id));
906}
907
908void UI::addMenuItem(const std::string &label, const std::string &shortcut,
909 const std::string &id) {
910 currentParent().children.push_back(menuItem(label, shortcut, id));
911}
912
913void UI::addSpacer(const std::string &id, float grow) {
914 currentParent().children.push_back(spacer(id, grow));
915}
916
917void UI::setItemFlexGrow(float grow) {
918 WidgetDesc &parent = currentParent();
919 if (parent.children.empty()) return;
920 parent.children.back().flexGrow = grow;
921}
922
923void UI::setItemFlexShrink(float shrink) {
924 WidgetDesc &parent = currentParent();
925 if (!parent.children.empty()) parent.children.back().flexShrink = std::max(0.f, shrink);
926}
927
928void UI::setItemFlexBasis(float basis) {
929 WidgetDesc &parent = currentParent();
930 if (!parent.children.empty()) parent.children.back().flexBasis = basis;
931}
932
933void UI::setItemAlignSelf(const std::string &align) {
934 WidgetDesc &parent = currentParent();
935 if (parent.children.empty()) return;
936 parent.children.back().alignSelf = align == "inherit" ? -1 : int(parseFlexAlign(align));
937}
938
940 WidgetDesc &parent = currentParent();
941 if (!parent.children.empty()) parent.children.back().aspectRatio = std::max(0.f, ratio);
942}
943
945 WidgetDesc &parent = currentParent();
946 if (!parent.children.empty()) parent.children.back().gridColumnSpan = std::max(1, span);
947}
948
949void UI::setItemSize(float width, float height) {
950 WidgetDesc &parent = currentParent();
951 if (parent.children.empty()) return;
952 parent.children.back().sizeX = width;
953 parent.children.back().sizeY = height;
954}
955
956void UI::setItemMargin(float l, float t, float r, float b) {
957 WidgetDesc &parent = currentParent();
958 if (parent.children.empty()) return;
959 parent.children.back().marginL = l;
960 parent.children.back().marginT = t;
961 parent.children.back().marginR = r;
962 parent.children.back().marginB = b;
963}
964
965void UI::setItemPadding(float l, float t, float r, float b) {
966 WidgetDesc &parent = currentParent();
967 if (parent.children.empty()) return;
968 parent.children.back().paddingL = l;
969 parent.children.back().paddingT = t;
970 parent.children.back().paddingR = r;
971 parent.children.back().paddingB = b;
972}
973
974void UI::setItemMinSize(float w, float h) {
975 WidgetDesc &parent = currentParent();
976 if (parent.children.empty()) return;
977 parent.children.back().minSizeX = w;
978 parent.children.back().minSizeY = h;
979}
980
981void UI::setItemMaxSize(float w, float h) {
982 WidgetDesc &parent = currentParent();
983 if (parent.children.empty()) return;
984 parent.children.back().maxSizeX = w;
985 parent.children.back().maxSizeY = h;
986}
987
988void UI::setItemPercent(float w, float h) {
989 WidgetDesc &parent = currentParent();
990 if (parent.children.empty()) return;
991 parent.children.back().percentW = w;
992 parent.children.back().percentH = h;
993}
994
995void UI::setItemAbsolute(float anchorX, float anchorY, float x, float y) {
996 WidgetDesc &parent = currentParent();
997 if (parent.children.empty()) return;
998 parent.children.back().absolute = true;
999 parent.children.back().anchorX = anchorX;
1000 parent.children.back().anchorY = anchorY;
1001 parent.children.back().posX = x;
1002 parent.children.back().posY = y;
1003}
1004
1005void UI::setItemTooltip(const std::string &text) {
1006 WidgetDesc &parent = currentParent();
1007 if (parent.children.empty()) return;
1008 parent.children.back().tooltip = text;
1009}
1010
1011void UI::setItemDragSource(const std::string &payloadType, const std::string &payloadText) {
1012 WidgetDesc &parent = currentParent();
1013 if (parent.children.empty()) return;
1014 auto &item = parent.children.back();
1015 item.dragSource = !payloadType.empty();
1016 item.dragPayloadType = payloadType;
1017 item.dragPayloadText = payloadText;
1018}
1019
1020void UI::setItemDropTarget(const std::string &acceptedType) {
1021 WidgetDesc &parent = currentParent();
1022 if (parent.children.empty()) return;
1023 auto &item = parent.children.back();
1024 item.dropTarget = !acceptedType.empty();
1025 item.acceptedDropType = acceptedType;
1026}
1027
1029 WidgetDesc &parent = currentParent();
1030 if (!parent.children.empty()) parent.children.back().enabled = enabled;
1031}
1032
1034 WidgetDesc &parent = currentParent();
1035 if (!parent.children.empty()) parent.children.back().checked = selected;
1036}
1037
1038void UI::setItemFocusMode(const std::string &mode) {
1039 WidgetDesc &parent = currentParent();
1040 if (!parent.children.empty()) parent.children.back().focusMode = parseFocusMode(mode);
1041}
1042
1043void UI::setItemMouseFilter(const std::string &filter) {
1044 WidgetDesc &parent = currentParent();
1045 if (!parent.children.empty()) parent.children.back().mouseFilter = parseMouseFilter(filter);
1046}
1047
1048void UI::setItemTheme(const std::string &theme) {
1049 WidgetDesc &parent = currentParent();
1050 if (!parent.children.empty()) parent.children.back().themePreset = parseThemePreset(theme);
1051}
1052
1053void UI::setThemeScope(const std::string &theme) {
1054 currentParent().themePreset = parseThemePreset(theme);
1055}
1056
1057void UI::setItemStyleClass(const std::string &name) {
1058 WidgetDesc &parent = currentParent();
1059 if (!parent.children.empty()) parent.children.back().styleClass = name;
1060}
1061
1062void UI::setStyleScope(const std::string &name) { currentParent().styleClass = name; }
1063
1065 WidgetDesc &parent = currentParent();
1066 if (!parent.children.empty()) parent.children.back().tabIndex = index;
1067}
1068
1069void UI::setItemFocusOrder(const std::string &previous, const std::string &next) {
1070 WidgetDesc &parent = currentParent();
1071 if (parent.children.empty()) return;
1072 parent.children.back().focusPrevious = previous;
1073 parent.children.back().focusNext = next;
1074}
1075
1076void UI::setItemFocusNeighbors(const std::string &left, const std::string &right,
1077 const std::string &up, const std::string &down) {
1078 WidgetDesc &parent = currentParent();
1079 if (parent.children.empty()) return;
1080 parent.children.back().focusLeft = left;
1081 parent.children.back().focusRight = right;
1082 parent.children.back().focusUp = up;
1083 parent.children.back().focusDown = down;
1084}
1085
1086void UI::setItemAccessibility(const std::string &role, const std::string &name,
1087 const std::string &description) {
1088 WidgetDesc &parent = currentParent();
1089 if (parent.children.empty()) return;
1090 parent.children.back().accessibilityRole = parseAccessibilityRole(role);
1091 parent.children.back().accessibilityName = name;
1092 parent.children.back().accessibilityDescription = description;
1093}
1094
1095void UI::setFlexAlign(const std::string &align) {
1096 WidgetDesc &parent = currentParent();
1097 if (parent.type != NodeType::Flex) return;
1098 parent.alignItems = parseFlexAlign(align);
1099}
1100
1101void UI::setFlexJustify(const std::string &justify) {
1102 WidgetDesc &parent = currentParent();
1103 if (parent.type != NodeType::Flex) return;
1104 parent.justifyContent = parseFlexJustify(justify);
1105}
1106
1107void UI::setLayoutGaps(float columnGap, float rowGap) {
1108 WidgetDesc &parent = currentParent();
1109 if (parent.type != NodeType::Flex && parent.type != NodeType::Grid) return;
1110 parent.columnGap = columnGap;
1111 parent.rowGap = rowGap;
1112}
1113
1114void UI::setFlexWrap(bool wrap) {
1115 WidgetDesc &parent = currentParent();
1116 if (parent.type == NodeType::Flex)
1117 parent.flexWrap = wrap ? FlexWrap::Wrap : FlexWrap::NoWrap;
1118}
1119
1120void UI::setLayoutOverflow(const std::string &overflow) {
1121 WidgetDesc &parent = currentParent();
1122 if (parent.type == NodeType::Flex || parent.type == NodeType::Grid)
1123 parent.overflow = parseOverflowMode(overflow);
1124}
1125
1126void UI::addListItem(const std::string &label, const std::string &id) {
1127 WidgetDesc &parent = currentParent();
1128 std::string itemId = id;
1129 if (itemId.empty())
1130 itemId = parent.id + "/" + std::to_string(parent.children.size());
1131 parent.children.push_back(button(label, itemId).withKey(itemId));
1132}
1133
1134bool UI::buildComplete() const { return openStack_.empty() && hasBuiltRoot_; }
1135
1137 if (!buildComplete()) return false;
1138 const UIHostHandle handle = remount(std::move(builtRoot_));
1139 if (!UIHost::resolve(handle)) return false;
1140 hasBuiltRoot_ = false;
1141 builtRoot_ = WidgetDesc{};
1142 return true;
1143}
1144
1145bool UI::mountBuildAs(const std::string &name) {
1146 if (!buildComplete()) return false;
1147 const UIHostHandle handle = mountAs(name, std::move(builtRoot_));
1148 if (!UIHost::resolve(handle)) return false;
1149 hasBuiltRoot_ = false;
1150 builtRoot_ = WidgetDesc{};
1151 return true;
1152}
1153
1154bool UI::remountBuildAs(const std::string &name) {
1155 if (!buildComplete()) return false;
1158 auto host = UIHost::resolve(h);
1159 if (!host) return false;
1160 host->get().setTreeReconcile(std::move(builtRoot_));
1161 selected_ = h;
1162 hasBuiltRoot_ = false;
1163 builtRoot_ = WidgetDesc{};
1164 return true;
1165}
1166
1167bool UI::setListItems(const std::string &listId, const std::vector<std::string> &items) {
1168 auto host = resolveSelected();
1169 if (!host) return false;
1170 WidgetDesc listNode = listButtons(listId, items);
1171 auto existing = host->get().findById(listId);
1172 if (existing && existing->get().type == NodeType::Group) {
1173 host->get().setTreeReconcile(
1174 window(host->get().getName().empty() ? "List" : host->get().getName(), {std::move(listNode)}, "root"));
1175 return true;
1176 }
1177 host->get().setTree(
1178 window(host->get().getName().empty() ? "List" : host->get().getName(), {std::move(listNode)}, "root"));
1179 return true;
1180}
1181
1182void UI::setText(const std::string &id, const std::string &text) {
1183 if (auto host = resolveSelected()) host->get().setTextById(id, text);
1184}
1185
1186void UI::setTextWrap(const std::string &id, float width) {
1187 auto host = resolveSelected();
1188 if (!host) return;
1189 if (auto n = host->get().findById(id)) n->get().wrapWidth = width;
1190}
1191
1192void UI::setVisible(const std::string &id, bool visible) {
1193 if (auto host = resolveSelected()) host->get().setVisibleById(id, visible);
1194}
1195
1196void UI::setEnabled(const std::string &id, bool enabled) {
1197 if (auto host = resolveSelected()) host->get().setEnabledById(id, enabled);
1198}
1199
1200void UI::setChecked(const std::string &id, bool checked) {
1201 if (auto host = resolveSelected()) host->get().setCheckedById(id, checked);
1202}
1203
1204void UI::setValue(const std::string &id, float value) {
1205 if (auto host = resolveSelected()) host->get().setValueById(id, value);
1206}
1207
1208void UI::setValueText(const std::string &id, const std::string &value) {
1209 if (auto host = resolveSelected()) host->get().setValueTextById(id, value);
1210}
1211
1212void UI::setColor(const std::string &id, float r, float g, float b, float a) {
1213 setImageTint(id, r, g, b, a);
1214}
1215
1216void UI::setImageTint(const std::string &id, float r, float g, float b, float a) {
1217 auto host = resolveSelected();
1218 if (!host) return;
1219 if (auto n = host->get().findById(id)) {
1220 n->get().tintR = r;
1221 n->get().tintG = g;
1222 n->get().tintB = b;
1223 n->get().tintA = a;
1224 }
1225}
1226
1227void UI::setImageUv(const std::string &id, float u0, float v0, float u1, float v1) {
1228 auto host = resolveSelected();
1229 if (!host) return;
1230 if (auto n = host->get().findById(id)) {
1231 n->get().uv0x = u0;
1232 n->get().uv0y = v0;
1233 n->get().uv1x = u1;
1234 n->get().uv1y = v1;
1235 }
1236}
1237
1238void UI::setImageNinePatch(const std::string &id, float l, float t, float r, float b) {
1239 auto host = resolveSelected();
1240 if (!host) return;
1241 if (auto n = host->get().findById(id)) {
1242 n->get().borderL = l;
1243 n->get().borderT = t;
1244 n->get().borderR = r;
1245 n->get().borderB = b;
1246 }
1247}
1248
1249void UI::setImageCornerRadius(const std::string &id, float radius) {
1250 auto host = resolveSelected();
1251 if (!host) return;
1252 if (auto n = host->get().findById(id)) n->get().cornerRadius = radius;
1253}
1254
1255void UI::setImageTextureId(const std::string &id, uint64_t textureId) {
1256 auto host = resolveSelected();
1257 if (!host) return;
1258 if (auto n = host->get().findById(id)) n->get().textureId = textureId;
1259}
1260
1262 if (!isBackendReady()) {
1263 if (!initBackend()) return 0;
1264 }
1265 return backend_ ? backend_->registerTexture(tex) : 0;
1266}
1267
1268void UI::unregisterTexture(uint64_t textureId) {
1269 if (backend_ && textureId != 0) backend_->unregisterTexture(textureId);
1270}
1271
1272float UI::getValue(const std::string &id) const {
1273 auto host = resolveSelected();
1274 if (!host) return 0.f;
1275 if (auto n = host->get().findById(id)) return n->get().value;
1276 return 0.f;
1277}
1278
1279std::string UI::getValueText(const std::string &id) const {
1280 auto host = resolveSelected();
1281 if (!host) return {};
1282 if (auto n = host->get().findById(id)) return n->get().valueText;
1283 return {};
1284}
1285
1286float UI::getColorR(const std::string &id) const {
1287 auto host = resolveSelected();
1288 if (!host) return 0.f;
1289 if (auto n = host->get().findById(id)) return n->get().tintR;
1290 return 0.f;
1291}
1292
1293float UI::getColorG(const std::string &id) const {
1294 auto host = resolveSelected();
1295 if (!host) return 0.f;
1296 if (auto n = host->get().findById(id)) return n->get().tintG;
1297 return 0.f;
1298}
1299
1300float UI::getColorB(const std::string &id) const {
1301 auto host = resolveSelected();
1302 if (!host) return 0.f;
1303 if (auto n = host->get().findById(id)) return n->get().tintB;
1304 return 0.f;
1305}
1306
1307float UI::getColorA(const std::string &id) const {
1308 auto host = resolveSelected();
1309 if (!host) return 0.f;
1310 if (auto n = host->get().findById(id)) return n->get().tintA;
1311 return 0.f;
1312}
1313
1314bool UI::getChecked(const std::string &id) const {
1315 auto host = resolveSelected();
1316 if (!host) return false;
1317 if (auto n = host->get().findById(id)) return n->get().checked;
1318 return false;
1319}
1320
1321bool UI::setImageNinePatchFile(const std::string &id, const std::string &path) {
1322 auto host = resolveSelected();
1323 if (!host) return false;
1324 auto n = host->get().findById(id);
1325 if (!n || (n->get().type != NodeType::Image && n->get().type != NodeType::ImageButton &&
1326 n->get().type != NodeType::NinePatchPanel))
1327 return false;
1328 auto *asset = loadNinePatch(path);
1329 if (!asset) return false;
1330 n->get().textureId = asset->textureId;
1331 n->get().borderL = float(asset->info.borderLeft);
1332 n->get().borderT = float(asset->info.borderTop);
1333 n->get().borderR = float(asset->info.borderRight);
1334 n->get().borderB = float(asset->info.borderBottom);
1335 if (n->get().type == NodeType::NinePatchPanel) {
1336 n->get().paddingL = float(asset->info.paddingLeft);
1337 n->get().paddingT = float(asset->info.paddingTop);
1338 n->get().paddingR = float(asset->info.paddingRight);
1339 n->get().paddingB = float(asset->info.paddingBottom);
1340 }
1341 return true;
1342}
1343
1344UI::NinePatchResource *UI::loadNinePatch(const std::string &path) {
1345 if (auto found = ninePatches_.find(path); found != ninePatches_.end())
1346 return &found->second;
1347 auto *images = eve::ModuleManager::getInstance<eve::image::Image>("Image");
1348 auto *graphics = eve::ModuleManager::getInstance<eve::graphics::Graphics>("Graphics");
1349 if (!images || !graphics) return nullptr;
1350 try {
1351 // The provider hands back a cache-owned ImageData; the pin keeps it alive
1352 // while the nine-patch border is measured and stripped.
1353 eve::image::ImageData *source = images->newImageDataFromFile(path);
1354 if (source == nullptr) return nullptr;
1355 auto sourcePin = eve::ResourceManager::getInstance().pin(source);
1356 if (!sourcePin.ok()) return nullptr;
1357 eve::ResourcePin keepAlive = std::move(sourcePin).takeValue();
1358 // The pin is the authority from here on; the borrowed pointer may have gone stale
1359 // before the pin was taken.
1360 source = static_cast<eve::image::ImageData *>(keepAlive.get());
1361 NinePatchResource resource;
1362 std::string error;
1363 if (!parseNinePatch(*source, resource.info, &error)) {
1364 std::fprintf(stderr, "[ui] invalid .9.png '%s': %s\n", path.c_str(),
1365 error.c_str());
1366 return nullptr;
1367 }
1368 auto cropped = stripNinePatchBorder(*source);
1369 if (!cropped) return nullptr;
1370 resource.texture = graphics->newTexture(cropped.get());
1371 if (!resource.texture) return nullptr;
1372 resource.textureId = registerTexture(resource.texture);
1373 if (resource.textureId == 0) {
1374 graphics->releaseTexture(resource.texture);
1375 return nullptr;
1376 }
1377 auto inserted = ninePatches_.emplace(path, std::move(resource));
1378 return &inserted.first->second;
1379 } catch (const std::exception &e) {
1380 std::fprintf(stderr, "[ui] failed to load .9.png '%s': %s\n", path.c_str(), e.what());
1381 return nullptr;
1382 }
1383}
1384
1385void UI::releaseNinePatches() {
1386 auto *graphics = eve::ModuleManager::getInstance<eve::graphics::Graphics>("Graphics");
1387 for (auto &[path, resource] : ninePatches_) {
1388 (void)path;
1389 if (backend_ && resource.textureId != 0)
1390 backend_->unregisterTexture(resource.textureId);
1391 if (graphics && resource.texture) graphics->releaseTexture(resource.texture);
1392 }
1393 ninePatches_.clear();
1394}
1395
1396bool UI::requestFocus(const std::string &id) {
1397 if (auto host = resolveSelected()) return host->get().requestFocusById(id);
1398 return false;
1399}
1400
1401bool UI::moveFocus(const std::string &direction) {
1402 auto host = resolveSelected();
1403 if (!host) return false;
1405 return parseFocusDirection(direction, &parsed) && host->get().moveFocus(parsed);
1406}
1407
1408std::string UI::getFocusedId() const {
1409 if (auto host = resolveSelected()) return host->get().focusedId();
1410 return {};
1411}
1412
1414 if (auto host = resolveSelected()) host->get().setVisible(visible);
1415}
1416
1418 if (auto host = resolveSelected()) host->get().setLayer(layer);
1419}
1420
1421void UI::setHostModal(bool modal) {
1422 if (auto host = resolveSelected()) host->get().setModal(modal);
1423}
1424
1425void UI::setHostOverlay(bool overlay) {
1426 if (auto host = resolveSelected()) host->get().meta()->overlay = overlay;
1427}
1428
1429void UI::setHostInputTransparent(bool transparent) {
1430 if (auto host = resolveSelected()) host->get().meta()->inputTransparent = transparent;
1431}
1432
1433void UI::setHostHudCanvas(float referenceWidth, float referenceHeight, float userScale) {
1434 if (!std::isfinite(referenceWidth) || !std::isfinite(referenceHeight) || !std::isfinite(userScale) ||
1435 referenceWidth <= 0.f || referenceHeight <= 0.f || userScale <= 0.f)
1436 throw std::invalid_argument("HUD canvas dimensions and scale must be finite and positive");
1437 if (auto host = resolveSelected()) {
1438 auto &canvas = host->get().meta()->canvas;
1439 canvas.enabled = true;
1440 canvas.referenceWidth = referenceWidth;
1441 canvas.referenceHeight = referenceHeight;
1442 canvas.userScale = userScale;
1443 }
1444}
1445
1447 if (auto host = resolveSelected()) host->get().meta()->canvas.enabled = false;
1448}
1449
1450void UI::setHostSafeArea(float left, float top, float right, float bottom) {
1451 for (float margin : {left, top, right, bottom})
1452 if (!std::isfinite(margin) || margin < 0.f)
1453 throw std::invalid_argument("HUD safe margins must be finite and nonnegative");
1454 if (auto host = resolveSelected()) {
1455 auto &canvas = host->get().meta()->canvas;
1456 canvas.safeLeft = left;
1457 canvas.safeTop = top;
1458 canvas.safeRight = right;
1459 canvas.safeBottom = bottom;
1460 }
1461}
1462
1463void UI::setHostOverlayAlpha(float alpha) {
1464 if (auto host = resolveSelected()) host->get().meta()->overlayBgAlpha = std::max(0.f, std::min(1.f, alpha));
1465}
1466
1467void UI::setHostMovable(bool movable) {
1468 if (auto host = resolveSelected()) host->get().meta()->lockPos = !movable;
1469}
1470
1472 if (auto host = resolveSelected()) host->get().meta()->lockSize = !resizable;
1473}
1474
1475void UI::setHostPos(float x, float y, float pivotX, float pivotY) {
1476 auto host = resolveSelected();
1477 if (!host) return;
1478 auto m = host->get().meta();
1479 m->hasPos = true;
1480 m->posX = x;
1481 m->posY = y;
1482 m->pivotX = pivotX;
1483 m->pivotY = pivotY;
1484}
1485
1486void UI::setHostWorldAnchor(float x, float y, float z) {
1487 if (auto host = resolveSelected()) host->get().setWorldAnchor(x, y, z);
1488}
1489
1491 if (auto host = resolveSelected()) host->get().clearWorldAnchor();
1492}
1493
1494void UI::setHostWorldEdgePolicy(const std::string &policy, float safeMargin) {
1495 if (auto host = resolveSelected()) {
1496 auto anchor = host->get().worldAnchor();
1497 anchor->edgePolicy = policy == "clamp" ? WorldAnchorEdgePolicy::Clamp
1499 anchor->safeMargin = std::max(0.f, safeMargin);
1500 }
1501}
1502
1503void UI::setHostWorldDistanceScale(bool enabled, float referenceDistance, float minScale,
1504 float maxScale) {
1505 if (auto host = resolveSelected()) {
1506 auto anchor = host->get().worldAnchor();
1507 anchor->distanceScale = enabled;
1508 anchor->referenceDistance = std::max(referenceDistance, 0.001f);
1509 anchor->minScale = std::max(0.01f, std::min(minScale, maxScale));
1510 anchor->maxScale = std::max(anchor->minScale, std::max(minScale, maxScale));
1511 }
1512}
1513
1514void UI::setHostWorldOverlap(bool enabled, int priority, float padding,
1515 float maxDisplacement) {
1516 if (auto host = resolveSelected()) {
1517 auto anchor = host->get().worldAnchor();
1518 anchor->overlapPolicy = enabled ? WorldAnchorOverlapPolicy::Avoid
1520 anchor->overlapPriority = priority;
1521 anchor->overlapPadding = std::max(0.f, padding);
1522 anchor->maxDisplacement = std::max(0.f, maxDisplacement);
1523 }
1524}
1525
1526std::string UI::getHostWorldState() const {
1527 const auto host = resolveSelected();
1528 if (!host) return "disabled";
1529 switch (host->get().worldAnchor()->state) {
1530 case WorldAnchorState::Visible: return "visible";
1531 case WorldAnchorState::BehindCamera: return "behind-camera";
1532 case WorldAnchorState::OutsideViewport: return "outside-viewport";
1533 case WorldAnchorState::NoCamera: return "no-camera";
1534 case WorldAnchorState::Crowded: return "crowded";
1535 case WorldAnchorState::Disabled: return "disabled";
1536 }
1537 return "disabled";
1538}
1539
1541 if (const auto host = resolveSelected()) return host->get().worldAnchor()->screenX;
1542 return 0.f;
1543}
1544
1546 if (const auto host = resolveSelected()) return host->get().worldAnchor()->screenY;
1547 return 0.f;
1548}
1549
1550void UI::setHostAnchor(float x, float y) {
1551 auto host = resolveSelected();
1552 if (!host) return;
1553 auto m = host->get().meta();
1554 m->anchorX = x;
1555 m->anchorY = y;
1556}
1557
1558void UI::setHostSize(float w, float h) {
1559 auto host = resolveSelected();
1560 if (!host) return;
1561 auto m = host->get().meta();
1562 m->hasSize = true;
1563 m->sizeX = w;
1564 m->sizeY = h;
1565}
1566
1567void UI::setHostPercent(float w, float h) {
1568 auto host = resolveSelected();
1569 if (!host) return;
1570 auto m = host->get().meta();
1571 m->percentW = w;
1572 m->percentH = h;
1573}
1574
1575void UI::animateHostPos(float x, float y, float durationMs, const std::string &ease, float delayMs) {
1576 if (!resolveSelected()) return;
1577 tweens_.animateHostPos(selected_, x, y, durationMs, ease, delayMs, uiTweenWallClockMs());
1578}
1579
1580void UI::animateHostSize(float w, float h, float durationMs, const std::string &ease, float delayMs) {
1581 if (!resolveSelected()) return;
1582 tweens_.animateHostSize(selected_, w, h, durationMs, ease, delayMs, uiTweenWallClockMs());
1583}
1584
1585void UI::animateHostOverlayAlpha(float alpha, float durationMs, const std::string &ease, float delayMs) {
1586 if (!resolveSelected()) return;
1587 tweens_.animateHostOverlayAlpha(selected_, alpha, durationMs, ease, delayMs, uiTweenWallClockMs());
1588}
1589
1590std::string UI::consumeClick() { return UISystem::consumeClick(); }
1591
1593
1594std::string UI::dragDropSupport() const {
1596 ? "supported"
1597 : "unsupported-platform";
1598}
1599
1600std::string UI::consumeDrop() {
1601 auto drop = UISystem::consumeDrop();
1602 if (!drop) return {};
1603 lastDropType_ = std::move(drop->payloadType);
1604 lastDropText_ = std::move(drop->payloadText);
1605 lastDropSource_ = drop->sourceHostName.empty()
1606 ? std::string{}
1607 : drop->sourceHostName + "/" + drop->sourceNodeId;
1608 lastDropOrigin_ = drop->origin == DragDropOrigin::OperatingSystemFile ? "os-file"
1609 : "internal";
1610 return drop->targetHostName.empty() ? drop->targetNodeId
1611 : drop->targetHostName + "/" + drop->targetNodeId;
1612}
1613
1614std::string UI::getDropType() const { return lastDropType_; }
1615
1616std::string UI::getDropText() const { return lastDropText_; }
1617
1618std::string UI::getDropSource() const { return lastDropSource_; }
1619
1620std::string UI::getDropOrigin() const { return lastDropOrigin_; }
1621
1623
1625
1626bool UI::setTheme(const std::string &name) { return setThemeByName(name); }
1627
1628std::string UI::getTheme() const { return globalThemeName(); }
1629
1630std::string UI::defineStyleClass(const std::string &name, const std::string &parent) {
1632}
1633
1634void UI::animateItemOpacity(const std::string &id, float opacity, float durationMs, const std::string &ease,
1635 float delayMs) {
1636 if (!resolveSelected()) return;
1637 // Script-facing facade: missing hosts/nodes are no-ops (same as other UI setters).
1638 tweens_.animateItemOpacity(selected_, id, opacity, durationMs, ease, delayMs, uiTweenWallClockMs())
1639 .ignore("UI.animateItemOpacity: host/node unavailable");
1640}
1641
1642void UI::animateItemValue(const std::string &id, float value, float durationMs, const std::string &ease,
1643 float delayMs) {
1644 if (!std::isfinite(value) || !std::isfinite(durationMs) || !std::isfinite(delayMs))
1645 throw std::invalid_argument("HUD value tween inputs must be finite");
1646 if (!resolveSelected()) return;
1647 // Script-facing facade: missing hosts/nodes are no-ops (same as other UI setters).
1648 tweens_.animateItemValue(selected_, id, value, durationMs, ease, delayMs, uiTweenWallClockMs())
1649 .ignore("UI.animateItemValue: host/node unavailable");
1650}
1651
1652void UI::animateItemPos(const std::string &id, float x, float y, float durationMs, const std::string &ease,
1653 float delayMs) {
1654 if (!resolveSelected()) return;
1655 tweens_.animateItemPos(selected_, id, x, y, durationMs, ease, delayMs, uiTweenWallClockMs())
1656 .ignore("UI.animateItemPos: host/node unavailable");
1657}
1658
1660 if (!resolveSelected()) return;
1661 tweens_.cancelHost(selected_);
1662}
1663
1664void UI::cancelItemTweens(const std::string &id) {
1665 if (!resolveSelected()) return;
1666 tweens_.cancelItem(selected_, id);
1667}
1668
1670 if (!resolveSelected()) return;
1671 tweens_.cancelAll(selected_);
1672}
1673
1674std::string UI::setStyleClassColor(const std::string &name, const std::string &property, float r,
1675 float g, float b, float a) {
1677}
1678
1679std::string UI::setStyleClassMetric(const std::string &name, const std::string &property, float x,
1680 float y) {
1682}
1683
1685
1689
1693
1694void UI::setScale(float scale) {
1695 if (!isBackendReady()) {
1696 if (!initBackend()) return;
1697 }
1698 if (backend_) backend_->setScale(scale);
1700}
1701
1702float UI::getScale() const {
1703 return backend_ ? backend_->getScale() : 1.f;
1704}
1705
1706std::string UI::getStats() const {
1707 const UIStats &s = UISystem::stats();
1708 char buf[160];
1709 std::snprintf(buf, sizeof(buf), "hosts=%d nodes=%d measureMs=%.3f walkMs=%.3f", s.hostCount,
1710 s.nodeCount, s.measureMs, s.walkMs);
1711 return buf;
1712}
1713
1714std::string UI::getLayoutDiagnostics() const {
1715 auto host = resolveSelected();
1716 if (!host) return "{\"nodes\":[]}";
1717 std::ostringstream out;
1718 out << "{\"host\":" << jsonQuoted(host->get().getName()) << ",\"nodes\":[";
1719 bool first = true;
1720 for (const UINode &node : host->get().tree()->nodes) {
1721 if (!first) out << ',';
1722 first = false;
1723 out << "{\"id\":" << jsonQuoted(node.id) << ",\"width\":" << node.measuredW
1724 << ",\"height\":" << node.measuredH << ",\"overflowX\":"
1725 << node.layoutOverflowX << ",\"overflowY\":" << node.layoutOverflowY << '}';
1726 }
1727 out << "]}";
1728 return out.str();
1729}
1730
1731std::string UI::getAccessibilitySnapshot() const {
1732 auto host = resolveSelected();
1733 if (!host) return "{\"nodes\":[]}";
1734 std::ostringstream out;
1735 out << "{\"host\":" << jsonQuoted(host->get().getName()) << ",\"nodes\":[";
1736 bool first = true;
1737 for (const UINode &node : host->get().tree()->nodes) {
1738 if (node.accessibilityRole == AccessibilityRole::Auto &&
1739 node.accessibilityName.empty())
1740 continue;
1741 if (!first) out << ',';
1742 first = false;
1743 out << "{\"id\":" << jsonQuoted(node.id) << ",\"role\":"
1744 << static_cast<int>(node.accessibilityRole) << ",\"name\":"
1745 << jsonQuoted(node.accessibilityName) << ",\"description\":"
1746 << jsonQuoted(node.accessibilityDescription) << ",\"enabled\":"
1747 << (node.enabled ? "true" : "false") << ",\"focused\":"
1748 << (node.focused ? "true" : "false") << '}';
1749 }
1750 out << "]}";
1751 return out.str();
1752}
1753
1754#if !(defined(EVENGINE_WEBGPU) && defined(__EMSCRIPTEN__))
1755std::string UI::saveTreeJson() const {
1756 auto host = resolveSelected();
1757 if (!host) return "{}";
1758 auto t = host->get().tree();
1759 Poco::JSON::Object root;
1760 root.set("schema", "eve.ui.tree");
1761 root.set("version", 5);
1762 root.set("host", host->get().getName());
1763 if (t->root >= 0) nodeToJson(*t, t->nodes[size_t(t->root)], root);
1764 std::ostringstream oss;
1765 Poco::JSON::Stringifier::stringify(root, oss, 1);
1766 return oss.str();
1767}
1768
1769bool UI::loadTreeJson(const std::string &json) {
1770 auto host = resolveSelected();
1771 if (!host || json.empty()) return false;
1772 try {
1773 Poco::JSON::Parser parser;
1774 const Poco::Dynamic::Var result = parser.parse(json);
1775 const Poco::JSON::Object::Ptr obj = result.extract<Poco::JSON::Object::Ptr>();
1776 if (!obj) return false;
1777 if (obj->has("schema") && obj->getValue<std::string>("schema") != "eve.ui.tree")
1778 return false;
1779 const int version = obj->optValue<int>("version", 1);
1780 if (version < 1 || version > 5) return false;
1781 WidgetDesc root = descFromJson(*obj);
1782 host->get().setTree(std::move(root));
1783 return true;
1784 } catch (...) {
1785 return false;
1786 }
1787}
1788#else
1789// WebGPU trims Poco. Use EVCommon's owning Value/JSON path so UI assets retain
1790// their portable core rather than degrading to a silent no-op.
1791std::string UI::saveTreeJson() const {
1792 auto host = resolveSelected();
1793 if (!host) return "{}";
1794 static const char *types[] = {"window",
1795 "text",
1796 "button",
1797 "sameLine",
1798 "group",
1799 "separator",
1800 "checkbox",
1801 "slider",
1802 "progress",
1803 "inputText",
1804 "collapsingHeader",
1805 "child",
1806 "flex",
1807 "spacer",
1808 "image",
1809 "imageButton",
1810 "combo",
1811 "scrollList",
1812 "viewport",
1813 "searchField",
1814 "switch",
1815 "badge",
1816 "card",
1817 "sectionHeader",
1818 "menuBar",
1819 "menu",
1820 "menuItem",
1821 "toolbar",
1822 "toolbox",
1823 "sidebar",
1824 "statusBar",
1825 "splitPane",
1826 "ninePatchPanel",
1827 "colorPalette",
1828 "grid",
1829 "tab",
1830 "tabBar",
1831 "tabContainer",
1832 "panelFrame",
1833 "dockArea",
1834 "appFrame",
1835 "link",
1836 "filled-image",
1837 "radial-fill"};
1838 const auto tree = host->get().tree();
1839 std::function<eve::Value(int)> encode = [&](int index) -> eve::Value {
1840 const UINode &n = tree->nodes[size_t(index)];
1842 const int typeIndex = static_cast<int>(n.type);
1843 node.set("type", typeIndex >= 0 && typeIndex < int(std::size(types)) ? types[typeIndex] : "text");
1844 if (!n.id.empty()) node.set("id", n.id);
1845 if (!n.key.empty()) node.set("key", n.key);
1846 if (!n.text.empty()) node.set("text", n.text);
1847 if (!n.valueText.empty()) node.set("valueText", n.valueText);
1848 if (!n.tooltip.empty()) node.set("tooltip", n.tooltip);
1849 if (n.readOnly) node.set("readOnly", n.readOnly);
1850 if (n.multiline) node.set("multiline", n.multiline);
1851 if (!n.placeholder.empty()) node.set("placeholder", n.placeholder);
1852 if (!n.disabledReason.empty()) node.set("disabledReason", n.disabledReason);
1853 if (!n.helpText.empty()) node.set("helpText", n.helpText);
1854 if (!n.styleClass.empty()) node.set("styleClass", n.styleClass);
1855 node.set("visible", n.visible);
1856 node.set("enabled", n.enabled);
1857 node.set("checked", n.checked);
1858 node.set("value", n.value);
1859 node.set("minValue", n.minValue);
1860 node.set("maxValue", n.maxValue);
1861 node.set("sizeX", n.sizeX);
1862 node.set("sizeY", n.sizeY);
1863 node.set("absolute", n.absolute);
1864 node.set("anchorX", n.anchorX);
1865 node.set("anchorY", n.anchorY);
1866 node.set("posX", n.posX);
1867 node.set("posY", n.posY);
1868 node.set("fillDirection", int(n.fillDirection));
1869 node.set("fillStretch", n.fillStretch);
1870 node.set("fillClockwise", n.fillClockwise);
1871 node.set("fillStartDegrees", n.fillStartDegrees);
1872 node.set("fillInnerRadius", n.fillInnerRadius);
1873 node.set("fontSize", n.fontSize);
1874 node.set("textColor", eve::Value::array({n.textR, n.textG, n.textB, n.textA}));
1875 node.set("textAlignX", n.textAlignX);
1876 node.set("textAlignY", n.textAlignY);
1877 node.set("tint", eve::Value::array({n.tintR, n.tintG, n.tintB, n.tintA}));
1878 node.set("uv", eve::Value::array({n.uv0x, n.uv0y, n.uv1x, n.uv1y}));
1879 node.set("mouseFilter", n.mouseFilter == MouseFilter::Ignore
1880 ? "ignore"
1881 : (n.mouseFilter == MouseFilter::Pass ? "pass" : "stop"));
1882 node.set("focusMode",
1883 n.focusMode == FocusMode::None ? "none" : (n.focusMode == FocusMode::Click ? "click" : "all"));
1884 node.set("flexDirection", n.flexDirection == FlexDirection::Column ? "column" : "row");
1885 node.set("alignItems", int(n.alignItems));
1886 node.set("justifyContent", int(n.justifyContent));
1887 node.set("gap", n.gap);
1888 node.set("columnGap", n.columnGap);
1889 node.set("rowGap", n.rowGap);
1890 node.set("flexGrow", n.flexGrow);
1891 node.set("flexShrink", n.flexShrink);
1892 node.set("flexBasis", n.flexBasis);
1893 node.set("alignSelf", n.alignSelf);
1894 node.set("aspectRatio", n.aspectRatio);
1895 node.set("flexWrap", n.flexWrap == FlexWrap::Wrap ? "wrap" : "nowrap");
1896 node.set("overflow", int(n.overflow));
1897 node.set("gridColumns", n.gridColumns);
1898 node.set("gridColumnSpan", n.gridColumnSpan);
1899 node.set("accessibilityRole", int(n.accessibilityRole));
1900 node.set("accessibilityName", n.accessibilityName);
1901 node.set("accessibilityDescription", n.accessibilityDescription);
1903 for (int child = n.firstChild; child >= 0;
1904 child = tree->nodes[size_t(child)].nextSibling)
1906 node.set("children", std::move(children));
1907 return node;
1908 };
1909 eve::Value root = tree->root >= 0 ? encode(tree->root) : eve::Value::object({});
1910 root.set("schema", "eve.ui.tree");
1911 root.set("version", 5);
1912 root.set("host", host->get().getName());
1913 auto encoded = eve::json::stringify(root);
1914 return encoded.ok() ? std::move(encoded).takeValue() : "{}";
1915}
1916
1917bool UI::loadTreeJson(const std::string &text) {
1918 auto host = resolveSelected();
1919 if (!host || text.empty()) return false;
1920 std::string error;
1922 const eve::json::Value root = document.root();
1923 if (!document.valid() || !root.isObject()) return false;
1924 if (root.has("schema") && root.getString("schema") != "eve.ui.tree") return false;
1925 const int version = root.getInt("version", 1);
1926 if (version < 1 || version > 5) return false;
1927 static const char *types[] = {"window",
1928 "text",
1929 "button",
1930 "sameLine",
1931 "group",
1932 "separator",
1933 "checkbox",
1934 "slider",
1935 "progress",
1936 "inputText",
1937 "collapsingHeader",
1938 "child",
1939 "flex",
1940 "spacer",
1941 "image",
1942 "imageButton",
1943 "combo",
1944 "scrollList",
1945 "viewport",
1946 "searchField",
1947 "switch",
1948 "badge",
1949 "card",
1950 "sectionHeader",
1951 "menuBar",
1952 "menu",
1953 "menuItem",
1954 "toolbar",
1955 "toolbox",
1956 "sidebar",
1957 "statusBar",
1958 "splitPane",
1959 "ninePatchPanel",
1960 "colorPalette",
1961 "grid",
1962 "tab",
1963 "tabBar",
1964 "tabContainer",
1965 "panelFrame",
1966 "dockArea",
1967 "appFrame",
1968 "link",
1969 "filled-image",
1970 "radial-fill"};
1971 bool valid = true;
1972 std::function<WidgetDesc(eve::json::Value)> decode = [&](eve::json::Value value) {
1973 WidgetDesc node;
1974 const std::string type = value.getString("type", "text");
1975 for (int i = 0; i < int(std::size(types)); ++i)
1976 if (type == types[i]) node.type = static_cast<NodeType>(i);
1977 node.id = value.getString("id");
1978 node.key = value.getString("key");
1979 node.text = value.getString("text");
1980 node.valueText = value.getString("valueText");
1981 node.tooltip = value.getString("tooltip");
1982 node.readOnly = value.getBool("readOnly", false);
1983 node.multiline = value.getBool("multiline", false);
1984 node.placeholder = value.getString("placeholder");
1985 node.disabledReason = value.getString("disabledReason");
1986 node.helpText = value.getString("helpText");
1987 node.styleClass = value.getString("styleClass");
1988 node.visible = value.getBool("visible", true);
1989 node.enabled = value.getBool("enabled", true);
1990 node.checked = value.getBool("checked", false);
1991 node.value = value.getFloat("value");
1992 node.minValue = value.getFloat("minValue");
1993 node.maxValue = value.getFloat("maxValue", 1.f);
1994 node.sizeX = value.getFloat("sizeX");
1995 node.sizeY = value.getFloat("sizeY");
1996 node.absolute = value.getBool("absolute");
1997 node.anchorX = value.getFloat("anchorX");
1998 node.anchorY = value.getFloat("anchorY");
1999 node.posX = value.getFloat("posX");
2000 node.posY = value.getFloat("posY");
2001 const int direction = value.getInt("fillDirection");
2002 if (direction < 0 || direction > 3) valid = false;
2003 node.fillDirection = FillDirection(direction);
2004 node.fillStretch = value.getBool("fillStretch");
2005 node.fillClockwise = value.getBool("fillClockwise", true);
2006 node.fillStartDegrees = value.getFloat("fillStartDegrees", -90.f);
2007 node.fillInnerRadius = value.getFloat("fillInnerRadius");
2008 node.fontSize = value.getFloat("fontSize");
2009 node.textAlignX = value.getFloat("textAlignX");
2010 node.textAlignY = value.getFloat("textAlignY");
2011 const auto textColor = value.get("textColor");
2012 if (textColor.size() >= 4) {
2013 node.textR = textColor.at(0).asFloat(1.f);
2014 node.textG = textColor.at(1).asFloat(1.f);
2015 node.textB = textColor.at(2).asFloat(1.f);
2016 node.textA = textColor.at(3).asFloat(1.f);
2017 }
2018 const auto tint = value.get("tint");
2019 if (tint.size() >= 4) {
2020 node.tintR = tint.at(0).asFloat(1.f);
2021 node.tintG = tint.at(1).asFloat(1.f);
2022 node.tintB = tint.at(2).asFloat(1.f);
2023 node.tintA = tint.at(3).asFloat(1.f);
2024 }
2025 const auto uv = value.get("uv");
2026 if (uv.size() >= 4) {
2027 node.uv0x = uv.at(0).asFloat();
2028 node.uv0y = uv.at(1).asFloat();
2029 node.uv1x = uv.at(2).asFloat(1.f);
2030 node.uv1y = uv.at(3).asFloat(1.f);
2031 }
2032 const auto filter = value.getString("mouseFilter", "stop");
2033 node.mouseFilter =
2035 const auto focus = value.getString("focusMode", "all");
2036 node.focusMode = focus == "none" ? FocusMode::None : (focus == "click" ? FocusMode::Click : FocusMode::All);
2037 node.flexDirection = value.getString("flexDirection") == "column" ? FlexDirection::Column : FlexDirection::Row;
2038 node.alignItems = static_cast<FlexAlign>(value.getInt("alignItems"));
2039 node.justifyContent = static_cast<FlexJustify>(value.getInt("justifyContent"));
2040 node.gap = value.getFloat("gap", -1.f);
2041 node.columnGap = value.getFloat("columnGap", -1.f);
2042 node.rowGap = value.getFloat("rowGap", -1.f);
2043 node.flexGrow = value.getFloat("flexGrow");
2044 node.flexShrink = value.getFloat("flexShrink", 1.f);
2045 node.flexBasis = value.getFloat("flexBasis", -1.f);
2046 node.alignSelf = value.getInt("alignSelf", -1);
2047 node.aspectRatio = value.getFloat("aspectRatio");
2048 node.flexWrap = value.getString("flexWrap") == "wrap" ? FlexWrap::Wrap : FlexWrap::NoWrap;
2049 node.overflow = static_cast<OverflowMode>(value.getInt("overflow"));
2050 node.gridColumns = std::max(1, value.getInt("gridColumns", 1));
2051 node.gridColumnSpan = std::max(1, value.getInt("gridColumnSpan", 1));
2052 node.accessibilityRole = static_cast<AccessibilityRole>(value.getInt("accessibilityRole"));
2053 node.accessibilityName = value.getString("accessibilityName");
2054 if (node.type == NodeType::Link) node.accessibilityRole = AccessibilityRole::Link;
2055 node.accessibilityDescription = value.getString("accessibilityDescription");
2056 if (!validHudFields(node)) valid = false;
2057 const eve::json::Value children = value.get("children");
2058 for (size_t i = 0; i < children.size(); ++i)
2059 if (children.at(i).isObject()) node.children.push_back(decode(children.at(i)));
2060 return node;
2061 };
2062 auto description = decode(root);
2063 if (!valid) return false;
2064 host->get().setTree(std::move(description));
2065 return true;
2066}
2067#endif
2068
2069graphics::Canvas *UI::viewportCanvas(const std::string &id) {
2070 auto host = resolveSelected();
2071 if (!host || id.empty()) return nullptr;
2072 const std::string key = host->get().getName() + "/" + id;
2073 if (auto state = UISystem::viewportState(host->get().getName(), id)) return state->get().canvas;
2074 auto ensured = UISystem::ensureViewport(key, 320, 240);
2075 if (!ensured.ok()) return nullptr;
2076 return std::move(ensured).takeValue().get().canvas;
2077}
2078
2079bool UI::viewportHovered(const std::string &id) {
2080 auto host = resolveSelected();
2081 if (!host) return false;
2082 if (auto state = UISystem::viewportState(host->get().getName(), id)) return state->get().hovered;
2083 return false;
2084}
2085
2086bool UI::viewportActive(const std::string &id) {
2087 auto host = resolveSelected();
2088 if (!host) return false;
2089 if (auto state = UISystem::viewportState(host->get().getName(), id)) return state->get().active;
2090 return false;
2091}
2092
2093float UI::viewportMouseX(const std::string &id) {
2094 auto host = resolveSelected();
2095 if (!host) return 0.f;
2096 if (auto state = UISystem::viewportState(host->get().getName(), id)) return state->get().mouseX;
2097 return 0.f;
2098}
2099
2100float UI::viewportMouseY(const std::string &id) {
2101 auto host = resolveSelected();
2102 if (!host) return 0.f;
2103 if (auto state = UISystem::viewportState(host->get().getName(), id)) return state->get().mouseY;
2104 return 0.f;
2105}
2106
2107float UI::viewportDragDX(const std::string &id) {
2108 auto host = resolveSelected();
2109 if (!host) return 0.f;
2110 if (auto state = UISystem::viewportState(host->get().getName(), id)) return state->get().dragDX;
2111 return 0.f;
2112}
2113
2114float UI::viewportDragDY(const std::string &id) {
2115 auto host = resolveSelected();
2116 if (!host) return 0.f;
2117 if (auto state = UISystem::viewportState(host->get().getName(), id)) return state->get().dragDY;
2118 return 0.f;
2119}
2120
2121float UI::viewportWheel(const std::string &id) {
2122 auto host = resolveSelected();
2123 if (!host) return 0.f;
2124 if (auto state = UISystem::viewportState(host->get().getName(), id)) return state->get().wheel;
2125 return 0.f;
2126}
2127
2128#if !(defined(EVENGINE_WEBGPU) && defined(__EMSCRIPTEN__))
2129namespace {
2130
2131const char *nodeTypeName(NodeType t) {
2132 switch (t) {
2133 case NodeType::Link: return "link";
2134 case NodeType::Window: return "window";
2135 case NodeType::Text: return "text";
2136 case NodeType::Button: return "button";
2137 case NodeType::SameLine: return "sameLine";
2138 case NodeType::Group: return "group";
2139 case NodeType::Separator: return "separator";
2140 case NodeType::Checkbox: return "checkbox";
2141 case NodeType::Slider: return "slider";
2142 case NodeType::FilledImage: return "filled-image";
2143 case NodeType::RadialFill: return "radial-fill";
2144 case NodeType::Progress: return "progress";
2145 case NodeType::InputText: return "inputText";
2146 case NodeType::CollapsingHeader: return "collapsingHeader";
2147 case NodeType::Child: return "child";
2148 case NodeType::Flex: return "flex";
2149 case NodeType::Spacer: return "spacer";
2150 case NodeType::Image: return "image";
2151 case NodeType::ImageButton: return "imageButton";
2152 case NodeType::Combo: return "combo";
2153 case NodeType::ScrollList: return "scrollList";
2154 case NodeType::Viewport: return "viewport";
2155 case NodeType::SearchField: return "searchField";
2156 case NodeType::Switch: return "switch";
2157 case NodeType::Badge: return "badge";
2158 case NodeType::Card: return "card";
2159 case NodeType::NinePatchPanel: return "ninePatchPanel";
2160 case NodeType::ColorPalette: return "colorPalette";
2161 case NodeType::Grid: return "grid";
2162 case NodeType::SectionHeader: return "sectionHeader";
2163 case NodeType::MenuBar: return "menuBar";
2164 case NodeType::Menu: return "menu";
2165 case NodeType::MenuItem: return "menuItem";
2166 case NodeType::Toolbar: return "toolbar";
2167 case NodeType::Toolbox: return "toolbox";
2168 case NodeType::Sidebar: return "sidebar";
2169 case NodeType::StatusBar: return "statusBar";
2170 case NodeType::SplitPane: return "splitPane";
2171 case NodeType::Tab: return "tab";
2172 case NodeType::TabBar: return "tabBar";
2173 case NodeType::TabContainer: return "tabContainer";
2174 case NodeType::PanelFrame: return "panelFrame";
2175 case NodeType::DockArea: return "dockArea";
2176 case NodeType::AppFrame: return "appFrame";
2177 }
2178 return "text";
2179}
2180
2181NodeType nodeTypeFromName(const std::string &s) {
2182 if (s == "window") return NodeType::Window;
2183 if (s == "button") return NodeType::Button;
2184 if (s == "sameLine") return NodeType::SameLine;
2185 if (s == "group") return NodeType::Group;
2186 if (s == "separator") return NodeType::Separator;
2187 if (s == "checkbox") return NodeType::Checkbox;
2188 if (s == "slider") return NodeType::Slider;
2189 if (s == "filled-image") return NodeType::FilledImage;
2190 if (s == "radial-fill") return NodeType::RadialFill;
2191 if (s == "progress") return NodeType::Progress;
2192 if (s == "link") return NodeType::Link;
2193 if (s == "inputText") return NodeType::InputText;
2194 if (s == "collapsingHeader") return NodeType::CollapsingHeader;
2195 if (s == "child") return NodeType::Child;
2196 if (s == "flex") return NodeType::Flex;
2197 if (s == "spacer") return NodeType::Spacer;
2198 if (s == "image") return NodeType::Image;
2199 if (s == "imageButton") return NodeType::ImageButton;
2200 if (s == "combo") return NodeType::Combo;
2201 if (s == "scrollList") return NodeType::ScrollList;
2202 if (s == "viewport") return NodeType::Viewport;
2203 if (s == "searchField") return NodeType::SearchField;
2204 if (s == "switch") return NodeType::Switch;
2205 if (s == "badge") return NodeType::Badge;
2206 if (s == "card") return NodeType::Card;
2207 if (s == "ninePatchPanel") return NodeType::NinePatchPanel;
2208 if (s == "colorPalette" || s == "color-palette" || s == "color") return NodeType::ColorPalette;
2209 if (s == "grid") return NodeType::Grid;
2210 if (s == "sectionHeader") return NodeType::SectionHeader;
2211 if (s == "menuBar") return NodeType::MenuBar;
2212 if (s == "menu") return NodeType::Menu;
2213 if (s == "menuItem") return NodeType::MenuItem;
2214 if (s == "toolbar") return NodeType::Toolbar;
2215 if (s == "toolbox") return NodeType::Toolbox;
2216 if (s == "sidebar") return NodeType::Sidebar;
2217 if (s == "statusBar") return NodeType::StatusBar;
2218 if (s == "splitPane") return NodeType::SplitPane;
2219 if (s == "tab") return NodeType::Tab;
2220 if (s == "tabBar") return NodeType::TabBar;
2221 if (s == "tabContainer") return NodeType::TabContainer;
2222 if (s == "panelFrame") return NodeType::PanelFrame;
2223 if (s == "dockArea") return NodeType::DockArea;
2224 if (s == "appFrame") return NodeType::AppFrame;
2225 return NodeType::Text;
2226}
2227
2228void nodeToJson(const UIHost::Tree &tree, const UINode &n, Poco::JSON::Object &o) {
2229 o.set("type", nodeTypeName(n.type));
2230 if (!n.id.empty()) o.set("id", n.id);
2231 if (!n.key.empty()) o.set("key", n.key);
2232 if (!n.text.empty()) o.set("text", n.text);
2233 if (!n.valueText.empty()) o.set("valueText", n.valueText);
2234 if (!n.tooltip.empty()) o.set("tooltip", n.tooltip);
2235 if (n.readOnly) o.set("readOnly", n.readOnly);
2236 if (n.multiline) o.set("multiline", n.multiline);
2237 if (!n.placeholder.empty()) o.set("placeholder", n.placeholder);
2238 if (!n.disabledReason.empty()) o.set("disabledReason", n.disabledReason);
2239 if (!n.helpText.empty()) o.set("helpText", n.helpText);
2240 if (!n.visible) o.set("visible", false);
2241 if (!n.enabled) o.set("enabled", false);
2242 if (n.focusMode != FocusMode::All)
2243 o.set("focusMode", n.focusMode == FocusMode::None ? "none" : "click");
2244 if (n.mouseFilter != MouseFilter::Stop)
2245 o.set("mouseFilter", n.mouseFilter == MouseFilter::Pass ? "pass" : "ignore");
2246 if (n.themePreset != ThemePreset::Inherit)
2247 o.set("theme", n.themePreset == ThemePreset::Dark ? "dark" : "light");
2248 if (!n.styleClass.empty()) o.set("styleClass", n.styleClass);
2249 if (n.tabIndex != 0) o.set("tabIndex", n.tabIndex);
2250 if (!n.focusPrevious.empty()) o.set("focusPrevious", n.focusPrevious);
2251 if (!n.focusNext.empty()) o.set("focusNext", n.focusNext);
2252 if (!n.focusLeft.empty()) o.set("focusLeft", n.focusLeft);
2253 if (!n.focusRight.empty()) o.set("focusRight", n.focusRight);
2254 if (!n.focusUp.empty()) o.set("focusUp", n.focusUp);
2255 if (!n.focusDown.empty()) o.set("focusDown", n.focusDown);
2256 if (n.accessibilityRole != AccessibilityRole::Auto) {
2257 const char *role = "auto";
2258 switch (n.accessibilityRole) {
2259 case AccessibilityRole::Button: role = "button"; break;
2260 case AccessibilityRole::Checkbox: role = "checkbox"; break;
2261 case AccessibilityRole::Slider: role = "slider"; break;
2262 case AccessibilityRole::Text: role = "text"; break;
2263 case AccessibilityRole::Link: role = "link"; break;
2264 case AccessibilityRole::TextInput: role = "text-input"; break;
2265 case AccessibilityRole::List: role = "list"; break;
2266 case AccessibilityRole::ListItem: role = "list-item"; break;
2267 case AccessibilityRole::Menu: role = "menu"; break;
2268 case AccessibilityRole::MenuItem: role = "menu-item"; break;
2269 case AccessibilityRole::Progress: role = "progress"; break;
2270 case AccessibilityRole::Region: role = "region"; break;
2271 case AccessibilityRole::Tab: role = "tab"; break;
2272 case AccessibilityRole::Window: role = "window"; break;
2273 case AccessibilityRole::Auto: break;
2274 }
2275 o.set("accessibilityRole", role);
2276 }
2277 if (!n.accessibilityName.empty()) o.set("accessibilityName", n.accessibilityName);
2278 if (!n.accessibilityDescription.empty())
2279 o.set("accessibilityDescription", n.accessibilityDescription);
2280 if (n.dragSource) {
2281 o.set("dragSource", true);
2282 o.set("dragPayloadType", n.dragPayloadType);
2283 o.set("dragPayloadText", n.dragPayloadText);
2284 }
2285 if (n.dropTarget) {
2286 o.set("dropTarget", true);
2287 o.set("acceptedDropType", n.acceptedDropType);
2288 }
2289 if (n.checked) o.set("checked", true);
2290 if (!n.open) o.set("open", false);
2291 if (n.value != 0.f) o.set("value", n.value);
2292 if (n.minValue != 0.f) o.set("minValue", n.minValue);
2293 if (n.maxValue != 1.f) o.set("maxValue", n.maxValue);
2294 if (n.sizeX != 0.f) o.set("sizeX", n.sizeX);
2295 if (n.sizeY != 0.f) o.set("sizeY", n.sizeY);
2296 if (n.marginL != 0.f || n.marginT != 0.f || n.marginR != 0.f || n.marginB != 0.f)
2297 o.set("margin", Poco::Dynamic::Array({n.marginL, n.marginT, n.marginR, n.marginB}));
2298 if (n.paddingL != 0.f || n.paddingT != 0.f || n.paddingR != 0.f || n.paddingB != 0.f)
2299 o.set("padding", Poco::Dynamic::Array({n.paddingL, n.paddingT, n.paddingR, n.paddingB}));
2300 if (n.minSizeX != 0.f) o.set("minSizeX", n.minSizeX);
2301 if (n.minSizeY != 0.f) o.set("minSizeY", n.minSizeY);
2302 if (n.maxSizeX != 0.f) o.set("maxSizeX", n.maxSizeX);
2303 if (n.maxSizeY != 0.f) o.set("maxSizeY", n.maxSizeY);
2304 if (n.percentW != 0.f) o.set("percentW", n.percentW);
2305 if (n.percentH != 0.f) o.set("percentH", n.percentH);
2306 if (n.aspectRatio > 0.f) o.set("aspectRatio", n.aspectRatio);
2307 if (n.absolute) {
2308 o.set("absolute", true);
2309 o.set("anchorX", n.anchorX);
2310 o.set("anchorY", n.anchorY);
2311 o.set("posX", n.posX);
2312 o.set("posY", n.posY);
2313 }
2314 if (n.wrapWidth != 0.f) o.set("wrapWidth", n.wrapWidth);
2315 if (n.flexDirection != FlexDirection::Row)
2316 o.set("flexDirection", n.flexDirection == FlexDirection::Column ? "column" : "row");
2317 if (n.alignItems != FlexAlign::Start) o.set("alignItems", int(n.alignItems));
2318 if (n.justifyContent != FlexJustify::Start) o.set("justifyContent", int(n.justifyContent));
2319 if (n.gap >= 0.f) o.set("gap", n.gap);
2320 if (n.flexGrow != 0.f) o.set("flexGrow", n.flexGrow);
2321 if (n.flexShrink != 1.f) o.set("flexShrink", n.flexShrink);
2322 if (n.flexBasis >= 0.f) o.set("flexBasis", n.flexBasis);
2323 if (n.alignSelf >= 0) o.set("alignSelf", n.alignSelf);
2324 if (n.columnGap >= 0.f) o.set("columnGap", n.columnGap);
2325 if (n.rowGap >= 0.f) o.set("rowGap", n.rowGap);
2326 if (n.flexWrap == FlexWrap::Wrap) o.set("flexWrap", "wrap");
2327 if (n.overflow != OverflowMode::Visible) o.set("overflow", int(n.overflow));
2328 if (n.type == NodeType::Grid) o.set("gridColumns", n.gridColumns);
2329 if (n.gridColumnSpan != 1) o.set("gridColumnSpan", n.gridColumnSpan);
2330 if (n.type == NodeType::ColorPalette || n.tintR != 1.f || n.tintG != 1.f || n.tintB != 1.f ||
2331 n.tintA != 1.f)
2332 o.set("tint", Poco::Dynamic::Array({n.tintR, n.tintG, n.tintB, n.tintA}));
2333 if (n.borderL != 0.f || n.borderT != 0.f || n.borderR != 0.f || n.borderB != 0.f)
2334 o.set("border", Poco::Dynamic::Array({n.borderL, n.borderT, n.borderR, n.borderB}));
2335 if (n.type == NodeType::FilledImage || n.type == NodeType::RadialFill) {
2336 o.set("fillDirection", int(n.fillDirection));
2337 o.set("fillStretch", n.fillStretch);
2338 o.set("fillStartDegrees", n.fillStartDegrees);
2339 o.set("fillClockwise", n.fillClockwise);
2340 o.set("fillInnerRadius", n.fillInnerRadius);
2341 }
2342 if (n.fontSize > 0.f) {
2343 o.set("fontSize", n.fontSize);
2344 o.set("textColor", Poco::Dynamic::Array({n.textR, n.textG, n.textB, n.textA}));
2345 o.set("textAlignX", n.textAlignX);
2346 o.set("textAlignY", n.textAlignY);
2347 }
2348 if (n.cornerRadius != 0.f) o.set("cornerRadius", n.cornerRadius);
2349 if (n.uv0x != 0.f || n.uv0y != 0.f || n.uv1x != 1.f || n.uv1y != 1.f)
2350 o.set("uv", Poco::Dynamic::Array({n.uv0x, n.uv0y, n.uv1x, n.uv1y}));
2351
2352 Poco::JSON::Array children;
2353 for (int c = n.firstChild; c >= 0; c = tree.nodes[size_t(c)].nextSibling) {
2354 Poco::JSON::Object child;
2355 nodeToJson(tree, tree.nodes[size_t(c)], child);
2356 children.add(child);
2357 }
2358 if (children.size() > 0) o.set("children", children);
2359}
2360
2361float fnum(const Poco::Dynamic::Var &v, float def = 0.f) {
2362 try {
2363 return float(v.convert<double>());
2364 } catch (...) {
2365 return def;
2366 }
2367}
2368
2369void applyCommonFields(WidgetDesc &d, const Poco::JSON::Object &o) {
2370 if (d.type == NodeType::Link) d.accessibilityRole = AccessibilityRole::Link;
2371 if (o.has("id")) d.id = o.getValue<std::string>("id");
2372 if (o.has("key")) d.key = o.getValue<std::string>("key");
2373 if (o.has("text")) d.text = o.getValue<std::string>("text");
2374 if (o.has("valueText")) d.valueText = o.getValue<std::string>("valueText");
2375 if (o.has("helpText")) d.helpText = o.getValue<std::string>("helpText");
2376 if (o.has("disabledReason")) d.disabledReason = o.getValue<std::string>("disabledReason");
2377 if (o.has("placeholder")) d.placeholder = o.getValue<std::string>("placeholder");
2378 if (o.has("multiline")) d.multiline = o.getValue<bool>("multiline");
2379 if (o.has("readOnly")) d.readOnly = o.getValue<bool>("readOnly");
2380 if (o.has("tooltip")) d.tooltip = o.getValue<std::string>("tooltip");
2381 if (o.has("visible")) d.visible = o.getValue<bool>("visible");
2382 if (o.has("enabled")) d.enabled = o.getValue<bool>("enabled");
2383 if (o.has("focusMode"))
2384 d.focusMode = parseFocusMode(o.getValue<std::string>("focusMode"));
2385 if (o.has("mouseFilter"))
2386 d.mouseFilter = parseMouseFilter(o.getValue<std::string>("mouseFilter"));
2387 if (o.has("theme"))
2388 d.themePreset = parseThemePreset(o.getValue<std::string>("theme"));
2389 if (o.has("styleClass")) d.styleClass = o.getValue<std::string>("styleClass");
2390 if (o.has("tabIndex")) d.tabIndex = int(fnum(o.get("tabIndex")));
2391 if (o.has("focusPrevious"))
2392 d.focusPrevious = o.getValue<std::string>("focusPrevious");
2393 if (o.has("focusNext")) d.focusNext = o.getValue<std::string>("focusNext");
2394 if (o.has("focusLeft")) d.focusLeft = o.getValue<std::string>("focusLeft");
2395 if (o.has("focusRight")) d.focusRight = o.getValue<std::string>("focusRight");
2396 if (o.has("focusUp")) d.focusUp = o.getValue<std::string>("focusUp");
2397 if (o.has("focusDown")) d.focusDown = o.getValue<std::string>("focusDown");
2398 if (o.has("accessibilityRole"))
2399 d.accessibilityRole =
2400 parseAccessibilityRole(o.getValue<std::string>("accessibilityRole"));
2401 if (o.has("accessibilityName"))
2402 d.accessibilityName = o.getValue<std::string>("accessibilityName");
2403 if (o.has("accessibilityDescription"))
2404 d.accessibilityDescription =
2405 o.getValue<std::string>("accessibilityDescription");
2406 if (o.has("dragSource")) d.dragSource = o.getValue<bool>("dragSource");
2407 if (o.has("dragPayloadType"))
2408 d.dragPayloadType = o.getValue<std::string>("dragPayloadType");
2409 if (o.has("dragPayloadText"))
2410 d.dragPayloadText = o.getValue<std::string>("dragPayloadText");
2411 if (o.has("dropTarget")) d.dropTarget = o.getValue<bool>("dropTarget");
2412 if (o.has("acceptedDropType"))
2413 d.acceptedDropType = o.getValue<std::string>("acceptedDropType");
2414 if (o.has("checked")) d.checked = o.getValue<bool>("checked");
2415 if (o.has("open")) d.open = o.getValue<bool>("open");
2416 if (o.has("value")) d.value = fnum(o.get("value"));
2417 if (o.has("minValue")) d.minValue = fnum(o.get("minValue"));
2418 if (o.has("maxValue")) d.maxValue = fnum(o.get("maxValue"));
2419 if (o.has("sizeX")) d.sizeX = fnum(o.get("sizeX"));
2420 if (o.has("sizeY")) d.sizeY = fnum(o.get("sizeY"));
2421 if (o.has("margin")) {
2422 const Poco::JSON::Array::Ptr a = o.getArray("margin");
2423 if (a && a->size() >= 4) {
2424 d.marginL = fnum(a->get(0));
2425 d.marginT = fnum(a->get(1));
2426 d.marginR = fnum(a->get(2));
2427 d.marginB = fnum(a->get(3));
2428 }
2429 }
2430 if (o.has("padding")) {
2431 const Poco::JSON::Array::Ptr a = o.getArray("padding");
2432 if (a && a->size() >= 4) {
2433 d.paddingL = fnum(a->get(0));
2434 d.paddingT = fnum(a->get(1));
2435 d.paddingR = fnum(a->get(2));
2436 d.paddingB = fnum(a->get(3));
2437 }
2438 }
2439 if (o.has("minSizeX")) d.minSizeX = fnum(o.get("minSizeX"));
2440 if (o.has("minSizeY")) d.minSizeY = fnum(o.get("minSizeY"));
2441 if (o.has("maxSizeX")) d.maxSizeX = fnum(o.get("maxSizeX"));
2442 if (o.has("maxSizeY")) d.maxSizeY = fnum(o.get("maxSizeY"));
2443 if (o.has("percentW")) d.percentW = fnum(o.get("percentW"));
2444 if (o.has("percentH")) d.percentH = fnum(o.get("percentH"));
2445 if (o.has("aspectRatio")) d.aspectRatio = fnum(o.get("aspectRatio"));
2446 if (o.has("absolute")) d.absolute = o.getValue<bool>("absolute");
2447 if (o.has("anchorX")) d.anchorX = fnum(o.get("anchorX"));
2448 if (o.has("anchorY")) d.anchorY = fnum(o.get("anchorY"));
2449 if (o.has("posX")) d.posX = fnum(o.get("posX"));
2450 if (o.has("posY")) d.posY = fnum(o.get("posY"));
2451 if (o.has("wrapWidth")) d.wrapWidth = fnum(o.get("wrapWidth"));
2452 if (o.has("flexDirection")) d.flexDirection =
2453 o.getValue<std::string>("flexDirection") == "column" ? FlexDirection::Column
2455 if (o.has("alignItems")) d.alignItems = FlexAlign(int(fnum(o.get("alignItems"))));
2456 if (o.has("justifyContent"))
2457 d.justifyContent = FlexJustify(int(fnum(o.get("justifyContent"))));
2458 if (o.has("gap")) d.gap = fnum(o.get("gap"), -1.f);
2459 if (o.has("flexGrow")) d.flexGrow = fnum(o.get("flexGrow"));
2460 if (o.has("flexShrink")) d.flexShrink = fnum(o.get("flexShrink"), 1.f);
2461 if (o.has("flexBasis")) d.flexBasis = fnum(o.get("flexBasis"), -1.f);
2462 if (o.has("alignSelf")) d.alignSelf = int(fnum(o.get("alignSelf"), -1.f));
2463 if (o.has("columnGap")) d.columnGap = fnum(o.get("columnGap"), -1.f);
2464 if (o.has("rowGap")) d.rowGap = fnum(o.get("rowGap"), -1.f);
2465 if (o.has("flexWrap"))
2466 d.flexWrap = o.getValue<std::string>("flexWrap") == "wrap" ? FlexWrap::Wrap
2468 if (o.has("overflow")) d.overflow = OverflowMode(int(fnum(o.get("overflow"))));
2469 if (o.has("gridColumns"))
2470 d.gridColumns = std::max(1, int(fnum(o.get("gridColumns"), 1.f)));
2471 if (o.has("gridColumnSpan"))
2472 d.gridColumnSpan = std::max(1, int(fnum(o.get("gridColumnSpan"), 1.f)));
2473 if (o.has("tint")) {
2474 const Poco::JSON::Array::Ptr a = o.getArray("tint");
2475 if (a && a->size() >= 4) {
2476 d.tintR = fnum(a->get(0), 1.f);
2477 d.tintG = fnum(a->get(1), 1.f);
2478 d.tintB = fnum(a->get(2), 1.f);
2479 d.tintA = fnum(a->get(3), 1.f);
2480 }
2481 }
2482 if (o.has("border")) {
2483 const Poco::JSON::Array::Ptr a = o.getArray("border");
2484 if (a && a->size() >= 4) {
2485 d.borderL = fnum(a->get(0));
2486 d.borderT = fnum(a->get(1));
2487 d.borderR = fnum(a->get(2));
2488 d.borderB = fnum(a->get(3));
2489 }
2490 }
2491 if (o.has("fillDirection")) {
2492 const int direction = int(fnum(o.get("fillDirection")));
2493 if (direction < 0 || direction > 3) throw std::invalid_argument("Invalid HUD fill direction");
2494 d.fillDirection = FillDirection(direction);
2495 }
2496 if (o.has("fillStretch")) d.fillStretch = o.getValue<bool>("fillStretch");
2497 if (o.has("fillStartDegrees")) d.fillStartDegrees = fnum(o.get("fillStartDegrees"), -90.f);
2498 if (o.has("fillClockwise")) d.fillClockwise = o.getValue<bool>("fillClockwise");
2499 if (o.has("fillInnerRadius")) d.fillInnerRadius = fnum(o.get("fillInnerRadius"));
2500 if (o.has("fontSize")) d.fontSize = fnum(o.get("fontSize"));
2501 if (o.has("textAlignX")) d.textAlignX = fnum(o.get("textAlignX"));
2502 if (o.has("textAlignY")) d.textAlignY = fnum(o.get("textAlignY"));
2503 if (o.has("textColor")) {
2504 const auto color = o.getArray("textColor");
2505 if (color && color->size() >= 4) {
2506 d.textR = fnum(color->get(0), 1.f);
2507 d.textG = fnum(color->get(1), 1.f);
2508 d.textB = fnum(color->get(2), 1.f);
2509 d.textA = fnum(color->get(3), 1.f);
2510 }
2511 }
2512 if (o.has("cornerRadius")) d.cornerRadius = fnum(o.get("cornerRadius"));
2513 if (o.has("uv")) {
2514 const Poco::JSON::Array::Ptr a = o.getArray("uv");
2515 if (a && a->size() >= 4) {
2516 d.uv0x = fnum(a->get(0));
2517 d.uv0y = fnum(a->get(1));
2518 d.uv1x = fnum(a->get(2), 1.f);
2519 d.uv1y = fnum(a->get(3), 1.f);
2520 }
2521 }
2522 if (!validHudFields(d)) throw std::invalid_argument("Invalid HUD fill or text style");
2523}
2524
2525WidgetDesc descFromJson(const Poco::JSON::Object &o) {
2526 WidgetDesc d;
2527 d.type = nodeTypeFromName(o.optValue<std::string>("type", "text"));
2528 applyCommonFields(d, o);
2529 if (o.has("children")) {
2530 const Poco::JSON::Array::Ptr children = o.getArray("children");
2531 for (size_t i = 0; i < children->size(); ++i) {
2532 const Poco::JSON::Object::Ptr child =
2533 children->getObject(static_cast<unsigned int>(i));
2534 if (child) d.children.push_back(descFromJson(*child));
2535 }
2536 }
2537 return d;
2538}
2539
2540} // namespace
2541#endif
2542
2543void UI::mountSimple(const std::string &title, const std::string &labelText,
2544 const std::string &buttonText) {
2545 const UIHostHandle handle =
2546 mountAs("default", window(title, {text(labelText, "label"), button(buttonText, "btn")}, "root"));
2547 if (!UIHost::resolve(handle)) return;
2548}
2549
2551 if (!inspector_) inspector_ = std::make_unique<Inspector>();
2552 inspector_->setPickScene([this]() { return callPickHandler(); });
2553 inspector_->open();
2554 return inspector_->isOpen();
2555}
2556
2558 if (inspector_) inspector_->close();
2559}
2560
2562 if (!inspector_) inspector_ = std::make_unique<Inspector>();
2563 inspector_->refresh();
2564 return inspector_->instanceCount() > 0;
2565}
2566
2567bool UI::inspectSelectClass(const std::string &name) {
2568 if (!inspector_) inspector_ = std::make_unique<Inspector>();
2569 inspector_->setPickScene([this]() { return callPickHandler(); });
2570 inspector_->open(); // scans classes and mounts the panel if not open yet
2571 return inspector_->selectClass(name);
2572}
2573
2574bool UI::inspectObject(ssq::Object object) {
2575 if (!inspector_) inspector_ = std::make_unique<Inspector>();
2576 inspector_->setPickScene([this]() { return callPickHandler(); });
2577 inspector_->open(); // scans classes and mounts the panel if not open yet
2578 return inspector_->inspectObject(object);
2579}
2580
2581bool UI::inspectSetPickHandler(ssq::Function fn) {
2583 if (!rt) return false;
2584 HSQUIRRELVM squirrel = rt->handle();
2585 const SQInteger top = sq_gettop(squirrel);
2586 sq_pushroottable(squirrel);
2587 sq_pushstring(squirrel, "eve", -1);
2588 if (SQ_FAILED(sq_get(squirrel, -2)) ||
2589 sq_gettype(squirrel, -1) != OT_TABLE) {
2590 sq_settop(squirrel, top);
2591 return false;
2592 }
2593 sq_pushstring(squirrel, "_inspectorPickHandler", -1);
2594 sq_pushobject(squirrel, fn.getRaw());
2595 sq_newslot(squirrel, -3, SQFalse);
2596 sq_settop(squirrel, top);
2597 return true;
2598}
2599
2600ssq::Object UI::callPickHandler() {
2602 if (!rt) return {};
2603 HSQUIRRELVM squirrel = rt->handle();
2604 const SQInteger top = sq_gettop(squirrel);
2605 sq_pushroottable(squirrel);
2606 sq_pushstring(squirrel, "eve", -1);
2607 if (SQ_FAILED(sq_get(squirrel, -2)) ||
2608 sq_gettype(squirrel, -1) != OT_TABLE) {
2609 sq_settop(squirrel, top);
2610 return {};
2611 }
2612 sq_pushstring(squirrel, "_inspectorPickHandler", -1);
2613 if (SQ_FAILED(sq_get(squirrel, -2)) ||
2614 (sq_gettype(squirrel, -1) != OT_CLOSURE &&
2615 sq_gettype(squirrel, -1) != OT_NATIVECLOSURE)) {
2616 sq_settop(squirrel, top);
2617 return {};
2618 }
2619 // The handler is the value we just looked up; call it with the root table as receiver
2620 // and keep its return value on top for the instance check below.
2621 HSQOBJECT handler;
2622 sq_getstackobj(squirrel, -1, &handler);
2623 if (SQ_FAILED(script::callFunctionResult(squirrel, handler, script::rootTable))) {
2624 sq_settop(squirrel, top);
2625 return {};
2626 }
2627 if (sq_gettype(squirrel, -1) != OT_INSTANCE) {
2628 sq_settop(squirrel, top);
2629 return {};
2630 }
2631 ssq::Object out(squirrel);
2632 sq_getstackobj(squirrel, -1, &out.getRaw());
2633 sq_addref(squirrel, &out.getRaw());
2634 sq_settop(squirrel, top);
2635 return out;
2636}
2637
2639 if (!inspector_) inspector_ = std::make_unique<Inspector>();
2640 inspector_->setPickScene([this]() { return callPickHandler(); });
2641 inspector_->open();
2642 const ssq::Object picked = callPickHandler();
2643 if (picked.getType() != ssq::Type::INSTANCE) return false;
2644 return inspector_->inspectObject(picked);
2645}
2646
2648 return inspector_ && inspector_->addInstance();
2649}
2650
2651namespace {
2652
2653const char *propertyKindName(property_access::PropertyKind kind) {
2655 switch (kind) {
2656 case PropertyKind::Auto: return "auto";
2657 case PropertyKind::Bool: return "bool";
2658 case PropertyKind::Integer: return "integer";
2659 case PropertyKind::Number: return "number";
2660 case PropertyKind::String: return "string";
2661 case PropertyKind::Enum: return "enum";
2662 case PropertyKind::Color: return "color";
2663 case PropertyKind::Vec2: return "vec2";
2664 case PropertyKind::Vec3: return "vec3";
2665 case PropertyKind::Vec4: return "vec4";
2666 case PropertyKind::AssetRef: return "assetRef";
2667 case PropertyKind::ObjectRef: return "objectRef";
2668 case PropertyKind::Struct: return "struct";
2669 case PropertyKind::Array: return "array";
2670 case PropertyKind::Map: return "map";
2671 case PropertyKind::Action: return "action";
2672 case PropertyKind::ReadOnlyText: return "readOnlyText";
2673 }
2674 return "auto";
2675}
2676
2677} // namespace
2678
2679ssq::Object UI::propertySchema(ssq::Object instance) {
2680 Runtime *runtime = ModuleManager::runtime();
2681 if (!runtime) return ssq::Object();
2682 if (instance.getType() != ssq::Type::INSTANCE) return ssq::Object(runtime->handle());
2684 ssq::VM &vm = runtime->vm();
2685 ssq::Table out = vm.newTable();
2686 out.set("typeId", model.schema().typeId);
2687 out.set("version", static_cast<int>(model.schema().version));
2688 ssq::Array properties = vm.newArray();
2689 for (const property_access::PropertyDescriptor &property : model.schema().properties) {
2690 ssq::Table entry = vm.newTable();
2691 entry.set("path", property.path);
2692 entry.set("kind", std::string(propertyKindName(property.kind)));
2693 entry.set("displayName", property.displayName);
2694 entry.set("description", property.description);
2695 entry.set("category", property.category);
2696 entry.set("readOnly", property_access::hasFlag(property.flags, property_access::PropertyFlag::ReadOnly));
2697 entry.set("presenterHint", property.presenterHint);
2698 entry.set("units", property.numeric.units);
2699 if (property.numeric.minimum) entry.set("min", *property.numeric.minimum);
2700 if (property.numeric.maximum) entry.set("max", *property.numeric.maximum);
2701 if (property.numeric.step) entry.set("step", *property.numeric.step);
2702 ssq::Array choices = vm.newArray();
2703 for (const std::string &choice : property.choices) choices.push(choice);
2704 entry.set("choices", choices);
2705 properties.push(entry);
2706 }
2707 out.set("properties", properties);
2708 return out;
2709}
2710
2712 if (!databasePanel_) databasePanel_ = std::make_unique<DatabasePanel>();
2713 databasePanel_->open();
2714 return databasePanel_->isOpen();
2715}
2716
2718 if (databasePanel_) databasePanel_->close();
2719}
2720
2722 if (!databasePanel_) databasePanel_ = std::make_unique<DatabasePanel>();
2723 databasePanel_->refresh();
2724 return databasePanel_->isOpen();
2725}
2726
2727bool UI::dbSelectClass(const std::string &name) {
2728 if (!databasePanel_) databasePanel_ = std::make_unique<DatabasePanel>();
2729 databasePanel_->refresh();
2730 return databasePanel_->selectClass(name);
2731}
2732
2733uint64_t UI::dbRegister(ssq::Object object, const std::string &label) {
2734 if (!databasePanel_) databasePanel_ = std::make_unique<DatabasePanel>();
2735 databasePanel_->open(); // mount the panel so the entry becomes visible
2736 auto result = databasePanel_->registerObject(object, label);
2737 if (!result) return 0;
2738 return result.value().packed();
2739}
2740
2742 if (!databasePanel_) databasePanel_ = std::make_unique<DatabasePanel>();
2743 databasePanel_->open();
2744 auto result = databasePanel_->createInstance();
2745 if (!result) return 0;
2746 return result.value().packed();
2747}
2748
2750 if (!databasePanel_)
2752 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "database panel is not open", {}, {}, "ui"));
2754 auto result = databasePanel_->unregister(handle);
2755 if (!result.ok()) return eve::Result<void>::failure(result.status());
2756 return eve::Result<void>::success(result.status());
2757}
2758
2760 if (!inspector_) inspector_ = std::make_unique<Inspector>();
2761 inspector_->setPickScene([this]() { return callPickHandler(); });
2762 inspector_->open();
2763 if (!databasePanel_) databasePanel_ = std::make_unique<DatabasePanel>();
2764 databasePanel_->open();
2765 if (!scenePanel_) scenePanel_ = std::make_unique<ScenePanel>();
2766 scenePanel_->setPickHandler([this](const std::string &nodeId) {
2767 callScenePickHandler(nodeId);
2768 });
2769 scenePanel_->open();
2770 if (!editorShell_) editorShell_ = std::make_unique<EditorShell>();
2771 editorShell_->open(inspector_->host(), databasePanel_->host(),
2772 scenePanel_->host());
2773 return editorShell_->isOpen();
2774}
2775
2777 if (editorShell_) editorShell_->close();
2778}
2779
2780bool UI::editorSelectPanel(const std::string &name) {
2781 return editorShell_ && editorShell_->selectPanel(name);
2782}
2783
2785 if (!scenePanel_) scenePanel_ = std::make_unique<ScenePanel>();
2786 scenePanel_->setPickHandler([this](const std::string &nodeId) {
2787 callScenePickHandler(nodeId);
2788 });
2789 scenePanel_->open();
2790 return scenePanel_->isOpen();
2791}
2792
2794 if (scenePanel_) scenePanel_->close();
2795}
2796
2797bool UI::sceneSelectNode(const std::string &id) {
2798 return scenePanel_ && scenePanel_->selectNode(id);
2799}
2800
2801bool UI::sceneSetPickHandler(ssq::Function fn) {
2803 if (!rt) return false;
2804 HSQUIRRELVM squirrel = rt->handle();
2805 const SQInteger top = sq_gettop(squirrel);
2806 sq_pushroottable(squirrel);
2807 sq_pushstring(squirrel, "eve", -1);
2808 if (SQ_FAILED(sq_get(squirrel, -2)) ||
2809 sq_gettype(squirrel, -1) != OT_TABLE) {
2810 sq_settop(squirrel, top);
2811 return false;
2812 }
2813 sq_pushstring(squirrel, "_scenePickHandler", -1);
2814 sq_pushobject(squirrel, fn.getRaw());
2815 sq_newslot(squirrel, -3, SQFalse);
2816 sq_settop(squirrel, top);
2817 return true;
2818}
2819
2820void UI::callScenePickHandler(const std::string &nodeId) {
2822 if (!rt) return;
2823 HSQUIRRELVM squirrel = rt->handle();
2824 const SQInteger top = sq_gettop(squirrel);
2825 sq_pushroottable(squirrel);
2826 sq_pushstring(squirrel, "eve", -1);
2827 if (SQ_FAILED(sq_get(squirrel, -2)) ||
2828 sq_gettype(squirrel, -1) != OT_TABLE) {
2829 sq_settop(squirrel, top);
2830 return;
2831 }
2832 sq_pushstring(squirrel, "_scenePickHandler", -1);
2833 if (SQ_FAILED(sq_get(squirrel, -2)) ||
2834 (sq_gettype(squirrel, -1) != OT_CLOSURE &&
2835 sq_gettype(squirrel, -1) != OT_NATIVECLOSURE)) {
2836 sq_settop(squirrel, top);
2837 return;
2838 }
2839 // Same shape as the inspector handler above: the looked-up closure, called with the
2840 // root table as receiver and the node id as its argument. A failed call used to be
2841 // discarded here too.
2842 HSQOBJECT handler;
2843 sq_getstackobj(squirrel, -1, &handler);
2845 sq_settop(squirrel, top);
2846}
2847
2848void UI::expose(ssq::Table &table) {
2849 auto cls = table.addClass(name, UI::create, false);
2850 expose(cls);
2866}
2867
2868void UI::expose(ssq::Class &cls) {
2869 cls.addFunc("getName", &UI::getName);
2870 cls.addFunc("initBackend", &UI::initBackend);
2871 cls.addFunc("isBackendReady", &UI::isBackendReady);
2872 cls.addFunc("beginFrameAndRender", &UI::beginFrameAndRender);
2873 cls.addFunc("dispatchEvents", &UI::dispatchEvents);
2874 cls.addFunc("wantCaptureMouse", &UI::wantCaptureMouse);
2875 cls.addFunc("wantCaptureKeyboard", &UI::wantCaptureKeyboard);
2876
2877 cls.addFunc("select", &UI::select);
2878 cls.addFunc("bindOwner", &UI::bindOwner);
2879 cls.addFunc("mountBuildAs", &UI::mountBuildAs);
2880 cls.addFunc("remountBuildAs", &UI::remountBuildAs);
2881
2882 cls.addFunc("beginBuild", &UI::beginBuild);
2883 cls.addFunc("beginWindow", &UI::beginWindow);
2884 cls.addFunc("beginGroup", &UI::beginGroup);
2885 cls.addFunc("beginList", &UI::beginList);
2886 cls.addFunc("beginCollapsing", &UI::beginCollapsing);
2887 cls.addFunc("beginChild", &UI::beginChild);
2888 cls.addFunc("beginCard", &UI::beginCard);
2889 cls.addFunc("beginNinePatch", &UI::beginNinePatch);
2890 cls.addFunc("beginMenuBar", &UI::beginMenuBar);
2891 cls.addFunc("beginMenu", &UI::beginMenu);
2892 cls.addFunc("beginToolbar", &UI::beginToolbar);
2893 cls.addFunc("beginToolbox", &UI::beginToolbox);
2894 cls.addFunc("beginSidebar", &UI::beginSidebar);
2895 cls.addFunc("beginStatusBar", &UI::beginStatusBar);
2896 cls.addFunc("beginSplitPane", &UI::beginSplitPane);
2897 cls.addFunc("beginTabBar", &UI::beginTabBar);
2898 cls.addFunc("beginTabContainer", &UI::beginTabContainer);
2899 cls.addFunc("beginPanelFrame", &UI::beginPanelFrame);
2900 cls.addFunc("beginDockArea", &UI::beginDockArea);
2901 cls.addFunc("beginAppFrame", &UI::beginAppFrame);
2902 cls.addFunc("addTab", &UI::addTab);
2903 cls.addFunc("beginScrollList", &UI::beginScrollList);
2904 cls.addFunc("beginFlex", &UI::beginFlex);
2905 cls.addFunc("beginRow", &UI::beginRow);
2906 cls.addFunc("beginColumn", &UI::beginColumn);
2907 cls.addFunc("beginGrid", &UI::beginGrid);
2908 cls.addFunc("end", &UI::end);
2909 cls.addFunc("text", &UI::addText);
2910 cls.addFunc("textWrapped", &UI::addTextWrapped);
2911 cls.addFunc("button", &UI::addButton);
2912 cls.addFunc("icon", &UI::addIcon);
2913 cls.addFunc("iconButton", &UI::addIconButton);
2914 cls.addFunc("sameLine", &UI::addSameLine);
2915 cls.addFunc("separator", &UI::addSeparator);
2916 cls.addFunc("checkbox", &UI::addCheckbox);
2917 cls.addFunc("slider", &UI::addSlider);
2918 cls.addFunc("colorPalette", &UI::addColorPalette);
2919 cls.addFunc("progress", &UI::addProgress);
2920 cls.addFunc("image", &UI::addImage);
2921 cls.addFunc("ninePatch", &UI::addNinePatch);
2922 cls.addFunc("imageButton", &UI::addImageButton);
2923 cls.addFunc("viewport", &UI::addViewport);
2924 cls.addFunc("combo", &UI::addCombo);
2925 cls.addFunc("link", &UI::addLink);
2926 cls.addFunc("setItemTextInput", &UI::setItemTextInput);
2927 cls.addFunc("setItemHelp", &UI::setItemHelp);
2928 cls.addFunc("inputText", &UI::addInputText);
2929 cls.addFunc("searchField", &UI::addSearchField);
2930 cls.addFunc("switch", &UI::addSwitch);
2931 cls.addFunc("badge", &UI::addBadge);
2932 cls.addFunc("sectionHeader", &UI::addSectionHeader);
2933 cls.addFunc("menuItem", &UI::addMenuItem);
2934 cls.addFunc("spacer", &UI::addSpacer);
2935 cls.addFunc("setItemFlexGrow", &UI::setItemFlexGrow);
2936 cls.addFunc("setItemFlexShrink", &UI::setItemFlexShrink);
2937 cls.addFunc("setItemFlexBasis", &UI::setItemFlexBasis);
2938 cls.addFunc("setItemAlignSelf", &UI::setItemAlignSelf);
2939 cls.addFunc("setItemAspectRatio", &UI::setItemAspectRatio);
2940 cls.addFunc("setItemGridColumnSpan", &UI::setItemGridColumnSpan);
2941 cls.addFunc("setItemSize", &UI::setItemSize);
2942 cls.addFunc("setItemMargin", &UI::setItemMargin);
2943 cls.addFunc("setItemPadding", &UI::setItemPadding);
2944 cls.addFunc("setItemMinSize", &UI::setItemMinSize);
2945 cls.addFunc("setItemMaxSize", &UI::setItemMaxSize);
2946 cls.addFunc("setItemPercent", &UI::setItemPercent);
2947 cls.addFunc("setItemAbsolute", &UI::setItemAbsolute);
2948 cls.addFunc("setItemTooltip", &UI::setItemTooltip);
2949 cls.addFunc("setItemDragSource", &UI::setItemDragSource);
2950 cls.addFunc("setItemDropTarget", &UI::setItemDropTarget);
2951 cls.addFunc("setItemEnabled", &UI::setItemEnabled);
2952 cls.addFunc("setItemSelected", &UI::setItemSelected);
2953 cls.addFunc("setItemFocusMode", &UI::setItemFocusMode);
2954 cls.addFunc("setItemMouseFilter", &UI::setItemMouseFilter);
2955 cls.addFunc("setItemTheme", &UI::setItemTheme);
2956 cls.addFunc("setThemeScope", &UI::setThemeScope);
2957 cls.addFunc("setItemStyleClass", &UI::setItemStyleClass);
2958 cls.addFunc("setStyleScope", &UI::setStyleScope);
2959 cls.addFunc("setItemTabIndex", &UI::setItemTabIndex);
2960 cls.addFunc("setItemFocusOrder", &UI::setItemFocusOrder);
2961 cls.addFunc("setItemFocusNeighbors", &UI::setItemFocusNeighbors);
2962 cls.addFunc("setItemAccessibility", &UI::setItemAccessibility);
2963 cls.addFunc("setFlexAlign", &UI::setFlexAlign);
2964 cls.addFunc("setFlexJustify", &UI::setFlexJustify);
2965 cls.addFunc("setLayoutGaps", &UI::setLayoutGaps);
2966 cls.addFunc("setFlexWrap", &UI::setFlexWrap);
2967 cls.addFunc("setLayoutOverflow", &UI::setLayoutOverflow);
2968 cls.addFunc("listItem", &UI::addListItem);
2969 cls.addFunc("mountBuild", &UI::mountBuild);
2970
2971 cls.addFunc("setText", &UI::setText);
2972 cls.addFunc("setTextWrap", &UI::setTextWrap);
2973 cls.addFunc("setVisible", &UI::setVisible);
2974 cls.addFunc("setEnabled", &UI::setEnabled);
2975 cls.addFunc("setChecked", &UI::setChecked);
2976 cls.addFunc("setValue", &UI::setValue);
2977 cls.addFunc("setValueText", &UI::setValueText);
2978 cls.addFunc("setColor", &UI::setColor);
2979 cls.addFunc("setImageTint", &UI::setImageTint);
2980 cls.addFunc("setImageUv", &UI::setImageUv);
2981 cls.addFunc("setImageNinePatch", &UI::setImageNinePatch);
2982 cls.addFunc("setImageNinePatchFile", &UI::setImageNinePatchFile);
2983 cls.addFunc("setImageCornerRadius", &UI::setImageCornerRadius);
2984 cls.addFunc("setImageTextureId", &UI::setImageTextureId);
2985 cls.addFunc("registerTexture", &UI::registerTexture);
2986 cls.addFunc("unregisterTexture", &UI::unregisterTexture);
2987 cls.addFunc("getValue", &UI::getValue);
2988 cls.addFunc("getValueText", &UI::getValueText);
2989 cls.addFunc("getColorR", &UI::getColorR);
2990 cls.addFunc("getColorG", &UI::getColorG);
2991 cls.addFunc("getColorB", &UI::getColorB);
2992 cls.addFunc("getColorA", &UI::getColorA);
2993 cls.addFunc("getChecked", &UI::getChecked);
2994 cls.addFunc("requestFocus", &UI::requestFocus);
2995 cls.addFunc("moveFocus", &UI::moveFocus);
2996 cls.addFunc("getFocusedId", &UI::getFocusedId);
2997 cls.addFunc("setHostVisible", &UI::setHostVisible);
2998 cls.addFunc("setHostLayer", &UI::setHostLayer);
2999 cls.addFunc("setHostModal", &UI::setHostModal);
3000 cls.addFunc("setHostOverlay", &UI::setHostOverlay);
3001 cls.addFunc("setHostInputTransparent", &UI::setHostInputTransparent);
3002 cls.addFunc("setHostHudCanvas", &UI::setHostHudCanvas);
3003 cls.addFunc("clearHostHudCanvas", &UI::clearHostHudCanvas);
3004 cls.addFunc("setHostSafeArea", &UI::setHostSafeArea);
3005 cls.addFunc("resourceBar", &UI::addResourceBar);
3006 cls.addFunc("skillSlot", &UI::addSkillSlot);
3007 cls.addFunc("filledImage", &UI::addFilledImage);
3008 cls.addFunc("radialFill", &UI::addRadialFill);
3009 cls.addFunc("setItemFillDirection", &UI::setItemFillDirection);
3010 cls.addFunc("setItemRadialFill", &UI::setItemRadialFill);
3011 cls.addFunc("setHostOverlayAlpha", &UI::setHostOverlayAlpha);
3012 cls.addFunc("setHostMovable", &UI::setHostMovable);
3013 cls.addFunc("setHostResizable", &UI::setHostResizable);
3014 cls.addFunc("setHostPos", &UI::setHostPos);
3015 cls.addFunc("setHostWorldAnchor", &UI::setHostWorldAnchor);
3016 cls.addFunc("clearHostWorldAnchor", &UI::clearHostWorldAnchor);
3017 cls.addFunc("setHostWorldEdgePolicy", &UI::setHostWorldEdgePolicy);
3018 cls.addFunc("setHostWorldDistanceScale", &UI::setHostWorldDistanceScale);
3019 cls.addFunc("setHostWorldOverlap", &UI::setHostWorldOverlap);
3020 cls.addFunc("getHostWorldState", &UI::getHostWorldState);
3021 cls.addFunc("getHostWorldScreenX", &UI::getHostWorldScreenX);
3022 cls.addFunc("getHostWorldScreenY", &UI::getHostWorldScreenY);
3023 cls.addFunc("setHostAnchor", &UI::setHostAnchor);
3024 cls.addFunc("setHostSize", &UI::setHostSize);
3025 cls.addFunc("setHostPercent", &UI::setHostPercent);
3026 // Trailing ease/delay (and cancelItemTweens id) are optional in script; C++
3027 // defaults do not reach Squirrel through member-function pointers.
3028 addOptionalTweenFunc(cls, "animateHostPos", sqAnimateHostPos, 4, _SC("xfffsf"));
3029 addOptionalTweenFunc(cls, "animateHostSize", sqAnimateHostSize, 4, _SC("xfffsf"));
3030 addOptionalTweenFunc(cls, "animateHostOverlayAlpha", sqAnimateHostOverlayAlpha, 3, _SC("xffsf"));
3031 addOptionalTweenFunc(cls, "animateItemValue", sqAnimateItemValue, 4, _SC("xsffsf"));
3032 addOptionalTweenFunc(cls, "animateItemOpacity", sqAnimateItemOpacity, 4, _SC("xsffsf"));
3033 addOptionalTweenFunc(cls, "animateItemPos", sqAnimateItemPos, 5, _SC("xsfffsf"));
3034 cls.addFunc("cancelHostTweens", &UI::cancelHostTweens);
3035 addOptionalTweenFunc(cls, "cancelItemTweens", sqCancelItemTweens, 1, _SC("xs"));
3036 cls.addFunc("cancelAllTweens", &UI::cancelAllTweens);
3037 cls.addFunc("tickTweens", &UI::tickTweens);
3038 cls.addFunc("getHostTweenCount", &UI::getHostTweenCount);
3039 cls.addFunc("getItemTweenCount", &UI::getItemTweenCount);
3040 cls.addFunc("consumeClick", &UI::consumeClick);
3041 cls.addFunc("consumeChange", &UI::consumeChange);
3042 cls.addFunc("dragDropSupport", &UI::dragDropSupport);
3043 cls.addFunc("consumeDrop", &UI::consumeDrop);
3044 cls.addFunc("getDropType", &UI::getDropType);
3045 cls.addFunc("getDropText", &UI::getDropText);
3046 cls.addFunc("getDropSource", &UI::getDropSource);
3047 cls.addFunc("getDropOrigin", &UI::getDropOrigin);
3048 cls.addFunc("onClick", &UI::onClick);
3049 cls.addFunc("onChange", &UI::onChange);
3050 cls.addFunc("componentOnClick", &UI::componentOnClick);
3051 cls.addFunc("componentOnChange", &UI::componentOnChange);
3052 cls.addFunc("componentClearHandlers", &UI::componentClearHandlers);
3053
3054 cls.addFunc("setThemeDark", &UI::setThemeDark);
3055 cls.addFunc("setThemeLight", &UI::setThemeLight);
3056 cls.addFunc("setTheme", &UI::setTheme);
3057 cls.addFunc("defineStyleClass", &UI::defineStyleClass);
3058 cls.addFunc("setStyleClassColor", &UI::setStyleClassColor);
3059 cls.addFunc("setStyleClassMetric", &UI::setStyleClassMetric);
3060 cls.addFunc("clearStyleClasses", &UI::clearStyleClasses);
3061 cls.addFunc("getTheme", &UI::getTheme);
3062 cls.addFunc("setNavKeyboard", &UI::setNavKeyboard);
3063 cls.addFunc("setNavGamepad", &UI::setNavGamepad);
3064 cls.addFunc("setScale", &UI::setScale);
3065 cls.addFunc("getScale", &UI::getScale);
3066 cls.addFunc("getStats", &UI::getStats);
3067 cls.addFunc("getLayoutDiagnostics", &UI::getLayoutDiagnostics);
3068 cls.addFunc("getAccessibilitySnapshot", &UI::getAccessibilitySnapshot);
3069 cls.addFunc("saveTreeJson", &UI::saveTreeJson);
3070 cls.addFunc("loadTreeJson", &UI::loadTreeJson);
3071 cls.addFunc("viewportCanvas", &UI::viewportCanvas);
3072 cls.addFunc("viewportHovered", &UI::viewportHovered);
3073 cls.addFunc("viewportActive", &UI::viewportActive);
3074 cls.addFunc("viewportMouseX", &UI::viewportMouseX);
3075 cls.addFunc("viewportMouseY", &UI::viewportMouseY);
3076 cls.addFunc("viewportDragDX", &UI::viewportDragDX);
3077 cls.addFunc("viewportDragDY", &UI::viewportDragDY);
3078 cls.addFunc("viewportWheel", &UI::viewportWheel);
3079
3080 cls.addFunc("mountSimple", &UI::mountSimple);
3081
3082 cls.addFunc("inspect", &UI::inspectOpen);
3083 cls.addFunc("inspectClose", &UI::inspectClose);
3084 cls.addFunc("inspectRefresh", &UI::inspectRefresh);
3085 cls.addFunc("inspectSelectClass", &UI::inspectSelectClass);
3086 cls.addFunc("inspectObject", &UI::inspectObject);
3087 cls.addFunc("inspectSetPickHandler", &UI::inspectSetPickHandler);
3088 cls.addFunc("inspectPickScene", &UI::inspectPickScene);
3089 cls.addFunc("inspectAddInstance", &UI::inspectAddInstance);
3090 cls.addFunc("propertySchema", &UI::propertySchema);
3091
3092 cls.addFunc("dbOpen", &UI::dbOpen);
3093 cls.addFunc("dbClose", &UI::dbClose);
3094 cls.addFunc("dbRefresh", &UI::dbRefresh);
3095 cls.addFunc("dbSelectClass", &UI::dbSelectClass);
3096 cls.addFunc("dbRegister", &UI::dbRegister);
3097 cls.addFunc("dbCreateInstance", &UI::dbCreateInstance);
3098 const HSQUIRRELVM vm = cls.getHandle();
3099 cls.addFunc("dbUnregister", [vm](UI *value, uint64_t id) {
3100 if (!value)
3103 "UI instance must not be null", {}, {}, "ui")));
3104 return eve::script::projectResult(vm, value->dbUnregister(id));
3105 });
3106
3107 cls.addFunc("editorOpen", &UI::editorOpen);
3108 cls.addFunc("editorClose", &UI::editorClose);
3109 cls.addFunc("editorSelectPanel", &UI::editorSelectPanel);
3110
3111 cls.addFunc("sceneOpen", &UI::sceneOpen);
3112 cls.addFunc("sceneClose", &UI::sceneClose);
3113 cls.addFunc("sceneSelectNode", &UI::sceneSelectNode);
3114 cls.addFunc("sceneSetPickHandler", &UI::sceneSetPickHandler);
3115}
3116
3117} // namespace eve::ui
double z
double y
double m[16]
double x
LogicalId target
Duration start
LogicalId itemId
float w
Definition AnimClip.cpp:738
int root
Definition AnimSmr.cpp:119
std::string selected
const std::string & s
float gap
int priority
float uv
struct SQVM * HSQUIRRELVM
std::string title
std::string nodeId
HSQUIRRELVM vm
Definition ECS.cpp:38
HSQOBJECT cls
Definition ECS.cpp:39
SQObjectPtr key
Definition ECS.cpp:155
std::string name
Definition ECS.cpp:154
ScriptFieldRegion region
tensor::Graph g
Definition GpuGraph.cpp:7
vk::UniqueImage image
glm::vec4 tint
glm::vec3 n
Definition Grass.cpp:63
double r
float v
HexVec3 up
HexVec3 left
HexVec3 right
std::int32_t c
std::int32_t first
Icon icon
Definition Icons.cpp:11
int h
std::uint32_t height
std::uint32_t width
float ratio
PhysicsJointLink link
const ColourScope * parent
std::array< float, 3 > scale
std::map< std::string, PropertyRule > properties
std::set< std::string > choices
std::string label
std::string id
Poco::JSON::Object::Ptr result
const char * description
std::vector< RecipeParam > params
HSQOBJECT handler
bool valid
bool readOnly
MeleePoint3 b
Definition MeleeHit.cpp:41
double radius
Definition MeleeHit.cpp:42
MeleePoint3 a
Definition MeleeHit.cpp:40
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:27
std::shared_ptr< OceanGpuSpectrum > owner
std::shared_ptr< const OceanSprayFrame > previous
std::string error
Definition Package.cpp:174
std::vector< particles::ParticleRecordEvent > events
TileLayer * layer
int idx
让脚本成为 IPhotoModeApplySink 的提供方(决定③的第一个落地插座)。
std::string path
Definition PlayHost.cpp:111
PrimitiveHandle handle
Object::Ptr value
float d
int detail
float t
glm::mat4 model
const RoadNode * node
RoadLaneDirection direction
bool found
std::string filter
Graphics * graphics
std::string text
ScriptStructure out
std::string_view source
std::string kind
std::string resource
const SquirrelValueOptions & options
The single Squirrel projection for common Result, Status and Value.
Explicit Value/Owned/Borrowed semantics at the Squirrel boundary.
AbilityActivationGroup group
int columns
float opacity
int margin
bool visible
Json object
int children
Definition TreeMesh.cpp:432
float size
Definition TreeMesh.cpp:158
UIHostHandle host
std::string payloadType
Definition UISystem.cpp:154
std::string payloadText
Definition UISystem.cpp:155
uint32_t index
Owning, renderer-independent dynamic values.
float fraction
float bottom
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
static Runtime * runtime()
Active runtime associated with the last expose() call, or nullptr. @ownership Borrowed; the embedding...
virtual std::string getName() const =0
Returns the name.
eve::Result< ResourcePin > pin(Resource *resource)
Keeps one cached resource alive across unload()/clear()/reload.
Definition Resource.cpp:311
static ResourceManager & getInstance()
Returns the instance.
Definition Resource.cpp:15
void ignore(std::string_view reason={}) const noexcept
Explicitly discard this result after documenting the reason.
Definition Result.h:571
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
static constexpr RuntimeHandle fromPacked(std::uint64_t value) noexcept
Reconstructs a handle from an explicit packed boundary value.
EVENGINE_API_FOUNDATION public API.
Definition Runtime.h:189
HSQUIRRELVM handle() const noexcept
Raw Squirrel VM handle; nullptr after shutdown.
Definition Runtime.cpp:522
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
void set(const std::string &key, Value value)
Insert or replace an object member.
Definition Value.cpp:238
static Value array(Array value)
Compatibility factory for an array value.
Definition Value.cpp:128
void pushBack(Value value)
Append an element to an array value.
Definition Value.cpp:214
static Value object(Object value)
Compatibility factory for an object value.
Definition Value.cpp:129
Canvas public API.
Definition Canvas.h:17
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:15
Represents raw pixel data.
Definition ImageData.h:38
EVENGINE_API_FOUNDATION public API.
Definition Json.h:137
bool valid() const
Valid.
Definition Json.h:158
static Document parse(const std::string &text, std::string *error=nullptr)
Parse.
Definition Json.cpp:623
Value root() const
Root.
Definition Json.h:160
EVENGINE_API_FOUNDATION public API.
Definition Json.h:39
Value get(const char *key) const
Returns the value.
Definition Json.cpp:337
int getInt(const char *key, int fallback=0) const
Returns the int.
Definition Json.cpp:423
Adapts one live Squirrel instance to the renderer-independent property model.
Releases C++-owned Squirrel roots before Runtime destroys its VM.
virtual void releaseSquirrelRoots() noexcept=0
Drops every C++-owned Squirrel root this listener still holds.
RAII keep-alive for one RuntimeObjectRegistry entry.
T * get() const noexcept
Borrows the pinned object; valid until the pin is released.
void clearAll()
Removes every entry.
static ObjectRegistry & instance()
Returns the process-local singleton owned by the UI module.
static UIHostHandle createHost(const std::string &name="")
Creates an ECS-owned UI host.
Definition UIHost.cpp:49
static eve::OptionalRef< UIHost > resolve(UIHostHandle handle) noexcept
Resolves a UI host handle with ECS generation checking.
Definition UIHost.cpp:62
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::string consumeChange()
Pop next change as "name/node"; empty if none.
static UIHostHandle findHost(const std::string &name)
Lookup by Meta.name across the UIHost View.
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::vector< UIEvent > & pendingEvents()
Pending events.
Declarative UI module (eve.UI).
Definition UI.h:41
void cancelHostTweens()
Cancel pending host-level tweens on the selected host.
Definition UI.cpp:1659
bool inspectSelectClass(const std::string &name)
Selects a class in the inspector (creates its first instance).
Definition UI.cpp:2567
void setTextWrap(const std::string &id, float width)
Sets the text wrap.
Definition UI.cpp:1186
bool mountBuild()
Finishes the build pass and mounts the built tree.
Definition UI.cpp:1136
void addCombo(const std::string &label, const std::string &options, int selected, const std::string &id="")
Adds combo.
Definition UI.cpp:859
float viewportMouseX(const std::string &id)
Viewport mouse x.
Definition UI.cpp:2093
void setHostWorldAnchor(float x, float y, float z)
Projects the selected host from a 3D world point through the active Camera3D.
Definition UI.cpp:1486
void addSectionHeader(const std::string &label, const std::string &id="")
Adds a non-collapsible section heading.
Definition UI.cpp:904
void setItemTheme(const std::string &theme)
Overrides the last item's subtree theme: "inherit", "dark", or "light".
Definition UI.cpp:1048
void setItemDragSource(const std::string &payloadType, const std::string &payloadText)
Marks the most recently added item as a desktop drag source.
Definition UI.cpp:1011
bool setImageNinePatchFile(const std::string &id, const std::string &path)
Applies a .9.png texture and its parsed stretch metadata to an image.
Definition UI.cpp:1321
bool wantCaptureKeyboard() const
True when the UI wants to capture keyboard input this frame.
Definition UI.cpp:420
uint64_t registerTexture(graphics::Texture *tex)
Register an engine texture for UI drawing.
Definition UI.cpp:1261
std::string consumeClick()
Returns the id of the clicked widget since the last frame (or "").
Definition UI.cpp:1590
void setItemFlexShrink(float shrink)
Sets shrink weight on the most recently added flex item.
Definition UI.cpp:923
bool initBackend()
Creates the platform UI backend (ImGui); true on success.
Definition UI.cpp:310
UIHostHandle mount(WidgetDesc root)
Mounts the tree as an auto-named host and selects it.
Definition UI.cpp:470
void addLink(const std::string &label, const std::string &target, const std::string &id)
Add clickable text; target is metadata and activation emits a click event.
Definition UI.cpp:873
void setThemeScope(const std::string &theme)
Overrides the current open container's inherited subtree theme.
Definition UI.cpp:1053
void setHostPercent(float w, float h)
Sets the host percent.
Definition UI.cpp:1567
void setColor(const std::string &id, float r, float g, float b, float a=1.f)
Sets RGBA on a ColorPalette (or image tint) node.
Definition UI.cpp:1212
void animateHostOverlayAlpha(float alpha, float durationMs, const std::string &ease="smoothstep", float delayMs=0.f)
Animate the selected host's overlay background alpha.
Definition UI.cpp:1585
void setImageTextureId(const std::string &id, uint64_t textureId)
Sets the image texture id.
Definition UI.cpp:1255
void setHostPos(float x, float y, float pivotX=0.f, float pivotY=0.f)
Positions the host window with a pivot (0..1 each axis).
Definition UI.cpp:1475
std::string saveTreeJson() const
Saves tree json.
Definition UI.cpp:1755
bool editorSelectPanel(const std::string &name)
Shows one docked panel ("inspector"/"database"; "" hides all).
Definition UI.cpp:2780
bool inspectPickScene()
Calls the pick handler and inspects the returned object.
Definition UI.cpp:2638
UI()
Ui.
Definition UI.cpp:287
std::size_t getItemTweenCount() const
Number of pending item tweens (diagnostics / tests).
Definition UI.cpp:354
void dispatchEvents()
Dispatches queued widget callbacks (click/toggle/value/text).
Definition UI.cpp:356
void setItemFocusMode(const std::string &mode)
Sets the last item's focus mode: "none", "click", or "all".
Definition UI.cpp:1038
void setItemPercent(float w, float h)
Sets the item percent.
Definition UI.cpp:988
void bindOwner(uint32_t ownerId)
Binds the selected host to a UI/scene owner id.
Definition UI.cpp:435
void addText(const std::string &content, const std::string &id="")
Adds a text label to the current container.
Definition UI.cpp:738
void setImageCornerRadius(const std::string &id, float radius)
Sets the image corner radius.
Definition UI.cpp:1249
std::string getHostWorldState() const
Returns the selected host projection state as a stable lowercase name.
Definition UI.cpp:1526
void processEvent(const SDL_Event *event)
Feeds an SDL event into the UI backend (before window/game handling).
Definition UI.cpp:332
void setHostSize(float w, float h)
Sets the host size.
Definition UI.cpp:1558
bool inspectOpen()
Opens the auto-generated inspector (scans reflected classes).
Definition UI.cpp:2550
std::string getDropSource() const
Returns the source as "host/node", or empty for an OS file.
Definition UI.cpp:1618
void clearHostHudCanvas()
Returns this host to existing pixel layout. @thread UI thread; no callbacks.
Definition UI.cpp:1446
void componentOnClick(uint64_t owner, const std::string &id, ssq::Function fn)
Internal UIComponent callback registration scoped to one component owner.
Definition UI.cpp:394
void animateHostSize(float w, float h, float durationMs, const std::string &ease="smoothstep", float delayMs=0.f)
Animate the selected host's explicit window size (px).
Definition UI.cpp:1580
void setItemFlexBasis(float basis)
Sets its main-axis basis; negative restores automatic measurement.
Definition UI.cpp:928
bool sceneOpen()
Opens the scene panel (tree + selected node properties).
Definition UI.cpp:2784
bool sceneSetPickHandler(ssq::Function fn)
Registers the script callback for the scene panel Pick button. The callback (stored as eve....
Definition UI.cpp:2801
void editorClose()
Closes the editor shell (and its docked panels).
Definition UI.cpp:2776
void shutdownBackend()
Destroys the platform UI backend.
Definition UI.cpp:325
float viewportDragDX(const std::string &id)
Viewport drag dx.
Definition UI.cpp:2107
float getValue(const std::string &id) const
Returns the value.
Definition UI.cpp:1272
~UI() override
Ui.
Definition UI.cpp:293
void addSpacer(const std::string &id="", float grow=1.f)
Flexible empty space inside Flex (default grow=1).
Definition UI.cpp:913
void addImage(const std::string &id="", float width=0.f, float height=0.f)
Adds image.
Definition UI.cpp:832
void beginMenuBar(const std::string &id="")
Opens a window menu bar.
Definition UI.cpp:547
bool viewportActive(const std::string &id)
Viewport active.
Definition UI.cpp:2086
void setNavKeyboard(bool enabled)
Enables/disables keyboard navigation support.
Definition UI.cpp:1686
float getColorA(const std::string &id) const
Returns the color a.
Definition UI.cpp:1307
void unregisterTexture(uint64_t textureId)
Release a texture id previously returned by registerTexture().
Definition UI.cpp:1268
float getColorR(const std::string &id) const
ColorPalette / image tint channels; missing nodes return 0.
Definition UI.cpp:1286
void setHostWorldOverlap(bool enabled, int priority=0, float padding=4.f, float maxDisplacement=96.f)
Configures deterministic overlap avoidance for projected hosts.
Definition UI.cpp:1514
void setItemMaxSize(float w, float h)
Sets the item max size.
Definition UI.cpp:981
UIHostHandle findHostByOwner(uint32_t ownerId) const
Finds the host bound to an owner id, or null when absent.
Definition UI.cpp:426
void addIcon(const std::string &name, const std::string &id="")
Adds a semantic icon by name (for example "search" or "save").
Definition UI.cpp:752
void setLayoutOverflow(const std::string &overflow)
Sets overflow behavior: visible, clip, or scroll.
Definition UI.cpp:1120
bool setListItems(const std::string &listId, const std::vector< std::string > &items)
Replace children of a Group listId with buttons for each label (reconcile). Host must already exist a...
Definition UI.cpp:1167
UIHostHandle remountReconcile(WidgetDesc root)
Remount with key reconcile (props-only when structure matches).
Definition UI.cpp:484
void setItemPadding(float l, float t, float r, float b)
Sets the item padding.
Definition UI.cpp:965
void setHostSafeArea(float left, float top, float right, float bottom)
Sets nonnegative safe margins in display logical pixels. @thread UI thread; no callbacks.
Definition UI.cpp:1450
void setItemAspectRatio(float ratio)
Sets width/height ratio on the most recently added item.
Definition UI.cpp:939
void setItemFlexGrow(float grow)
Set flex item props on the most recently added child of the current open container....
Definition UI.cpp:917
void beginWindow(const std::string &title, const std::string &id="root")
Opens a window for the current build pass.
Definition UI.cpp:507
UIHostHandle remount(WidgetDesc root)
Replaces the selected host's tree.
Definition UI.cpp:478
float getColorB(const std::string &id) const
Returns the color b.
Definition UI.cpp:1300
void setItemAccessibility(const std::string &role, const std::string &name, const std::string &description="")
Sets the last item's accessibility role, name and description.
Definition UI.cpp:1086
void setItemHelp(const std::string &help, const std::string &disabledReason)
Set the last control's help and disabled explanation.
Definition UI.cpp:882
void end()
Closes the innermost open container.
Definition UI.cpp:726
bool remountBuildAs(const std::string &name)
Like mountBuildAs but reconciles by key when possible.
Definition UI.cpp:1154
void sceneClose()
Closes the scene panel.
Definition UI.cpp:2793
eve::Result< void > dbUnregister(uint64_t id)
Removes an entry from the database grid using its packed handle.
Definition UI.cpp:2749
void beginFlex(const std::string &direction="row", const std::string &id="", float gap=-1.f)
Begin a Flex container.
Definition UI.cpp:697
void addInputText(const std::string &label, const std::string &value, const std::string &id="")
Adds an editable text field.
Definition UI.cpp:887
void setHostMovable(bool movable)
Allows or prevents user movement after the initial position.
Definition UI.cpp:1467
void tickTweens(double nowMs)
Advance pending UI tweens using an explicit clock (ms).
Definition UI.cpp:350
void addRadialFill(const std::string &id, float width, float height, float fraction)
Adds a solid radial sector/ring overlay. @thread UI thread; no callbacks.
Definition UI.cpp:800
void setItemSelected(bool selected)
Marks the most recently added button as the selected tool/action.
Definition UI.cpp:1033
bool editorOpen()
Opens the menu bar and docks the inspector + database panels.
Definition UI.cpp:2759
void addViewport(const std::string &id, float width=0.f, float height=0.f)
Adds viewport.
Definition UI.cpp:855
void addImageButton(const std::string &id, float width, float height)
Adds image button.
Definition UI.cpp:851
void addSkillSlot(const std::string &id, float size, uint64_t iconTexture, float cooldown, const std::string &key)
Adds a composed skill slot; click ID ends in /activate. @thread UI thread; caller owns icon registrat...
Definition UI.cpp:796
UIHostHandle findHost(const std::string &name) const
Finds a host by name, or null when absent.
Definition UI.cpp:424
void addSearchField(const std::string &hint, const std::string &value="", const std::string &id="")
Adds a compact search field.
Definition UI.cpp:891
std::string getStats() const
Returns the stats.
Definition UI.cpp:1706
void beginToolbox(const std::string &id="", float cellSize=0.f, int columns=0)
Opens a wrapping editor tool grid.
Definition UI.cpp:555
void beginGroup(const std::string &id="")
Opens a group container in the current build pass.
Definition UI.cpp:512
void cancelAllTweens()
Cancel every pending tween on the selected host.
Definition UI.cpp:1669
void onClick(const std::string &id, ssq::Function fn)
On click.
Definition UI.cpp:380
void cancelItemTweens(const std::string &id="")
Cancel pending item tweens on the selected host.
Definition UI.cpp:1664
std::string setStyleClassColor(const std::string &name, const std::string &property, float r, float g, float b, float a=1.f)
Sets a named class color token and returns a stable status string.
Definition UI.cpp:1674
void beginCollapsing(const std::string &label, const std::string &id="", bool open=true)
Opens a collapsible header.
Definition UI.cpp:516
bool setTheme(const std::string &name)
Named preset: "dark" / "light" (case-insensitive). Returns false if unknown.
Definition UI.cpp:1626
void setHostLayer(int layer)
Sets the host layer.
Definition UI.cpp:1417
void setHostResizable(bool resizable)
Allows or prevents user resizing after the initial size.
Definition UI.cpp:1471
void beginTabContainer(const std::string &activePageId, const std::string &id="")
Opens a tabbed page stack; activePageId selects the visible page. Add pages with beginPanelFrame / be...
Definition UI.cpp:567
void setThemeLight()
Sets the theme light.
Definition UI.cpp:1624
void setItemAbsolute(float anchorX, float anchorY, float x=0.f, float y=0.f)
Sets the item absolute.
Definition UI.cpp:995
UIHostHandle mountAs(const std::string &name, WidgetDesc root)
Creates/replaces a named host from a WidgetDesc tree and selects it.
Definition UI.cpp:455
void beginFrameAndRender()
Builds and presents the current frame's UI.
Definition UI.cpp:339
void beginGrid(int columns, const std::string &id="", float columnGap=-1.f, float rowGap=-1.f)
Begins a fixed-column grid container.
Definition UI.cpp:707
bool select(const std::string &name)
Selects a named host; false when it does not exist.
Definition UI.cpp:428
void addIconButton(const std::string &name, const std::string &label="", const std::string &id="")
Adds a semantic icon button with an optional visible label.
Definition UI.cpp:758
std::string getAccessibilitySnapshot() const
JSON accessibility snapshot for semantically named nodes in the selected tree.
Definition UI.cpp:1731
float getScale() const
Current UI scale factor.
Definition UI.cpp:1702
void setItemMargin(float l, float t, float r, float b)
Sets the item margin.
Definition UI.cpp:956
bool viewportHovered(const std::string &id)
Viewport hovered.
Definition UI.cpp:2079
std::string getDropType() const
Returns the payload type of the last successfully consumed drop.
Definition UI.cpp:1614
UIHostHandle remountAs(const std::string &name, WidgetDesc root)
Creates/replaces a named host (does not select it).
Definition UI.cpp:490
void beginCard(const std::string &id="")
Opens a bordered card surface.
Definition UI.cpp:524
float viewportWheel(const std::string &id)
Viewport wheel.
Definition UI.cpp:2121
void animateItemValue(const std::string &id, float value, float durationMs, const std::string &ease="smoothstep", float delayMs=0.f)
Animate a normalized HUD fill on the selected host without rebuilding the tree.
Definition UI.cpp:1642
void setItemFillDirection(const std::string &direction, bool stretch)
Configures the last built fill: right/left/down/up; stretch retains complete UVs. @thread UI thread.
Definition UI.cpp:804
void setItemFocusNeighbors(const std::string &left, const std::string &right, const std::string &up, const std::string &down)
Sets explicit directional focus neighbors on the last item.
Definition UI.cpp:1076
void setScale(float scale)
Global UI scale factor (default 1).
Definition UI.cpp:1694
void beginColumn(const std::string &id="", float gap=-1.f)
Opens a column flex container.
Definition UI.cpp:705
void setNavGamepad(bool enabled)
Sets the nav gamepad.
Definition UI.cpp:1690
void setItemSize(float width, float height)
Sets width/height on the most recently added child.
Definition UI.cpp:949
void setHostModal(bool modal)
Marks the host as a modal (blocks other hosts) / overlay.
Definition UI.cpp:1421
void addResourceBar(const std::string &id, float width, float height, float fraction)
Adds a composed resource bar with /value, /trail and /label child IDs. @thread UI thread.
Definition UI.cpp:792
void addCheckbox(const std::string &label, bool checked, const std::string &id="")
Adds a checkbox.
Definition UI.cpp:770
void beginAppFrame(const std::string &id="")
Opens a fixed editor frame body that hosts toolbar/dock/status children.
Definition UI.cpp:582
bool inspectRefresh()
Re-scans script classes; true when any class is reflected.
Definition UI.cpp:2561
void beginTabBar(const std::string &id="")
Opens a horizontal tab strip.
Definition UI.cpp:565
bool dbSelectClass(const std::string &name)
Selects the class shown in the grid.
Definition UI.cpp:2727
void addTab(const std::string &label, const std::string &pageId, bool selected=false, const std::string &id="")
Adds a selectable tab label; pageId identifies the page to activate.
Definition UI.cpp:594
bool isBackendReady() const
True once the backend exists.
Definition UI.cpp:308
void beginBuild()
Imperative builder: open a new build pass (see beginWindow etc.).
Definition UI.cpp:494
bool dbRefresh()
Re-scans reflected classes; true when any class exists.
Definition UI.cpp:2721
void addSlider(const std::string &label, float value, float minV, float maxV, const std::string &id="")
Adds a slider.
Definition UI.cpp:774
void setFlexAlign(const std::string &align)
Set Flex container align/justify on the current open Flex (no-op otherwise).
Definition UI.cpp:1095
bool moveFocus(const std::string &direction)
Moves focus by "next", "previous", "left", "right", "up", or "down".
Definition UI.cpp:1401
void setItemTextInput(bool multiline, bool readOnly, const std::string &placeholder)
Configure the last control's plain-text editor options.
Definition UI.cpp:877
void addProgress(float fraction, const std::string &id="", const std::string &overlay="")
Adds a progress bar.
Definition UI.cpp:784
bool getChecked(const std::string &id) const
Returns the checked.
Definition UI.cpp:1314
void addSwitch(const std::string &label, bool checked, const std::string &id="")
Adds a modern boolean switch.
Definition UI.cpp:896
uint64_t dbRegister(ssq::Object object, const std::string &label)
Registers a live script object in the database grid.
Definition UI.cpp:2733
std::string defineStyleClass(const std::string &name, const std::string &parent="")
Declares/replaces a named style class and returns a stable status string.
Definition UI.cpp:1630
void setHostWorldDistanceScale(bool enabled, float referenceDistance=10.f, float minScale=0.65f, float maxScale=1.25f)
Configures distance scaling.
Definition UI.cpp:1503
bool sceneSelectNode(const std::string &id)
Selects a scene node by id.
Definition UI.cpp:2797
std::string dragDropSupport() const
Returns "supported" on desktop builds and "unsupported-platform" elsewhere.
Definition UI.cpp:1594
void setStyleScope(const std::string &name)
Applies a named style class to the current open container.
Definition UI.cpp:1062
void setHostVisible(bool visible)
Host-level state.
Definition UI.cpp:1413
void animateItemPos(const std::string &id, float x, float y, float durationMs, const std::string &ease="smoothstep", float delayMs=0.f)
Animate one node's absolute placement offset (marks the node absolute).
Definition UI.cpp:1652
std::string getFocusedId() const
Returns the focused control id, or an empty string.
Definition UI.cpp:1408
void setItemGridColumnSpan(int span)
Sets the grid-column span of the most recently added item.
Definition UI.cpp:944
void beginStatusBar(const std::string &id="")
Opens a compact horizontal status strip.
Definition UI.cpp:563
graphics::Canvas * viewportCanvas(const std::string &id)
Returns the offscreen render target of a selected-host Viewport widget.
Definition UI.cpp:2069
uint64_t dbCreateInstance()
Creates and registers an instance of the selected class.
Definition UI.cpp:2741
float getColorG(const std::string &id) const
Returns the color g.
Definition UI.cpp:1293
void setImageUv(const std::string &id, float u0, float v0, float u1, float v1)
Sets the image uv.
Definition UI.cpp:1227
ssq::Object propertySchema(ssq::Object instance)
Return the reflection-derived PropertySchema for a live script instance.
Definition UI.cpp:2679
void clearHostWorldAnchor()
Returns the selected host to ordinary screen-space placement.
Definition UI.cpp:1490
void addTextWrapped(const std::string &content, float width, const std::string &id="")
Adds text wrapped.
Definition UI.cpp:742
void setItemTooltip(const std::string &text)
Sets hover help on the most recently added item.
Definition UI.cpp:1005
void beginDockArea(const std::string &region, const std::string &id="")
Opens a named dock fill slot (region: left/right/top/bottom/center).
Definition UI.cpp:580
bool beginNinePatch(const std::string &path, const std::string &id="", float width=0.f, float height=0.f)
Opens a stretchable .9.png panel; false means the asset is invalid.
Definition UI.cpp:526
void setText(const std::string &id, const std::string &text)
Widget state setters/getters on the current host (by node id).
Definition UI.cpp:1182
void addMenuItem(const std::string &label, const std::string &shortcut="", const std::string &id="")
Adds a selectable menu command.
Definition UI.cpp:908
void beginList(const std::string &id)
Opens a list container (rows added with addListItem).
Definition UI.cpp:514
void addSeparator(const std::string &id="")
Adds a separator line.
Definition UI.cpp:766
void beginChild(const std::string &id, float width=0.f, float height=120.f)
Opens a sized child region.
Definition UI.cpp:520
void addBadge(const std::string &label, const std::string &id="")
Adds a compact status/category badge.
Definition UI.cpp:900
float getHostWorldScreenY() const
Returns the selected host's derived screen Y coordinate.
Definition UI.cpp:1545
void setHostAnchor(float x, float y)
Sets the host anchor.
Definition UI.cpp:1550
bool requestFocus(const std::string &id)
Requests keyboard/gamepad focus for a mounted control.
Definition UI.cpp:1396
void setItemMouseFilter(const std::string &filter)
Sets the last item's pointer filter: "stop", "pass", or "ignore".
Definition UI.cpp:1043
void setHostHudCanvas(float referenceWidth, float referenceHeight, float userScale)
Enables fit-scaled design units on this screen host; positive finite dimensions/scale required....
Definition UI.cpp:1433
bool addNinePatch(const std::string &path, const std::string &id="", float width=0.f, float height=0.f)
Adds a .9.png image after removing its one-pixel marker frame.
Definition UI.cpp:836
void setImageNinePatch(const std::string &id, float l, float t, float r, float b)
Sets the image nine patch.
Definition UI.cpp:1238
void addSameLine(const std::string &id="")
Adds an inline-break spacer.
Definition UI.cpp:764
void setEnabled(const std::string &id, bool enabled)
Enables or disables a mounted control.
Definition UI.cpp:1196
void setImageTint(const std::string &id, float r, float g, float b, float a=1.f)
Sets the image tint.
Definition UI.cpp:1216
void beginSplitPane(const std::string &direction="row", float ratio=0.25f, const std::string &id="")
Opens a two-child resizable split pane.
Definition UI.cpp:714
std::string getDropText() const
Returns the owning payload text of the last successfully consumed drop.
Definition UI.cpp:1616
void setThemeDark()
Applies the dark/light built-in theme.
Definition UI.cpp:1622
void onChange(const std::string &id, ssq::Function fn)
On change.
Definition UI.cpp:386
void animateHostPos(float x, float y, float durationMs, const std::string &ease="smoothstep", float delayMs=0.f)
Animate the selected host's window position (px).
Definition UI.cpp:1575
void releaseSquirrelRoots() noexcept
Drops database-panel Squirrel roots while the Runtime VM is alive.
Definition UI.cpp:299
bool inspectObject(ssq::Object object)
Inspects a caller-provided live script instance.
Definition UI.cpp:2574
void beginToolbar(const std::string &id="")
Opens a horizontal editor command strip.
Definition UI.cpp:553
std::string consumeChange()
Returns the id of the changed widget since the last frame (or "").
Definition UI.cpp:1592
void beginPanelFrame(const std::string &title, const std::string &id="")
Opens a fixed titled panel frame (not a free-floating Window host).
Definition UI.cpp:578
bool inspectAddInstance()
Creates another instance of the selected inspector class.
Definition UI.cpp:2647
void setHostOverlayAlpha(float alpha)
Sets overlay opacity (0..1); zero also removes the host border and outer padding.
Definition UI.cpp:1463
void setItemMinSize(float w, float h)
Sets the item min size.
Definition UI.cpp:974
void beginScrollList(const std::string &id="", float height=0.f, float itemHeight=0.f)
Begins scroll list.
Definition UI.cpp:598
void setHostWorldEdgePolicy(const std::string &policy, float safeMargin=8.f)
Configures off-screen handling and safe-edge margin.
Definition UI.cpp:1494
void setHostOverlay(bool overlay)
Sets the host overlay.
Definition UI.cpp:1425
void addColorPalette(const std::string &label, float r, float g, float b, float a=1.f, const std::string &id="")
Adds a color palette (ColorEdit + swatch grid). RGBA is stored on the node tint; read back with getCo...
Definition UI.cpp:779
void setValueText(const std::string &id, const std::string &value)
Sets the value text.
Definition UI.cpp:1208
std::string setStyleClassMetric(const std::string &name, const std::string &property, float x, float y=0.f)
Sets a named class metric token and returns a stable status string.
Definition UI.cpp:1679
std::size_t getHostTweenCount() const
Number of pending host tweens (diagnostics / tests).
Definition UI.cpp:352
void mountSimple(const std::string &title, const std::string &labelText, const std::string &buttonText)
One-shot convenience: a window with a label and a button.
Definition UI.cpp:2543
std::string getDropOrigin() const
Returns "internal", "os-file", or an empty string.
Definition UI.cpp:1620
void beginRow(const std::string &id="", float gap=-1.f)
Opens a row flex container.
Definition UI.cpp:703
void componentClearHandlers(uint64_t owner)
Removes every callback owned by one UIComponent; idempotent on the UI thread.
Definition UI.cpp:409
void setFlexWrap(bool wrap)
Enables or disables line wrapping on the current Flex.
Definition UI.cpp:1114
bool wantCaptureMouse() const
True when the UI wants to capture mouse input this frame.
Definition UI.cpp:416
void addButton(const std::string &label, const std::string &id="")
Adds a button to the current container.
Definition UI.cpp:748
void beginMenu(const std::string &label, const std::string &id="")
Opens a popup menu.
Definition UI.cpp:549
void setItemRadialFill(float startDegrees, bool clockwise, float innerRadius)
Configures the last radial fill; degrees point right at zero, inner radius is [0,1]....
Definition UI.cpp:822
bool mountBuildAs(const std::string &name)
Finishes the build pass and mounts as a named host.
Definition UI.cpp:1145
float viewportDragDY(const std::string &id)
Viewport drag dy.
Definition UI.cpp:2114
bool inspectSetPickHandler(ssq::Function fn)
Registers the script callback used by the inspector Pick button. The callback is stored on the script...
Definition UI.cpp:2581
void setItemEnabled(bool enabled)
Enables or disables the most recently added item.
Definition UI.cpp:1028
void setFlexJustify(const std::string &justify)
Sets Flex container justify on the current open Flex.
Definition UI.cpp:1101
bool dbOpen()
Opens the database panel (class menu + editable instance grid).
Definition UI.cpp:2711
std::string getValueText(const std::string &id) const
Returns the value text.
Definition UI.cpp:1279
void beginSidebar(const std::string &id="", float width=0.f)
Opens a vertical editor side panel.
Definition UI.cpp:559
std::string consumeDrop()
Pops one drop and returns its target as "host/node", or an empty string.
Definition UI.cpp:1600
void setValue(const std::string &id, float value)
Sets the value.
Definition UI.cpp:1204
void setItemStyleClass(const std::string &name)
Applies a named style class to the most recently added item.
Definition UI.cpp:1057
void setHostInputTransparent(bool transparent)
Makes a display-only host ignore mouse and keyboard input. @thread UI thread; no callbacks.
Definition UI.cpp:1429
void addListItem(const std::string &label, const std::string &id="")
Append one list row button (call inside beginList).
Definition UI.cpp:1126
void inspectClose()
Closes the inspector panel.
Definition UI.cpp:2557
void setLayoutGaps(float columnGap, float rowGap)
Sets independent column and row gaps on the current Flex/Grid.
Definition UI.cpp:1107
void setVisible(const std::string &id, bool visible)
Sets the visible.
Definition UI.cpp:1192
void componentOnChange(uint64_t owner, const std::string &id, ssq::Function fn)
Internal UIComponent value callback registration scoped to one component owner.
Definition UI.cpp:401
void animateItemOpacity(const std::string &id, float opacity, float durationMs, const std::string &ease="smoothstep", float delayMs=0.f)
Smoothly animates one retained node's transient opacity without rebuilding its tree.
Definition UI.cpp:1634
void setItemTabIndex(int index)
Sets the last item's sequential focus order; negative excludes it.
Definition UI.cpp:1064
std::string getTheme() const
Name of the active theme.
Definition UI.cpp:1628
void clearStyleClasses()
Clears all named style classes.
Definition UI.cpp:1684
void setItemAlignSelf(const std::string &align)
Sets its cross-axis alignment: inherit, start, center, end, or stretch.
Definition UI.cpp:933
void dbClose()
Closes the database panel.
Definition UI.cpp:2717
void setItemDropTarget(const std::string &acceptedType)
Marks the most recently added item as a desktop drop target.
Definition UI.cpp:1020
void setItemFocusOrder(const std::string &previous, const std::string &next)
Sets explicit previous and next focus neighbors on the last item.
Definition UI.cpp:1069
float getHostWorldScreenX() const
Returns the selected host's derived screen X coordinate.
Definition UI.cpp:1540
void setChecked(const std::string &id, bool checked)
Sets the checked.
Definition UI.cpp:1200
bool loadTreeJson(const std::string &json)
Loads tree json.
Definition UI.cpp:1769
std::string getLayoutDiagnostics() const
JSON diagnostics for measured size and overflow of the selected retained tree.
Definition UI.cpp:1714
void addFilledImage(const std::string &id, float width, float height, float fraction)
Adds a linear filled image; layout keeps its complete rectangle. @thread UI thread; no callbacks.
Definition UI.cpp:788
float viewportMouseY(const std::string &id)
Viewport mouse y.
Definition UI.cpp:2100
void animateHostSize(UIHostHandle host, float w, float h, float durationMs, const std::string &ease, float delayMs, double nowMs)
Animate selected-host explicit window size.
Definition UiTween.cpp:212
void cancelItem(UIHostHandle host, const std::string &id={})
Cancel every pending item tween for host + id (empty id = all items).
Definition UiTween.cpp:374
void tick(double nowMs)
Advance all pending tweens to nowMs.
Definition UiTween.cpp:388
void cancelAll(UIHostHandle host)
Cancel every pending tween for host.
Definition UiTween.cpp:383
std::size_t hostTweenCount() const noexcept
Number of pending host tweens (tests / diagnostics).
Definition UiTween.h:177
eve::Result< void > animateItemPos(UIHostHandle host, const std::string &id, float x, float y, float durationMs, const std::string &ease, float delayMs, double nowMs)
Animate one absolute node's placement offset.
Definition UiTween.cpp:330
void cancelHost(UIHostHandle host)
Cancel every pending host tween for host.
Definition UiTween.cpp:368
eve::Result< void > animateItemOpacity(UIHostHandle host, const std::string &id, float opacity, float durationMs, const std::string &ease, float delayMs, double nowMs)
Animate one node's transient opacity.
Definition UiTween.cpp:261
eve::Result< void > animateItemValue(UIHostHandle host, const std::string &id, float value, float durationMs, const std::string &ease, float delayMs, double nowMs)
Animate a normalized HUD value, replacing the previous value tween from its current sample.
Definition UiTween.cpp:294
void animateHostOverlayAlpha(UIHostHandle host, float alpha, float durationMs, const std::string &ease, float delayMs, double nowMs)
Animate selected-host overlay background alpha.
Definition UiTween.cpp:239
std::size_t itemTweenCount() const noexcept
Number of pending item tweens (tests / diagnostics).
Definition UiTween.h:180
void animateHostPos(UIHostHandle host, float x, float y, float durationMs, const std::string &ease, float delayMs, double nowMs)
Animate selected-host window position.
Definition UiTween.cpp:185
SDL2 desktop/mobile implementation of eve::window::Window.
Definition Window.h:16
SQInteger top
Definition Snapshot.cpp:115
char * encode(std::string format, const char *src, size_t srclen, size_t &dstlen, size_t linelen)
Encodes raw bytes (e.g. hex / base64) into a text buffer.
char * decode(std::string format, const char *src, size_t srclen, size_t &dstlen)
Decodes a text buffer (hex / base64) back into raw bytes.
Result< std::string > stringify(const eve::Value &value)
Serialize the canonical owning Value as deterministic compact JSON.
Definition Json.cpp:605
constexpr bool hasFlag(PropertyFlag value, PropertyFlag flag)
True when flag.
PropertyKind
Semantic property kind used by renderer-independent presenters.
std::unordered_map< std::string, SkillDefinition > & table()
Definition Skill.cpp:73
SQRESULT callFunction(HSQUIRRELVM vm, const HSQOBJECT &fn, const Receiver &receiver, Args &&... args)
Call a script function, deriving sq_call's parameter count from the pushes.
SQRESULT callFunctionResult(HSQUIRRELVM vm, const HSQOBJECT &fn, const Receiver &receiver, Args &&... args)
callFunction() that keeps the return value on top for the caller to read.
constexpr RootTable rootTable
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.
std::string reportScriptCallFailure(HSQUIRRELVM vm, const char *what)
Report a failed engine-to-script call, consuming the VM's script error.
void injectUIComponentClass(ssq::Table &eveTable)
WidgetDesc collapsingHeader(std::string label, std::vector< WidgetDesc > children, std::string id, bool defaultOpen)
Collapsible header containing child widgets.
Definition Widget.cpp:814
void exposePcgScreenshotSavedNoticeBindings(ssq::Table &t)
Register Pcg screenshot-notice bindings.
EVENGINE_API_WORLD void declareScriptPhotoModeApplySeam()
声明"`IPhotoModeApplySink` 可以由脚本提供"这条接缝。
StyleClassStatus defineStyleClass(const std::string &name, const std::string &parent)
Declares or replaces one sparse style class. @thread UI thread only. @reentrancy Does not invoke call...
Definition Theme.cpp:82
WidgetDesc menuItem(std::string label, std::string shortcut, std::string id, std::function< void()> onClick, bool selected)
Selectable menu command with an optional shortcut hint.
Definition Widget.cpp:642
void exposePcgPhotoModePanelsBindings(ssq::Table &t)
Register Pcg photo-mode panel bindings.
void registerEditorHostCapabilities()
Registers editor host capabilities.
void exposePcgColorPreviewSyncBindings(ssq::Table &table)
Register Pcg color-preview bindings.
void exposePcgPhotoModeSessionBindings(ssq::Table &table)
Register Pcg photo-mode session bindings.
WidgetDesc badge(std::string label, std::string id)
Compact status/category pill. Tint controls its background color.
Definition Widget.cpp:581
WidgetDesc filledImage(std::string id, float width, float height, float fraction)
Linear filled image; value is a fraction, layout retains width/height at zero fill....
Definition Widget.cpp:466
void exposePcgTooltipBindings(ssq::Table &t)
Register Pcg tooltip bindings.
WidgetDesc checkbox(std::string label, bool checked, std::string id, std::function< void(bool)> onToggle)
Checkbox with a label; fires onToggle.
Definition Widget.cpp:387
Icon
Semantic editor icons backed by the bundled Font Awesome 4.7 font.
Definition Icons.h:11
WidgetDesc tabBar(std::vector< WidgetDesc > children, std::string id)
Horizontal strip of Tab children.
Definition Widget.cpp:728
const std::string & globalThemeName()
Current preset name: "dark", "light", or "custom".
Definition Theme.cpp:279
WidgetDesc combo(std::string label, std::vector< std::string > options, int selected, std::string id, std::function< void(float)> onValue)
Combo.
Definition Widget.cpp:439
WidgetDesc statusBar(std::vector< WidgetDesc > children, std::string id)
Compact horizontal status strip; Spacer children absorb free width.
Definition Widget.cpp:688
WidgetDesc slider(std::string label, float value, float minV, float maxV, std::string id, std::function< void(float)> onValue)
Horizontal slider; fires onValue.
Definition Widget.cpp:399
void exposePcgDraggableWindowBindings(ssq::Table &table)
Register Pcg draggable-window bindings.
WidgetDesc panelFrame(std::string title, std::vector< WidgetDesc > children, std::string id)
Fixed titled panel chrome for dock regions (not a free-floating Window host).
Definition Widget.cpp:767
FlexDirection
Main-axis direction for Flex containers.
Definition UIHost.h:80
void exposePcgPhotoModeValuesBindings(ssq::Table &t)
Register complete Pcg photo-mode value bindings.
void clearStyleClasses()
Clears user-defined style classes. Intended for runtime/test teardown.
Definition Theme.cpp:160
MouseFilter
Pointer event participation and propagation policy.
Definition UIHost.h:107
WidgetDesc imageButton(std::string id, float width, float height, std::function< void()> onClick)
Image button.
Definition Widget.cpp:512
WidgetDesc inputText(std::string label, std::string value, std::string id, std::function< void(const std::string &)> onChange)
Editable text field; fires onTextChange.
Definition Widget.cpp:533
bool setThemeByName(const std::string &name)
Apply a named preset ("dark" / "light"). Case-insensitive. Returns false if unknown.
Definition Theme.cpp:288
void setThemeUiScale(float scale)
Logical (point-space) UI scale. Default 1.0.
Definition Theme.cpp:301
WidgetDesc resourceBar(std::string id, float width, float height, float fraction)
Composes a display-only resource bar; child IDs are /background, /trail, /value and /label....
Definition Widget.cpp:481
void exposePcgLoadingScreenBindings(ssq::Table &table)
Register Pcg loading-screen bindings.
WidgetDesc window(std::string title, std::vector< WidgetDesc > children, std::string id)
Top-level window widget with a title bar.
Definition Widget.cpp:326
bool parseNinePatch(const image::ImageData &source, NinePatchInfo &out, std::string *error)
Parse a raw, uncompiled Android .9.png image.
Definition NinePatch.cpp:55
@ Value
UINode.value (normalized HUD fill)
void bindUIEventSinkOwner(UI *owner) noexcept
Bind the live UI module into the platform event sink. @ownership Borrowed; cleared when the UI module...
Definition EventSink.cpp:40
WidgetDesc spacer(std::string id, float grow)
Flexible empty space; default flexGrow=1 so it absorbs free space in a Flex parent.
Definition Widget.cpp:888
void exposePcgPhotoModeColorPickerBindings(ssq::Table &t)
Register Pcg photo-mode color-picker bindings.
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
StyleClassStatus setStyleClassMetric(const std::string &name, const std::string &property, float x, float y)
Sets padding, rounding, or alpha on an existing style class.
Definition Theme.cpp:128
WidgetDesc toolbar(std::vector< WidgetDesc > children, std::string id)
Horizontal editor command strip; Spacer children absorb free width.
Definition Widget.cpp:655
WidgetDesc menu(std::string label, std::vector< WidgetDesc > children, std::string id)
Popup menu container used inside a MenuBar or another Menu.
Definition Widget.cpp:632
FocusMode
Keyboard/gamepad focus policy for an interactive control.
Definition UIHost.h:101
WidgetDesc skillSlot(std::string id, float size, uint64_t iconTexture, float cooldown, std::string key)
Composes an interactive skill slot; /activate emits clicks, /cooldown is a solid radial overlay....
Definition Widget.cpp:497
FlexJustify
Main-axis distribution of free space in a Flex container.
Definition UIHost.h:92
bool iconFromName(std::string_view name, Icon *out)
Resolves a semantic icon name; accepts kebab-case names case-insensitively.
Definition Icons.cpp:90
const char * styleClassStatusName(StyleClassStatus status)
Stable script-facing spelling of a mutation status.
Definition Theme.cpp:162
WidgetDesc colorPalette(std::string label, float r, float g, float b, float a, std::string id, std::function< void(float)> onValue)
Color editor with a swatch grid (调色板). RGBA is stored in tint channels. valueText may list extra swat...
Definition Widget.cpp:413
WidgetDesc ninePatchPanel(std::vector< WidgetDesc > children, std::string id, uint64_t textureId)
Stretchable textured container with asset-defined content padding.
Definition Widget.cpp:603
void exposeParentScalerBindings(ssq::Table &table)
Register ParentScaler value types and evaluator with the root script table.
void exposePcgPhotoModeRangesBindings(ssq::Table &t)
Register Pcg photo-mode range bindings.
WidgetDesc iconButton(Icon value, std::string label, std::string id, std::function< void()> onClick)
Button containing a semantic icon and optional visible label.
Definition Widget.cpp:357
std::unique_ptr< image::ImageData > stripNinePatchBorder(const image::ImageData &source)
Copy the drawable interior of a parsed .9.png without marker pixels.
WidgetDesc grid(int columns, std::vector< WidgetDesc > children, std::string id)
Fixed-column grid; children are placed in source order.
Definition Widget.cpp:878
ThemePreset
Built-in theme override inherited by a retained UI subtree.
Definition UIHost.h:110
void exposePcgPhotoModeRuntimeUIBindings(ssq::Table &table)
Register Pcg photo-mode runtime UI bindings.
WidgetDesc listButtons(std::string listId, const std::vector< std::string > &items)
Default list: one Button per item, id = listId + "/" + index.
Definition Widget.cpp:919
EVENGINE_API_WORLD void withdrawScriptPhotoModeApplySeam()
撤回接缝与仍然在位的脚本适配器。
WidgetDesc viewport(std::string id, float width, float height)
Viewport.
Definition Widget.cpp:523
WidgetDesc searchField(std::string hint, std::string value, std::string id, std::function< void(const std::string &)> onChange)
Compact search field with placeholder text and a bundled search icon.
Definition Widget.cpp:557
WidgetDesc button(std::string label, std::string id, std::function< void()> onClick)
Clickable button; fires onClick.
Definition Widget.cpp:345
WidgetDesc flex(FlexDirection direction, std::vector< WidgetDesc > children, std::string id)
Elastic layout container (row/column). Prefer row / column shorthands.
Definition Widget.cpp:860
WidgetDesc toggleSwitch(std::string label, bool checked, std::string id, std::function< void(bool)> onToggle)
Modern boolean toggle; fires onToggle when changed.
Definition Widget.cpp:569
WidgetDesc sidebar(std::vector< WidgetDesc > children, std::string id, float width)
Vertical editor side panel. Width defaults to 240 logical pixels.
Definition Widget.cpp:678
double uiTweenWallClockMs()
Wall-clock milliseconds from steady_clock (presentation clock).
Definition UiTween.cpp:115
WidgetDesc card(std::vector< WidgetDesc > children, std::string id)
Bordered surface container with editor-friendly padding.
Definition Widget.cpp:594
OverflowMode
Behavior when arranged children exceed the retained layout box.
Definition UIHost.h:86
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
Theme & globalTheme()
Global theme.
Definition Theme.cpp:277
FlexAlign
Cross-axis alignment of Flex children.
Definition UIHost.h:89
std::unique_ptr< UIBackend > createImGuiBackend()
Default backend: Dear ImGui + SDL + Vulkan (see ui/imgui/).
WidgetDesc toolbox(std::vector< WidgetDesc > children, std::string id, float cellSize, int columns)
Wrapping grid of editor tools with uniform square cells.
Definition Widget.cpp:666
WidgetDesc tab(std::string label, std::string pageId, bool selected, std::string id, std::function< void()> onClick)
Selectable tab label.
Definition Widget.cpp:715
WidgetDesc scrollList(std::string id, std::vector< WidgetDesc > children, float height, float itemHeight)
Scroll list.
Definition Widget.cpp:837
WidgetDesc sectionHeader(std::string label, std::string id)
Non-collapsible editor section heading with an accent marker.
Definition Widget.cpp:614
WidgetDesc separator(std::string id)
Horizontal separator line.
Definition Widget.cpp:379
void exposePcgControllerSelectionBindings(ssq::Table &t)
Register Pcg controller-selection bindings.
AccessibilityRole
Platform-neutral accessibility role exposed by controls.
Definition UIHost.h:129
WidgetDesc sameLine(std::string id)
Holds the next widget on the same line as the previous one.
Definition Widget.cpp:371
void registerUIAutomationCapabilities()
Registers ui automation capabilities.
void exposePcgPhotoModeApplyPlanBindings(ssq::Table &t)
Register Pcg photo-mode application-plan bindings.
StyleClassStatus setStyleClassColor(const std::string &name, const std::string &property, float r, float g, float b, float a)
Sets text/background/border/accent RGBA on an existing style class.
Definition Theme.cpp:99
WidgetDesc dockArea(std::string region, std::vector< WidgetDesc > children, std::string id)
Named dock fill slot; region name is stored in valueText (left/right/top/bottom/center)....
Definition Widget.cpp:780
WidgetDesc radialFill(std::string id, float width, float height, float fraction)
Solid radial cooldown overlay; supports sectors and rings (no texture sampling). @thread UI thread....
Definition Widget.cpp:475
WidgetDesc menuBar(std::vector< WidgetDesc > children, std::string id)
Window menu bar container. Must be a direct child of a Window.
Definition Widget.cpp:623
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
std::optional< std::reference_wrapper< T > > OptionalRef
Optional borrowed reference; it does not extend T's lifetime.
Definition BorrowedRef.h:24
SettlementPipeline::Stage fn
bool enabled
One stable property description consumed by any UI shell.
bool navEnableKeyboard
Definition Theme.h:123
bool navEnableGamepad
Definition Theme.h:124
UIEvent public API.
Definition UISystem.h:24
std::string kind
Definition UISystem.h:29
std::string nodeId
Definition UISystem.h:27
std::string hostName
Definition UISystem.h:26
Retained UI widget node (arena tree). Conceptual counterpart of eve::scene::SceneNode; built declarat...
Definition UIHost.h:151
UIStats public API.
Definition UISystem.h:68
Declarative widget description (build once / on dirty → flatten into UIHost::Tree).
Definition Widget.h:15
std::vector< WidgetDesc > children
Definition Widget.h:129
NodeType type
Definition Widget.h:16
std::string styleClass
Definition Widget.h:40
ThemePreset themePreset
Definition Widget.h:39
Object::Ptr theme
bool resizable
glm::vec4 color