载入中...
搜索中...
未找到
Widget.cpp
浏览该文件的文档.
1#include "ui/Widget.h"
2
3namespace eve::ui {
4namespace {
5
6int appendNode(UIHost::Tree &tree, WidgetDesc &&desc, int parent = -1) {
7 const int index = int(tree.nodes.size());
8 UINode node;
9 node.type = desc.type;
10 node.id = std::move(desc.id);
11 node.key = desc.key.empty() ? node.id : std::move(desc.key);
12 node.text = std::move(desc.text);
13 node.valueText = std::move(desc.valueText);
14 node.tooltip = std::move(desc.tooltip);
15 node.helpText = std::move(desc.helpText);
16 node.disabledReason = std::move(desc.disabledReason);
17 node.placeholder = std::move(desc.placeholder);
18 node.multiline = desc.multiline;
19 node.readOnly = desc.readOnly;
20 node.visible = desc.visible;
21 node.enabled = desc.enabled;
22 node.checked = desc.checked;
23 node.open = desc.open;
24 node.focusMode = desc.focusMode;
25 node.mouseFilter = desc.mouseFilter;
26 node.themePreset = desc.themePreset;
27 node.styleClass = std::move(desc.styleClass);
28 node.hasResolvedStyle =
29 resolveStyleClass(node.styleClass, &node.resolvedStyle) == StyleClassStatus::Applied;
30 node.tabIndex = desc.tabIndex;
31 node.focusNext = std::move(desc.focusNext);
32 node.focusPrevious = std::move(desc.focusPrevious);
33 node.focusLeft = std::move(desc.focusLeft);
34 node.focusRight = std::move(desc.focusRight);
35 node.focusUp = std::move(desc.focusUp);
36 node.focusDown = std::move(desc.focusDown);
37 node.accessibilityRole = desc.accessibilityRole;
38 node.accessibilityName = std::move(desc.accessibilityName);
39 node.accessibilityDescription = std::move(desc.accessibilityDescription);
40 node.dragSource = desc.dragSource;
41 node.dropTarget = desc.dropTarget;
42 node.dragPayloadType = std::move(desc.dragPayloadType);
43 node.dragPayloadText = std::move(desc.dragPayloadText);
44 node.acceptedDropType = std::move(desc.acceptedDropType);
45 node.value = desc.value;
46 node.minValue = desc.minValue;
47 node.maxValue = desc.maxValue;
48 node.sizeX = desc.sizeX;
49 node.sizeY = desc.sizeY;
50 node.marginL = desc.marginL;
51 node.marginT = desc.marginT;
52 node.marginR = desc.marginR;
53 node.marginB = desc.marginB;
54 node.paddingL = desc.paddingL;
55 node.paddingT = desc.paddingT;
56 node.paddingR = desc.paddingR;
57 node.paddingB = desc.paddingB;
58 node.minSizeX = desc.minSizeX;
59 node.minSizeY = desc.minSizeY;
60 node.maxSizeX = desc.maxSizeX;
61 node.maxSizeY = desc.maxSizeY;
62 node.percentW = desc.percentW;
63 node.percentH = desc.percentH;
64 node.aspectRatio = desc.aspectRatio;
65 node.anchorX = desc.anchorX;
66 node.anchorY = desc.anchorY;
67 node.posX = desc.posX;
68 node.posY = desc.posY;
69 node.absolute = desc.absolute;
70 node.textureId = desc.textureId;
71 node.tintR = desc.tintR;
72 node.tintG = desc.tintG;
73 node.tintB = desc.tintB;
74 node.tintA = desc.tintA;
75 node.uv0x = desc.uv0x;
76 node.uv0y = desc.uv0y;
77 node.uv1x = desc.uv1x;
78 node.uv1y = desc.uv1y;
79 node.borderL = desc.borderL;
80 node.borderT = desc.borderT;
81 node.borderR = desc.borderR;
82 node.borderB = desc.borderB;
83 node.fillDirection = desc.fillDirection;
84 node.fillStretch = desc.fillStretch;
85 node.fillStartDegrees = desc.fillStartDegrees;
86 node.fillClockwise = desc.fillClockwise;
87 node.fillInnerRadius = desc.fillInnerRadius;
88 node.cornerRadius = desc.cornerRadius;
89 node.fontSize = desc.fontSize;
90 node.textR = desc.textR;
91 node.textG = desc.textG;
92 node.textB = desc.textB;
93 node.textA = desc.textA;
94 node.textAlignX = desc.textAlignX;
95 node.textAlignY = desc.textAlignY;
96 node.wrapWidth = desc.wrapWidth;
97 node.itemHeight = desc.itemHeight;
98 node.flexDirection = desc.flexDirection;
99 node.alignItems = desc.alignItems;
100 node.justifyContent = desc.justifyContent;
101 node.gap = desc.gap;
102 node.flexGrow = desc.flexGrow;
103 node.flexShrink = desc.flexShrink;
104 node.flexBasis = desc.flexBasis;
105 node.alignSelf = desc.alignSelf;
106 node.columnGap = desc.columnGap;
107 node.rowGap = desc.rowGap;
108 node.flexWrap = desc.flexWrap;
109 node.overflow = desc.overflow;
110 node.gridColumns = desc.gridColumns;
111 node.gridColumnSpan = desc.gridColumnSpan;
112 node.parent = parent;
113 node.firstChild = -1;
114 node.nextSibling = -1;
115 node.handlerClick = 0;
116 node.handlerToggle = 0;
117 node.handlerValue = 0;
118 node.handlerText = 0;
119
120 if (desc.onClick) {
121 tree.clickHandlers.push_back(std::move(desc.onClick));
122 node.handlerClick = static_cast<uint32_t>(tree.clickHandlers.size());
123 }
124 if (desc.onToggle) {
125 tree.toggleHandlers.push_back(std::move(desc.onToggle));
126 node.handlerToggle = static_cast<uint32_t>(tree.toggleHandlers.size());
127 }
128 if (desc.onValue) {
129 tree.valueHandlers.push_back(std::move(desc.onValue));
130 node.handlerValue = static_cast<uint32_t>(tree.valueHandlers.size());
131 }
132 if (desc.onTextChange) {
133 tree.textHandlers.push_back(std::move(desc.onTextChange));
134 node.handlerText = static_cast<uint32_t>(tree.textHandlers.size());
135 }
136
137 tree.nodes.push_back(std::move(node));
138
139 int prevChild = -1;
140 int firstChild = -1;
141 for (auto &child : desc.children) {
142 int childIndex = appendNode(tree, std::move(child), index);
143 if (firstChild < 0) firstChild = childIndex;
144 if (prevChild >= 0) tree.nodes[size_t(prevChild)].nextSibling = childIndex;
145 prevChild = childIndex;
146 }
147 tree.nodes[size_t(index)].firstChild = firstChild;
148 return index;
149}
150
151bool structureMatches(const UIHost::Tree &tree, int nodeIndex, const WidgetDesc &desc) {
152 if (nodeIndex < 0 || nodeIndex >= int(tree.nodes.size())) return false;
153 const UINode &n = tree.nodes[size_t(nodeIndex)];
154 if (n.type != desc.type) return false;
155 const std::string &dk = desc.reconcileKey();
156 if (!dk.empty() && !n.key.empty() && n.key != dk) return false;
157
158 std::vector<std::string> oldKeys;
159 for (int c = n.firstChild; c >= 0; c = tree.nodes[size_t(c)].nextSibling) {
160 oldKeys.push_back(tree.nodes[size_t(c)].key);
161 }
162 if (oldKeys.size() != desc.children.size()) return false;
163 for (size_t i = 0; i < desc.children.size(); ++i) {
164 const std::string &ck = desc.children[i].reconcileKey();
165 if (ck.empty() || oldKeys[i].empty()) {
166 if (!(ck.empty() && oldKeys[i].empty())) return false;
167 } else if (ck != oldKeys[i]) {
168 return false;
169 }
170 }
171
172 int child = n.firstChild;
173 for (const auto &ch : desc.children) {
174 if (!structureMatches(tree, child, ch)) return false;
175 child = tree.nodes[size_t(child)].nextSibling;
176 }
177 return true;
178}
179
180void patchProps(UIHost::Tree &tree, int nodeIndex, WidgetDesc &&desc) {
181 UINode &n = tree.nodes[size_t(nodeIndex)];
182 n.text = std::move(desc.text);
183 n.valueText = std::move(desc.valueText);
184 n.tooltip = std::move(desc.tooltip);
185 n.helpText = std::move(desc.helpText);
186 n.disabledReason = std::move(desc.disabledReason);
187 n.placeholder = std::move(desc.placeholder);
188 n.multiline = desc.multiline;
189 n.readOnly = desc.readOnly;
190 n.visible = desc.visible;
191 n.enabled = desc.enabled;
192 n.checked = desc.checked;
193 n.open = desc.open;
194 n.focusMode = desc.focusMode;
195 n.mouseFilter = desc.mouseFilter;
196 n.themePreset = desc.themePreset;
197 n.styleClass = std::move(desc.styleClass);
198 n.hasResolvedStyle =
199 resolveStyleClass(n.styleClass, &n.resolvedStyle) == StyleClassStatus::Applied;
200 n.tabIndex = desc.tabIndex;
201 n.focusNext = std::move(desc.focusNext);
202 n.focusPrevious = std::move(desc.focusPrevious);
203 n.focusLeft = std::move(desc.focusLeft);
204 n.focusRight = std::move(desc.focusRight);
205 n.focusUp = std::move(desc.focusUp);
206 n.focusDown = std::move(desc.focusDown);
207 n.accessibilityRole = desc.accessibilityRole;
208 n.accessibilityName = std::move(desc.accessibilityName);
209 n.accessibilityDescription = std::move(desc.accessibilityDescription);
210 n.dragSource = desc.dragSource;
211 n.dropTarget = desc.dropTarget;
212 n.dragPayloadType = std::move(desc.dragPayloadType);
213 n.dragPayloadText = std::move(desc.dragPayloadText);
214 n.acceptedDropType = std::move(desc.acceptedDropType);
215 n.value = desc.value;
216 n.minValue = desc.minValue;
217 n.maxValue = desc.maxValue;
218 n.sizeX = desc.sizeX;
219 n.sizeY = desc.sizeY;
220 n.marginL = desc.marginL;
221 n.marginT = desc.marginT;
222 n.marginR = desc.marginR;
223 n.marginB = desc.marginB;
224 n.paddingL = desc.paddingL;
225 n.paddingT = desc.paddingT;
226 n.paddingR = desc.paddingR;
227 n.paddingB = desc.paddingB;
228 n.minSizeX = desc.minSizeX;
229 n.minSizeY = desc.minSizeY;
230 n.maxSizeX = desc.maxSizeX;
231 n.maxSizeY = desc.maxSizeY;
232 n.percentW = desc.percentW;
233 n.percentH = desc.percentH;
234 n.aspectRatio = desc.aspectRatio;
235 n.anchorX = desc.anchorX;
236 n.anchorY = desc.anchorY;
237 n.posX = desc.posX;
238 n.posY = desc.posY;
239 n.absolute = desc.absolute;
240 n.textureId = desc.textureId;
241 n.tintR = desc.tintR;
242 n.tintG = desc.tintG;
243 n.tintB = desc.tintB;
244 n.tintA = desc.tintA;
245 n.uv0x = desc.uv0x;
246 n.uv0y = desc.uv0y;
247 n.uv1x = desc.uv1x;
248 n.uv1y = desc.uv1y;
249 n.borderL = desc.borderL;
250 n.borderT = desc.borderT;
251 n.borderR = desc.borderR;
252 n.borderB = desc.borderB;
253 n.fillDirection = desc.fillDirection;
254 n.fillStretch = desc.fillStretch;
255 n.fillStartDegrees = desc.fillStartDegrees;
256 n.fillClockwise = desc.fillClockwise;
257 n.fillInnerRadius = desc.fillInnerRadius;
258 n.cornerRadius = desc.cornerRadius;
259 n.fontSize = desc.fontSize;
260 n.textR = desc.textR;
261 n.textG = desc.textG;
262 n.textB = desc.textB;
263 n.textA = desc.textA;
264 n.textAlignX = desc.textAlignX;
265 n.textAlignY = desc.textAlignY;
266 n.wrapWidth = desc.wrapWidth;
267 n.itemHeight = desc.itemHeight;
268 n.flexDirection = desc.flexDirection;
269 n.alignItems = desc.alignItems;
270 n.justifyContent = desc.justifyContent;
271 n.gap = desc.gap;
272 n.flexGrow = desc.flexGrow;
273 n.flexShrink = desc.flexShrink;
274 n.flexBasis = desc.flexBasis;
275 n.alignSelf = desc.alignSelf;
276 n.columnGap = desc.columnGap;
277 n.rowGap = desc.rowGap;
278 n.flexWrap = desc.flexWrap;
279 n.overflow = desc.overflow;
280 n.gridColumns = desc.gridColumns;
281 n.gridColumnSpan = desc.gridColumnSpan;
282 if (!desc.id.empty()) n.id = desc.id;
283
284 if (desc.onClick) {
285 if (n.handlerClick != 0) {
286 tree.clickHandlers[size_t(n.handlerClick - 1)] = std::move(desc.onClick);
287 } else {
288 tree.clickHandlers.push_back(std::move(desc.onClick));
289 n.handlerClick = static_cast<uint32_t>(tree.clickHandlers.size());
290 }
291 }
292 if (desc.onToggle) {
293 if (n.handlerToggle != 0) {
294 tree.toggleHandlers[size_t(n.handlerToggle - 1)] = std::move(desc.onToggle);
295 } else {
296 tree.toggleHandlers.push_back(std::move(desc.onToggle));
297 n.handlerToggle = static_cast<uint32_t>(tree.toggleHandlers.size());
298 }
299 }
300 if (desc.onValue) {
301 if (n.handlerValue != 0) {
302 tree.valueHandlers[size_t(n.handlerValue - 1)] = std::move(desc.onValue);
303 } else {
304 tree.valueHandlers.push_back(std::move(desc.onValue));
305 n.handlerValue = static_cast<uint32_t>(tree.valueHandlers.size());
306 }
307 }
308 if (desc.onTextChange) {
309 if (n.handlerText != 0) {
310 tree.textHandlers[size_t(n.handlerText - 1)] = std::move(desc.onTextChange);
311 } else {
312 tree.textHandlers.push_back(std::move(desc.onTextChange));
313 n.handlerText = static_cast<uint32_t>(tree.textHandlers.size());
314 }
315 }
316
317 int child = n.firstChild;
318 for (auto &ch : desc.children) {
319 patchProps(tree, child, std::move(ch));
320 child = tree.nodes[size_t(child)].nextSibling;
321 }
322}
323
324} // namespace
325
326WidgetDesc window(std::string title, std::vector<WidgetDesc> children, std::string id) {
329 d.id = std::move(id);
330 d.key = d.id;
331 d.text = std::move(title);
332 d.children = std::move(children);
333 return d;
334}
335
336WidgetDesc text(std::string content, std::string id) {
339 d.id = std::move(id);
340 d.key = d.id;
341 d.text = std::move(content);
342 return d;
343}
344
345WidgetDesc button(std::string label, std::string id, std::function<void()> onClick) {
348 d.id = std::move(id);
349 d.key = d.id;
350 d.text = std::move(label);
351 d.onClick = std::move(onClick);
352 return d;
353}
354
355WidgetDesc icon(Icon value, std::string id) { return text(iconGlyph(value), std::move(id)); }
356
357WidgetDesc iconButton(Icon value, std::string label, std::string id,
358 std::function<void()> onClick) {
359 return button(iconText(value, label), std::move(id), std::move(onClick));
360}
361
362WidgetDesc group(std::vector<WidgetDesc> children, std::string id) {
365 d.id = std::move(id);
366 d.key = d.id;
367 d.children = std::move(children);
368 return d;
369}
370
371WidgetDesc sameLine(std::string id) {
374 d.id = std::move(id);
375 d.key = d.id;
376 return d;
377}
378
379WidgetDesc separator(std::string id) {
382 d.id = std::move(id);
383 d.key = d.id;
384 return d;
385}
386
387WidgetDesc checkbox(std::string label, bool checked, std::string id,
388 std::function<void(bool)> onToggle) {
391 d.id = std::move(id);
392 d.key = d.id;
393 d.text = std::move(label);
394 d.checked = checked;
395 d.onToggle = std::move(onToggle);
396 return d;
397}
398
399WidgetDesc slider(std::string label, float value, float minV, float maxV, std::string id,
400 std::function<void(float)> onValue) {
403 d.id = std::move(id);
404 d.key = d.id;
405 d.text = std::move(label);
406 d.value = value;
407 d.minValue = minV;
408 d.maxValue = maxV;
409 d.onValue = std::move(onValue);
410 return d;
411}
412
413WidgetDesc colorPalette(std::string label, float r, float g, float b, float a, std::string id,
414 std::function<void(float)> onValue) {
417 d.id = std::move(id);
418 d.key = d.id;
419 d.text = std::move(label);
420 d.tintR = r;
421 d.tintG = g;
422 d.tintB = b;
423 d.tintA = a;
424 d.accessibilityRole = AccessibilityRole::Slider;
425 d.onValue = std::move(onValue);
426 return d;
427}
428
429WidgetDesc progress(float fraction, std::string id, std::string overlay) {
432 d.id = std::move(id);
433 d.key = d.id;
434 d.value = fraction;
435 d.text = std::move(overlay);
436 return d;
437}
438
439WidgetDesc combo(std::string label, std::vector<std::string> options, int selected,
440 std::string id, std::function<void(float)> onValue) {
443 d.id = std::move(id);
444 d.key = d.id;
445 d.text = std::move(label);
446 d.value = float(std::max(0, selected));
447 for (size_t i = 0; i < options.size(); ++i) {
448 if (i) d.valueText += '\n';
449 d.valueText += options[i];
450 }
451 d.onValue = std::move(onValue);
452 return d;
453}
454
455WidgetDesc image(std::string id, float width, float height, std::function<void()> onClick) {
458 d.id = std::move(id);
459 d.key = d.id;
460 d.sizeX = width;
461 d.sizeY = height;
462 d.onClick = std::move(onClick);
463 return d;
464}
465
466WidgetDesc filledImage(std::string id, float width, float height, float fraction) {
467 auto result = image(std::move(id), width, height);
469 result.value = fraction;
470 result.mouseFilter = MouseFilter::Ignore;
471 result.focusMode = FocusMode::None;
472 return result;
473}
474
475WidgetDesc radialFill(std::string id, float width, float height, float fraction) {
476 auto result = filledImage(std::move(id), width, height, fraction);
478 return result;
479}
480
481WidgetDesc resourceBar(std::string id, float width, float height, float fraction) {
482 auto background = image(id + "/background", width, height).withTint(.08f, .10f, .15f, 1.f).withAbsolute(0.f, 0.f);
483 auto trail =
484 filledImage(id + "/trail", width, height, fraction).withTint(.95f, .60f, .20f, 1.f).withAbsolute(0.f, 0.f);
485 auto value =
486 filledImage(id + "/value", width, height, fraction).withTint(.20f, .80f, .50f, 1.f).withAbsolute(0.f, 0.f);
487 auto label = text("", id + "/label").withSize(width, height).withAbsolute(0.f, 0.f);
488 label.fontSize = 14.f;
489 label.textAlignX = .5f;
490 label.textAlignY = .5f;
491 return row({std::move(background), std::move(trail), std::move(value), std::move(label)}, std::move(id))
492 .withSize(width, height)
495}
496
497WidgetDesc skillSlot(std::string id, float size, uint64_t iconTexture, float cooldown, std::string key) {
498 auto activate = imageButton(id + "/activate", size, size).withAbsolute(0.f, 0.f);
499 activate.textureId = iconTexture;
500 activate.tooltip = key;
501 auto mask =
502 radialFill(id + "/cooldown", size, size, cooldown).withTint(.02f, .03f, .06f, .80f).withAbsolute(0.f, 0.f);
503 auto label = text(std::move(key), id + "/key").withSize(size, size).withAbsolute(0.f, 0.f);
504 label.fontSize = 16.f;
505 label.textAlignX = .5f;
506 label.textAlignY = .5f;
507 label.mouseFilter = MouseFilter::Ignore;
508 label.focusMode = FocusMode::None;
509 return row({std::move(activate), std::move(mask), std::move(label)}, std::move(id)).withSize(size, size);
510}
511
512WidgetDesc imageButton(std::string id, float width, float height, std::function<void()> onClick) {
515 d.id = std::move(id);
516 d.key = d.id;
517 d.sizeX = width;
518 d.sizeY = height;
519 d.onClick = std::move(onClick);
520 return d;
521}
522
523WidgetDesc viewport(std::string id, float width, float height) {
526 d.id = std::move(id);
527 d.key = d.id;
528 d.sizeX = width;
529 d.sizeY = height;
530 return d;
531}
532
533WidgetDesc inputText(std::string label, std::string value, std::string id,
534 std::function<void(const std::string &)> onChange) {
537 d.id = std::move(id);
538 d.key = d.id;
539 d.text = std::move(label);
540 d.valueText = std::move(value);
541 d.onTextChange = std::move(onChange);
542 return d;
543}
544
545WidgetDesc link(std::string label, std::string target, std::string id, std::function<void()> onClick) {
548 d.accessibilityRole = AccessibilityRole::Link;
549 d.text = std::move(label);
550 d.valueText = std::move(target);
551 d.id = std::move(id);
552 d.key = d.id;
553 d.onClick = std::move(onClick);
554 return d;
555}
556
557WidgetDesc searchField(std::string hint, std::string value, std::string id,
558 std::function<void(const std::string &)> onChange) {
561 d.id = std::move(id);
562 d.key = d.id;
563 d.text = std::move(hint);
564 d.valueText = std::move(value);
565 d.onTextChange = std::move(onChange);
566 return d;
567}
568
569WidgetDesc toggleSwitch(std::string label, bool checked, std::string id,
570 std::function<void(bool)> onToggle) {
573 d.id = std::move(id);
574 d.key = d.id;
575 d.text = std::move(label);
576 d.checked = checked;
577 d.onToggle = std::move(onToggle);
578 return d;
579}
580
581WidgetDesc badge(std::string label, std::string id) {
584 d.id = std::move(id);
585 d.key = d.id;
586 d.text = std::move(label);
587 d.tintR = 0.96f;
588 d.tintG = 0.35f;
589 d.tintB = 0.40f;
590 d.tintA = 0.20f;
591 return d;
592}
593
594WidgetDesc card(std::vector<WidgetDesc> children, std::string id) {
597 d.id = std::move(id);
598 d.key = d.id;
599 d.children = std::move(children);
600 return d;
601}
602
603WidgetDesc ninePatchPanel(std::vector<WidgetDesc> children, std::string id,
604 uint64_t textureId) {
607 d.id = std::move(id);
608 d.key = d.id;
609 d.textureId = textureId;
610 d.children = std::move(children);
611 return d;
612}
613
614WidgetDesc sectionHeader(std::string label, std::string id) {
617 d.id = std::move(id);
618 d.key = d.id;
619 d.text = std::move(label);
620 return d;
621}
622
623WidgetDesc menuBar(std::vector<WidgetDesc> children, std::string id) {
626 d.id = std::move(id);
627 d.key = d.id;
628 d.children = std::move(children);
629 return d;
630}
631
632WidgetDesc menu(std::string label, std::vector<WidgetDesc> children, std::string id) {
635 d.id = std::move(id);
636 d.key = d.id;
637 d.text = std::move(label);
638 d.children = std::move(children);
639 return d;
640}
641
642WidgetDesc menuItem(std::string label, std::string shortcut, std::string id,
643 std::function<void()> onClick, bool selected) {
646 d.id = std::move(id);
647 d.key = d.id;
648 d.text = std::move(label);
649 d.valueText = std::move(shortcut);
650 d.checked = selected;
651 d.onClick = std::move(onClick);
652 return d;
653}
654
655WidgetDesc toolbar(std::vector<WidgetDesc> children, std::string id) {
658 d.id = std::move(id);
659 d.key = d.id;
660 d.flexDirection = FlexDirection::Row;
661 d.alignItems = FlexAlign::Center;
662 d.children = std::move(children);
663 return d;
664}
665
666WidgetDesc toolbox(std::vector<WidgetDesc> children, std::string id, float cellSize,
667 int columns) {
670 d.id = std::move(id);
671 d.key = d.id;
672 d.itemHeight = cellSize > 0.f ? cellSize : 40.f;
673 d.value = float(std::max(0, columns));
674 d.children = std::move(children);
675 return d;
676}
677
678WidgetDesc sidebar(std::vector<WidgetDesc> children, std::string id, float width) {
681 d.id = std::move(id);
682 d.key = d.id;
683 d.sizeX = width;
684 d.children = std::move(children);
685 return d;
686}
687
688WidgetDesc statusBar(std::vector<WidgetDesc> children, std::string id) {
691 d.id = std::move(id);
692 d.key = d.id;
693 d.flexDirection = FlexDirection::Row;
694 d.alignItems = FlexAlign::Center;
695 d.children = std::move(children);
696 return d;
697}
698
700 std::string id, std::function<void(float)> onResize) {
703 d.id = std::move(id);
704 d.key = d.id;
705 d.flexDirection = direction;
706 d.value = std::max(0.1f, std::min(0.9f, ratio));
707 d.minValue = 0.1f;
708 d.maxValue = 0.9f;
709 d.onValue = std::move(onResize);
710 d.children.push_back(std::move(first));
711 d.children.push_back(std::move(second));
712 return d;
713}
714
715WidgetDesc tab(std::string label, std::string pageId, bool selected, std::string id, std::function<void()> onClick) {
718 d.id = id.empty() ? ("tab/" + pageId) : std::move(id);
719 d.key = d.id;
720 d.text = std::move(label);
721 d.valueText = std::move(pageId);
722 d.checked = selected;
723 d.accessibilityRole = AccessibilityRole::Tab;
724 d.onClick = std::move(onClick);
725 return d;
726}
727
728WidgetDesc tabBar(std::vector<WidgetDesc> children, std::string id) {
731 d.id = std::move(id);
732 d.key = d.id;
733 d.flexDirection = FlexDirection::Row;
734 d.alignItems = FlexAlign::Center;
735 d.children = std::move(children);
736 return d;
737}
738
739WidgetDesc tabContainer(std::vector<WidgetDesc> pages, std::string activePageId, std::string id,
740 std::function<void(const std::string &)> onSelect) {
743 d.id = std::move(id);
744 d.key = d.id;
745 d.valueText = std::move(activePageId);
746 d.flexDirection = FlexDirection::Column;
747 d.flexGrow = 1.f;
748 d.onTextChange = std::move(onSelect);
749
750 std::vector<WidgetDesc> tabs;
751 tabs.reserve(pages.size());
752 if (d.valueText.empty() && !pages.empty()) {
753 d.valueText = pages.front().id.empty() ? pages.front().key : pages.front().id;
754 }
755 for (auto &page : pages) {
756 const std::string pageId = page.id.empty() ? page.key : page.id;
757 const std::string label = page.text.empty() ? pageId : page.text;
758 const bool selected = !d.valueText.empty() && pageId == d.valueText;
759 page.visible = selected;
760 tabs.push_back(tab(label, pageId, selected));
761 }
762 d.children.push_back(tabBar(std::move(tabs), d.id.empty() ? "tabs" : d.id + "/bar"));
763 for (auto &page : pages) d.children.push_back(std::move(page));
764 return d;
765}
766
767WidgetDesc panelFrame(std::string title, std::vector<WidgetDesc> children, std::string id) {
770 d.id = std::move(id);
771 d.key = d.id;
772 d.text = std::move(title);
773 d.flexDirection = FlexDirection::Column;
774 d.flexGrow = 1.f;
775 d.overflow = OverflowMode::Clip;
776 d.children = std::move(children);
777 return d;
778}
779
780WidgetDesc dockArea(std::string region, std::vector<WidgetDesc> children, std::string id) {
783 d.id = id.empty() ? ("dock/" + region) : std::move(id);
784 d.key = d.id;
785 d.valueText = std::move(region);
786 d.flexDirection = FlexDirection::Column;
787 d.flexGrow = 1.f;
788 d.overflow = OverflowMode::Clip;
789 d.children = std::move(children);
790 return d;
791}
792
793WidgetDesc appFrame(WidgetDesc body, WidgetDesc toolbarWidget, WidgetDesc statusBarWidget, std::string id) {
796 d.id = std::move(id);
797 d.key = d.id;
798 d.flexDirection = FlexDirection::Column;
799 d.flexGrow = 1.f;
800 d.percentW = 1.f;
801 d.percentH = 1.f;
802 if (toolbarWidget.type == NodeType::Toolbar || !toolbarWidget.children.empty() || !toolbarWidget.id.empty()) {
803 d.children.push_back(std::move(toolbarWidget));
804 }
805 body.flexGrow = std::max(body.flexGrow, 1.f);
806 d.children.push_back(std::move(body));
807 if (statusBarWidget.type == NodeType::StatusBar || !statusBarWidget.children.empty() ||
808 !statusBarWidget.id.empty()) {
809 d.children.push_back(std::move(statusBarWidget));
810 }
811 return d;
812}
813
814WidgetDesc collapsingHeader(std::string label, std::vector<WidgetDesc> children, std::string id,
815 bool defaultOpen) {
818 d.id = std::move(id);
819 d.key = d.id;
820 d.text = std::move(label);
821 d.open = defaultOpen;
822 d.children = std::move(children);
823 return d;
824}
825
826WidgetDesc child(std::string id, std::vector<WidgetDesc> children, float width, float height) {
829 d.id = std::move(id);
830 d.key = d.id;
831 d.sizeX = width;
832 d.sizeY = height;
833 d.children = std::move(children);
834 return d;
835}
836
837WidgetDesc scrollList(std::string id, std::vector<WidgetDesc> children, float height,
838 float itemHeight) {
841 d.id = std::move(id);
842 d.key = d.id;
843 d.sizeY = height;
844 d.itemHeight = itemHeight;
845 d.children = std::move(children);
846 return d;
847}
848
849WidgetDesc virtualList(std::string listId, const std::vector<std::string> &items, float height,
850 float itemHeight) {
851 const std::string lid = listId;
852 WidgetDesc inner = list(std::move(listId), items,
853 [lid](const std::string &label, int i) {
854 return button(label, lid + "/" + std::to_string(i))
855 .withKey(lid + "/" + std::to_string(i));
856 });
857 return scrollList(lid, std::move(inner.children), height, itemHeight);
858}
859
860WidgetDesc flex(FlexDirection direction, std::vector<WidgetDesc> children, std::string id) {
863 d.id = std::move(id);
864 d.key = d.id;
865 d.flexDirection = direction;
866 d.children = std::move(children);
867 return d;
868}
869
870WidgetDesc row(std::vector<WidgetDesc> children, std::string id) {
871 return flex(FlexDirection::Row, std::move(children), std::move(id));
872}
873
874WidgetDesc column(std::vector<WidgetDesc> children, std::string id) {
875 return flex(FlexDirection::Column, std::move(children), std::move(id));
876}
877
878WidgetDesc grid(int columns, std::vector<WidgetDesc> children, std::string id) {
881 d.id = std::move(id);
882 d.key = d.id;
883 d.gridColumns = std::max(1, columns);
884 d.children = std::move(children);
885 return d;
886}
887
888WidgetDesc spacer(std::string id, float grow) {
891 d.id = std::move(id);
892 d.key = d.id;
893 d.flexGrow = grow > 0.f ? grow : 1.f;
894 return d;
895}
896
898 if (!cond) return group({}, "__when_empty");
899 return child;
900}
901
902WidgetDesc whenElse(bool cond, WidgetDesc ifTrue, WidgetDesc ifFalse) {
903 return cond ? std::move(ifTrue) : std::move(ifFalse);
904}
905
906WidgetDesc list(std::string listId, const std::vector<std::string> &items,
907 const std::function<WidgetDesc(const std::string &, int)> &itemFn) {
908 std::vector<WidgetDesc> children;
909 children.reserve(items.size());
910 for (int i = 0; i < int(items.size()); ++i) {
911 WidgetDesc row = itemFn(items[size_t(i)], i);
912 if (row.id.empty()) row.id = listId + "/" + std::to_string(i);
913 if (row.key.empty()) row.key = row.id;
914 children.push_back(std::move(row));
915 }
916 return group(std::move(children), std::move(listId));
917}
918
919WidgetDesc listButtons(std::string listId, const std::vector<std::string> &items) {
920 std::string lid = listId;
921 return list(std::move(listId), items, [lid](const std::string &label, int i) {
922 return button(label, lid + "/" + std::to_string(i)).withKey(lid + "/" + std::to_string(i));
923 });
924}
925
927 if (!host) return;
928 auto t = host->tree();
929 ++t->generation;
930 t->nodes.clear();
931 t->clickHandlers.clear();
932 t->toggleHandlers.clear();
933 t->valueHandlers.clear();
934 t->textHandlers.clear();
935 t->root = -1;
936 t->root = appendNode(*t, std::move(root));
937 t->dirty = true;
938}
939
941 if (!host) return true;
942 auto t = host->tree();
943 if (t->root < 0 || t->nodes.empty() || !structureMatches(*t, t->root, root)) {
944 applyTree(host, std::move(root));
945 return true;
946 }
947 patchProps(*t, t->root, std::move(root));
948 t->dirty = false;
949 return false;
950}
951
952} // namespace eve::ui
LogicalId target
int root
Definition AnimSmr.cpp:119
std::string selected
int mask
std::string title
SQObjectPtr key
Definition ECS.cpp:155
scene::NodeDesc desc
ScriptFieldRegion region
tensor::Graph g
Definition GpuGraph.cpp:7
vk::UniqueImage image
glm::vec3 n
Definition Grass.cpp:63
double r
std::int32_t second
std::int32_t c
std::int32_t first
Icon icon
Definition Icons.cpp:11
std::uint32_t height
std::uint32_t width
float ratio
PhysicsJointLink link
const ColourScope * parent
std::string label
Poco::JSON::Object::Ptr result
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
std::string body
Object::Ptr value
float d
float t
const RoadNode * node
RoadLaneDirection direction
std::string text
unsigned column
const SquirrelValueOptions & options
AbilityActivationGroup group
int columns
int children
Definition TreeMesh.cpp:432
float size
Definition TreeMesh.cpp:158
UIHostHandle host
uint32_t index
float fraction
ECS mount point for one UI panel/screen. Subclass to attach UI to game entities, e....
Definition UIHost.h:284
WidgetDesc collapsingHeader(std::string label, std::vector< WidgetDesc > children, std::string id, bool defaultOpen)
Collapsible header containing child widgets.
Definition Widget.cpp:814
const char * iconGlyph(Icon icon)
Returns the UTF-8 glyph for an icon, or an empty string for None.
Definition Icons.cpp:86
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
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
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
std::string iconText(Icon icon, std::string_view label)
Composes an icon with an optional visible label.
Definition Icons.cpp:101
WidgetDesc tabBar(std::vector< WidgetDesc > children, std::string id)
Horizontal strip of Tab children.
Definition Widget.cpp:728
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
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
void applyTree(UIHost *host, WidgetDesc root)
Full replace flatten.
Definition Widget.cpp:926
FlexDirection
Main-axis direction for Flex containers.
Definition UIHost.h:80
WidgetDesc whenElse(bool cond, WidgetDesc ifTrue, WidgetDesc ifFalse)
When else.
Definition Widget.cpp:902
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
WidgetDesc tabContainer(std::vector< WidgetDesc > pages, std::string activePageId, std::string id, std::function< void(const std::string &)> onSelect)
Tab strip plus page bodies; only the active page is visible.
Definition Widget.cpp:739
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
WidgetDesc window(std::string title, std::vector< WidgetDesc > children, std::string id)
Top-level window widget with a title bar.
Definition Widget.cpp:326
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
WidgetDesc child(std::string id, std::vector< WidgetDesc > children, float width, float height)
Scrollable child region with an explicit size.
Definition Widget.cpp:826
WidgetDesc when(bool cond, WidgetDesc child)
Conditional: include child only when cond is true (empty group otherwise).
Definition Widget.cpp:897
WidgetDesc appFrame(WidgetDesc body, WidgetDesc toolbarWidget, WidgetDesc statusBarWidget, std::string id)
Fixed editor frame: optional toolbar, growing body, optional status bar. Place as a Window child (Men...
Definition Widget.cpp:793
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
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
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
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
WidgetDesc grid(int columns, std::vector< WidgetDesc > children, std::string id)
Fixed-column grid; children are placed in source order.
Definition Widget.cpp:878
WidgetDesc listButtons(std::string listId, const std::vector< std::string > &items)
Default list: one Button per item, id = listId + "/" + index.
Definition Widget.cpp:919
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
StyleClassStatus resolveStyleClass(const std::string &name, StyleClass *out)
Resolves inheritance into a sparse class and reports an explicit lookup status.
Definition Theme.cpp:150
WidgetDesc card(std::vector< WidgetDesc > children, std::string id)
Bordered surface container with editor-friendly padding.
Definition Widget.cpp:594
bool applyTreeReconcile(UIHost *host, WidgetDesc root)
Patch by key/id when structure (type + child keys) matches; otherwise full replace....
Definition Widget.cpp:940
WidgetDesc row(std::vector< WidgetDesc > children, std::string id)
Horizontal elastic layout row.
Definition Widget.cpp:870
WidgetDesc virtualList(std::string listId, const std::vector< std::string > &items, float height, float itemHeight)
Virtual list.
Definition Widget.cpp:849
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 splitPane(FlexDirection direction, WidgetDesc first, WidgetDesc second, float ratio, std::string id, std::function< void(float)> onResize)
Two resizable panes separated by a drag handle.
Definition Widget.cpp:699
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
WidgetDesc sameLine(std::string id)
Holds the next widget on the same line as the previous one.
Definition Widget.cpp:371
WidgetDesc list(std::string listId, const std::vector< std::string > &items, const std::function< WidgetDesc(const std::string &, int)> &itemFn)
Expand a string list into a Group of item widgets. itemFn(label, index) builds each row; keys default...
Definition Widget.cpp:906
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
Declarative widget description (build once / on dirty → flatten into UIHost::Tree).
Definition Widget.h:15
std::vector< WidgetDesc > children
Definition Widget.h:129
uint64_t textureId
Definition Widget.h:83
NodeType type
Definition Widget.h:16
std::string key
Reconciliation key; defaults to id when empty.
Definition Widget.h:19
WidgetDesc & withAbsolute(float ax, float ay, float x=0.f, float y=0.f)
With absolute.
Definition Widget.h:308
WidgetDesc & withMouseFilter(MouseFilter v)
Selects whether pointer input stops, passes through, or ignores this widget.
Definition Widget.h:185
WidgetDesc & withTint(float r, float g, float b, float a=1.f)
With tint.
Definition Widget.h:317
WidgetDesc & withSize(float w, float h)
With size.
Definition Widget.h:257
std::string text
Definition Widget.h:20
WidgetDesc & withKey(std::string v)
With key.
Definition Widget.h:137
std::string id
Definition Widget.h:17
WidgetDesc & withFocusMode(FocusMode v)
Selects how the widget participates in keyboard focus navigation.
Definition Widget.h:180