载入中...
搜索中...
未找到
UiPreview.cpp
浏览该文件的文档.
1#include <algorithm>
2#include <cmath>
3#include <cstring>
4#include <functional>
5#include <map>
6#include <utility>
7#include "ui/Theme.h"
11
12// UiPreview.cpp
13namespace eve::ui_editing {
14
17 result.documentRevision = document.revision();
18 result.viewportWidth = width;
19 result.viewportHeight = height;
20 if (!std::isfinite(width) || !std::isfinite(height) || width <= 0.0 || height <= 0.0) {
21 result.diagnostics.push_back(eve::editing::ruleDiagnostic(
22 eve::DiagnosticCode::InvalidArgument, RuleId("editor.ui.invalid-preview-viewport"),
23 DiagnosticSeverity::Error, "UI preview viewport must have finite positive dimensions"));
24 return result;
25 }
26 result.diagnostics = document.validate();
27 std::map<ObjectId, UiPreviewWidget> computed;
28 std::function<void(const ObjectId&, const UiPreviewWidget&, int)> visit;
29 visit = [&](const ObjectId& id, const UiPreviewWidget& parent, int depth) {
30 auto value = document.widget(id);
31 if (!value.ok()) return;
32 const UiWidgetSnapshot& widget = value.value();
33 const double contentX = parent.x + widget.style.marginLeft + (depth == 0 ? 0.0 : 0.0);
34 const double contentY = parent.y + widget.style.marginTop;
35 const double parentWidth = std::max(0.0, parent.width - widget.style.marginLeft - widget.style.marginRight);
36 const double parentHeight = std::max(0.0, parent.height - widget.style.marginTop - widget.style.marginBottom);
37 UiPreviewWidget preview;
38 preview.id = widget.id;
39 preview.parent = widget.parent;
40 preview.depth = depth;
41 preview.width = widget.layout.width;
42 preview.height = widget.layout.height;
43 preview.x =
44 contentX + parentWidth * widget.layout.anchorX + widget.layout.x - preview.width * widget.layout.pivotX;
45 preview.y =
46 contentY + parentHeight * widget.layout.anchorY + widget.layout.y - preview.height * widget.layout.pivotY;
47 preview.visible = widget.visible && parent.visible;
48 computed[id] = preview;
49 result.widgets.push_back(preview);
50 UiPreviewWidget childParent = preview;
51 childParent.x += widget.style.paddingLeft;
52 childParent.y += widget.style.paddingTop;
53 childParent.width = std::max(0.0, childParent.width - widget.style.paddingLeft - widget.style.paddingRight);
54 childParent.height = std::max(0.0, childParent.height - widget.style.paddingTop - widget.style.paddingBottom);
55 for (const ObjectId& child : document.children(id)) visit(child, childParent, depth + 1);
56 };
57 const UiPreviewWidget viewport{ObjectId(), ObjectId(), 0.0, 0.0, width, height, -1, true};
58 for (const ObjectId& root : document.children(ObjectId())) visit(root, viewport, 0);
59 const bool hasError = std::any_of(
60 result.diagnostics.begin(), result.diagnostics.end(),
61 [](const EditorDiagnostic& diagnostic) { return diagnostic.severity() == DiagnosticSeverity::Error; });
62 result.status = hasError ? EditorStatus::Failed : EditorStatus::Applied;
63 return result;
64}
65
67 if (!std::isfinite(x) || !std::isfinite(y))
68 return eve::editing::failed<ObjectId>(EditorStatus::Rejected, RuleId("editor.ui.invalid-pick-point"),
69 "UI pick coordinates must be finite");
70 const UiPreviewWidget* best = nullptr;
71 for (const UiPreviewWidget& widget : preview.widgets) {
72 if (!widget.visible || x < widget.x || y < widget.y || x > widget.x + widget.width ||
73 y > widget.y + widget.height)
74 continue;
75 if (!best || widget.depth > best->depth || (widget.depth == best->depth && widget.id > best->id))
76 best = &widget;
77 }
78 if (!best)
79 return eve::editing::failed<ObjectId>(EditorStatus::NotFound, RuleId("editor.ui.pick-miss"),
80 "No visible widget contains the preview point");
81 return eve::editing::applied<ObjectId>(best->id);
82}
83
85 const UiPreviewSnapshot& preview, const ObjectId& id) const {
86 if (preview.documentRevision != document.revision())
87 return eve::editing::failed<EditorValue>(EditorStatus::Conflict, RuleId("editor.ui.stale-preview"),
88 "UI preview revision no longer matches the document");
89 auto widget = document.widget(id);
90 if (!widget.ok())
91 return eve::editing::failed<EditorValue>(EditorStatus::NotFound, RuleId("editor.ui.widget-not-found"),
92 "UI widget does not exist");
93 double parentX = 0.0, parentY = 0.0, parentW = preview.viewportWidth, parentH = preview.viewportHeight;
94 if (!widget.value().parent.empty()) {
95 const auto parent =
96 std::find_if(preview.widgets.begin(), preview.widgets.end(),
97 [&](const UiPreviewWidget& value) { return value.id == widget.value().parent; });
98 if (parent == preview.widgets.end())
99 return eve::editing::failed<EditorValue>(EditorStatus::NotFound,
100 RuleId("editor.ui.preview-parent-not-found"),
101 "Parent is absent from UI preview");
102 auto parentWidget = document.widget(parent->id);
103 parentX = parent->x + parentWidget.value().style.paddingLeft;
104 parentY = parent->y + parentWidget.value().style.paddingTop;
105 parentW = std::max(
106 0.0, parent->width - parentWidget.value().style.paddingLeft - parentWidget.value().style.paddingRight);
107 parentH = std::max(
108 0.0, parent->height - parentWidget.value().style.paddingTop - parentWidget.value().style.paddingBottom);
109 }
110 const auto previewWidget = std::find_if(preview.widgets.begin(), preview.widgets.end(),
111 [&](const UiPreviewWidget& value) { return value.id == id; });
112 if (previewWidget == preview.widgets.end())
113 return eve::editing::failed<EditorValue>(EditorStatus::NotFound, RuleId("editor.ui.preview-widget-not-found"),
114 "Widget is absent from UI preview");
115 const double anchorX = parentX + parentW * widget.value().layout.anchorX;
116 const double anchorY = parentY + parentH * widget.value().layout.anchorY;
117 const double pivotX = previewWidget->x + previewWidget->width * widget.value().layout.pivotX;
118 const double pivotY = previewWidget->y + previewWidget->height * widget.value().layout.pivotY;
119 return eve::editing::applied<EditorValue>(
120 EditorValue::Object{{"anchor", EditorValue::Array{anchorX, anchorY}},
121 {"pivot", EditorValue::Array{pivotX, pivotY}},
122 {"line", EditorValue::Array{anchorX, anchorY, pivotX, pivotY}}});
123}
124
125} // namespace eve::ui_editing
126
127// UiThemePreview.cpp
128namespace eve::ui_editing {
129namespace {
130
131EditorDiagnostic previewDiagnostic(const char* rule, std::string message) {
133 DiagnosticSeverity::Error, std::move(message));
134}
135
136} // namespace
137
139 Revision expectedRevision) const {
141 snapshot.documentRevision = catalog.revision();
142 snapshot.themeId = themeId;
143 if (expectedRevision != catalog.revision()) {
144 snapshot.status = EditorStatus::Conflict;
145 snapshot.diagnostics.push_back(
146 previewDiagnostic("editor.ui-theme.stale-preview", "Theme preview requires the current catalog revision"));
147 return snapshot;
148 }
149 auto asset = catalog.theme(themeId);
150 if (!asset.ok()) {
151 snapshot.status = EditorStatus::NotFound;
152 snapshot.diagnostics.insert(snapshot.diagnostics.end(), asset.status().diagnostics().begin(),
153 asset.status().diagnostics().end());
154 return snapshot;
155 }
156 snapshot.theme = asset.value().tokens;
157 snapshot.runtimeName = catalog.runtimeName(themeId);
158 snapshot.status = EditorStatus::Applied;
159 return snapshot;
160}
161
163 auto asset = catalog.theme(catalog.activeId());
164 if (!asset.ok()) return Result<void>::failure(asset.status());
165 auto diagnostics = validateThemeTokens(asset.value().tokens);
166 if (!diagnostics.empty())
167 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.ui-theme.publish"),
168 "Active theme tokens are invalid");
169 ui::setGlobalTheme(asset.value().tokens, catalog.runtimeName(catalog.activeId()));
170 return eve::editing::applied<void>();
171}
172
173} // namespace eve::ui_editing
174
175// UiThemeTokens.cpp
176namespace eve::ui_editing {
177namespace {
178
179EditorDiagnostic tokenDiagnostic(const char* rule, std::string message) {
180 return eve::editing::ruleDiagnostic(eve::DiagnosticCode::InvalidArgument, RuleId(rule), DiagnosticSeverity::Error,
181 std::move(message));
182}
183
184struct ColorTok {
185 const char* path;
186 float (ui::Theme::*member)[4];
187};
188
189struct FloatTok {
190 const char* path;
191 float ui::Theme::*member;
192 float minimum;
193 float maximum;
194 const char* category;
195};
196
197struct LayoutTok {
198 const char* path;
199 float ui::ThemeLayout::*member;
200 float minimum;
201 float maximum;
202};
203
204const ColorTok kColors[] = {
205 {"color.text", &ui::Theme::text},
206 {"color.textDisabled", &ui::Theme::textDisabled},
207 {"color.windowBg", &ui::Theme::windowBg},
208 {"color.childBg", &ui::Theme::childBg},
209 {"color.popupBg", &ui::Theme::popupBg},
210 {"color.border", &ui::Theme::border},
211 {"color.borderShadow", &ui::Theme::borderShadow},
212 {"color.frameBg", &ui::Theme::frameBg},
213 {"color.frameBgHovered", &ui::Theme::frameBgHovered},
214 {"color.frameBgActive", &ui::Theme::frameBgActive},
215 {"color.titleBg", &ui::Theme::titleBg},
216 {"color.titleBgActive", &ui::Theme::titleBgActive},
217 {"color.titleBgCollapsed", &ui::Theme::titleBgCollapsed},
218 {"color.menuBarBg", &ui::Theme::menuBarBg},
219 {"color.button", &ui::Theme::button},
220 {"color.buttonHovered", &ui::Theme::buttonHovered},
221 {"color.buttonActive", &ui::Theme::buttonActive},
222 {"color.header", &ui::Theme::header},
223 {"color.headerHovered", &ui::Theme::headerHovered},
224 {"color.headerActive", &ui::Theme::headerActive},
225 {"color.checkMark", &ui::Theme::checkMark},
226 {"color.sliderGrab", &ui::Theme::sliderGrab},
227 {"color.sliderGrabActive", &ui::Theme::sliderGrabActive},
228 {"color.separator", &ui::Theme::separator},
229 {"color.scrollbarBg", &ui::Theme::scrollbarBg},
230 {"color.scrollbarGrab", &ui::Theme::scrollbarGrab},
231 {"color.scrollbarGrabHovered", &ui::Theme::scrollbarGrabHovered},
232 {"color.scrollbarGrabActive", &ui::Theme::scrollbarGrabActive},
233 {"color.tab", &ui::Theme::tab},
234 {"color.tabHovered", &ui::Theme::tabHovered},
235 {"color.tabActive", &ui::Theme::tabActive},
236 {"color.tabUnfocused", &ui::Theme::tabUnfocused},
237 {"color.tabUnfocusedActive", &ui::Theme::tabUnfocusedActive},
238 {"color.tableHeaderBg", &ui::Theme::tableHeaderBg},
239 {"color.tableBorderStrong", &ui::Theme::tableBorderStrong},
240 {"color.tableBorderLight", &ui::Theme::tableBorderLight},
241 {"color.tableRowBg", &ui::Theme::tableRowBg},
242 {"color.tableRowBgAlt", &ui::Theme::tableRowBgAlt},
243 {"color.plotLines", &ui::Theme::plotLines},
244 {"color.plotLinesHovered", &ui::Theme::plotLinesHovered},
245 {"color.plotHistogram", &ui::Theme::plotHistogram},
246 {"color.plotHistogramHovered", &ui::Theme::plotHistogramHovered},
247 {"color.textSelectedBg", &ui::Theme::textSelectedBg},
248 {"color.navHighlight", &ui::Theme::navHighlight},
249 {"color.modalDimBg", &ui::Theme::modalDimBg},
250};
251
252const FloatTok kFloats[] = {
253 {"geometry.windowRounding", &ui::Theme::windowRounding, 0.f, 24.f, "Geometry"},
254 {"geometry.childRounding", &ui::Theme::childRounding, 0.f, 24.f, "Geometry"},
255 {"geometry.frameRounding", &ui::Theme::frameRounding, 0.f, 24.f, "Geometry"},
256 {"geometry.popupRounding", &ui::Theme::popupRounding, 0.f, 24.f, "Geometry"},
257 {"geometry.scrollbarRounding", &ui::Theme::scrollbarRounding, 0.f, 24.f, "Geometry"},
258 {"geometry.grabRounding", &ui::Theme::grabRounding, 0.f, 24.f, "Geometry"},
259 {"geometry.tabRounding", &ui::Theme::tabRounding, 0.f, 24.f, "Geometry"},
260 {"geometry.windowBorderSize", &ui::Theme::windowBorderSize, 0.f, 8.f, "Geometry"},
261 {"geometry.childBorderSize", &ui::Theme::childBorderSize, 0.f, 8.f, "Geometry"},
262 {"geometry.popupBorderSize", &ui::Theme::popupBorderSize, 0.f, 8.f, "Geometry"},
263 {"geometry.frameBorderSize", &ui::Theme::frameBorderSize, 0.f, 8.f, "Geometry"},
264 {"spacing.windowPaddingX", &ui::Theme::windowPaddingX, 0.f, 64.f, "Spacing"},
265 {"spacing.windowPaddingY", &ui::Theme::windowPaddingY, 0.f, 64.f, "Spacing"},
266 {"spacing.framePaddingX", &ui::Theme::framePaddingX, 0.f, 64.f, "Spacing"},
267 {"spacing.framePaddingY", &ui::Theme::framePaddingY, 0.f, 64.f, "Spacing"},
268 {"spacing.itemSpacingX", &ui::Theme::itemSpacingX, 0.f, 64.f, "Spacing"},
269 {"spacing.itemSpacingY", &ui::Theme::itemSpacingY, 0.f, 64.f, "Spacing"},
270 {"spacing.itemInnerSpacingX", &ui::Theme::itemInnerSpacingX, 0.f, 64.f, "Spacing"},
271 {"spacing.itemInnerSpacingY", &ui::Theme::itemInnerSpacingY, 0.f, 64.f, "Spacing"},
272 {"spacing.cellPaddingX", &ui::Theme::cellPaddingX, 0.f, 64.f, "Spacing"},
273 {"spacing.cellPaddingY", &ui::Theme::cellPaddingY, 0.f, 64.f, "Spacing"},
274 {"spacing.indentSpacing", &ui::Theme::indentSpacing, 0.f, 64.f, "Spacing"},
275 {"spacing.scrollbarSize", &ui::Theme::scrollbarSize, 1.f, 64.f, "Spacing"},
276 {"spacing.grabMinSize", &ui::Theme::grabMinSize, 1.f, 64.f, "Spacing"},
277 {"typography.fontScale", &ui::Theme::fontScale, 0.25f, 4.f, "Typography"},
278};
279
280const LayoutTok kLayout[] = {
281 {"layout.toolbarHeight", &ui::ThemeLayout::toolbarHeight, 16.f, 128.f},
282 {"layout.statusBarHeight", &ui::ThemeLayout::statusBarHeight, 16.f, 128.f},
283 {"layout.sidebarWidth", &ui::ThemeLayout::sidebarWidth, 80.f, 640.f},
284 {"layout.toolboxCellSize", &ui::ThemeLayout::toolboxCellSize, 16.f, 128.f},
285 {"layout.splitterSize", &ui::ThemeLayout::splitterSize, 2.f, 24.f},
286 {"layout.minPaneSize", &ui::ThemeLayout::minPaneSize, 32.f, 640.f},
287 {"layout.panelPaddingX", &ui::ThemeLayout::panelPaddingX, 0.f, 64.f},
288 {"layout.panelPaddingY", &ui::ThemeLayout::panelPaddingY, 0.f, 64.f},
289 {"layout.cardPaddingX", &ui::ThemeLayout::cardPaddingX, 0.f, 64.f},
290 {"layout.cardPaddingY", &ui::ThemeLayout::cardPaddingY, 0.f, 64.f},
291 {"layout.barPaddingX", &ui::ThemeLayout::barPaddingX, 0.f, 64.f},
292 {"layout.barPaddingY", &ui::ThemeLayout::barPaddingY, 0.f, 64.f},
293 {"layout.sectionSpacingY", &ui::ThemeLayout::sectionSpacingY, 0.f, 64.f},
294 {"layout.searchMinWidth", &ui::ThemeLayout::searchMinWidth, 32.f, 640.f},
295 {"layout.searchIconGap", &ui::ThemeLayout::searchIconGap, 0.f, 32.f},
296};
297
298const EditorValue* field(const EditorValue& value, const char* key) {
299 const auto* object = value.getIf<EditorValue::Object>();
300 if (!object) return nullptr;
301 const auto found = object->find(key);
302 return found == object->end() ? nullptr : &found->second;
303}
304
305bool readColor(const EditorValue& value, float dest[4]) {
306 const auto* array = value.getIf<EditorValue::Array>();
307 if (!array || array->size() < 4) return false;
308 for (int i = 0; i < 4; ++i) {
309 const auto* number = (*array)[static_cast<std::size_t>(i)].getIf<double>();
310 if (!number || !std::isfinite(*number) || *number < 0.0 || *number > 1.0) return false;
311 dest[i] = static_cast<float>(*number);
312 }
313 return true;
314}
315
316EditorValue colorValue(const float src[4]) {
317 return EditorValue::Array{static_cast<double>(src[0]), static_cast<double>(src[1]), static_cast<double>(src[2]),
318 static_cast<double>(src[3])};
319}
320
321PropertyDescriptor colorProperty(const char* path) {
324 descriptor.displayNameKey = path;
325 descriptor.category = "Colors";
326 descriptor.type = PropertyType::Color;
327 descriptor.flags = PropertyFlag::Runtime;
328 descriptor.numeric.minimum = 0.0;
329 descriptor.numeric.maximum = 1.0;
330 descriptor.defaultValue = EditorValue::Array{1.0, 1.0, 1.0, 1.0};
331 return descriptor;
332}
333
334PropertyDescriptor floatProperty(const FloatTok& token) {
337 descriptor.displayNameKey = token.path;
338 descriptor.category = token.category;
339 descriptor.type = PropertyType::Float;
340 descriptor.flags = PropertyFlag::Runtime;
341 descriptor.numeric.minimum = token.minimum;
342 descriptor.numeric.maximum = token.maximum;
343 descriptor.defaultValue = static_cast<double>(token.minimum);
344 return descriptor;
345}
346
347PropertyDescriptor layoutProperty(const LayoutTok& token) {
350 descriptor.displayNameKey = token.path;
351 descriptor.category = "Layout";
352 descriptor.type = PropertyType::Float;
353 descriptor.flags = PropertyFlag::Runtime;
354 descriptor.numeric.minimum = token.minimum;
355 descriptor.numeric.maximum = token.maximum;
356 descriptor.defaultValue = static_cast<double>(token.minimum);
357 return descriptor;
358}
359
360bool inRange(float value, float minimum, float maximum) {
361 return std::isfinite(value) && value >= minimum && value <= maximum;
362}
363
364} // namespace
365
368 for (const ColorTok& token : kColors) object[token.path] = colorValue(theme.*(token.member));
369 for (const FloatTok& token : kFloats) object[token.path] = static_cast<double>(theme.*(token.member));
370 for (const LayoutTok& token : kLayout) object[token.path] = static_cast<double>(theme.layout.*(token.member));
371 object["nav.keyboard"] = theme.navEnableKeyboard;
372 object["nav.gamepad"] = theme.navEnableGamepad;
373 return EditorValue(std::move(object));
374}
375
377 if (!value.getIf<EditorValue::Object>())
378 return eve::editing::failed<ui::Theme>(EditorStatus::Rejected, RuleId("editor.ui-theme.tokens"),
379 "Theme tokens must be an object");
381 for (const ColorTok& token : kColors) {
382 const EditorValue* entry = field(value, token.path);
383 if (!entry || !readColor(*entry, theme.*(token.member)))
384 return eve::editing::failed<ui::Theme>(EditorStatus::Rejected, RuleId("editor.ui-theme.color"),
385 std::string("Theme color is missing or invalid: ") + token.path);
386 }
387 for (const FloatTok& token : kFloats) {
388 const EditorValue* entry = field(value, token.path);
389 const auto* number = entry ? entry->getIf<double>() : nullptr;
390 if (!number || !std::isfinite(*number))
391 return eve::editing::failed<ui::Theme>(EditorStatus::Rejected, RuleId("editor.ui-theme.float"),
392 std::string("Theme number is missing or invalid: ") + token.path);
393 theme.*(token.member) = static_cast<float>(*number);
394 }
395 for (const LayoutTok& token : kLayout) {
396 const EditorValue* entry = field(value, token.path);
397 const auto* number = entry ? entry->getIf<double>() : nullptr;
398 if (!number || !std::isfinite(*number))
399 return eve::editing::failed<ui::Theme>(
400 EditorStatus::Rejected, RuleId("editor.ui-theme.layout"),
401 std::string("Theme layout number is missing or invalid: ") + token.path);
402 theme.layout.*(token.member) = static_cast<float>(*number);
403 }
404 const EditorValue* keyboard = field(value, "nav.keyboard");
405 const EditorValue* gamepad = field(value, "nav.gamepad");
406 const auto* keyboardFlag = keyboard ? keyboard->getIf<bool>() : nullptr;
407 const auto* gamepadFlag = gamepad ? gamepad->getIf<bool>() : nullptr;
408 if (!keyboardFlag || !gamepadFlag)
409 return eve::editing::failed<ui::Theme>(EditorStatus::Rejected, RuleId("editor.ui-theme.nav"),
410 "Theme navigation flags are required");
411 theme.navEnableKeyboard = *keyboardFlag;
412 theme.navEnableGamepad = *gamepadFlag;
413 auto diagnostics = validateThemeTokens(theme);
414 if (!diagnostics.empty())
415 return eve::editing::failed<ui::Theme>(EditorStatus::Rejected, RuleId("editor.ui-theme.range"),
416 diagnostics.front().message());
417 return eve::editing::applied<ui::Theme>(theme);
418}
419
421 for (const ColorTok& token : kColors) {
422 if (path != PropertyPath(token.path)) continue;
423 if (!readColor(value, theme.*(token.member)))
424 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.ui-theme.token-color"),
425 std::string("Theme color token is invalid: ") + token.path);
426 return eve::editing::applied<void>();
427 }
428 for (const FloatTok& token : kFloats) {
429 if (path != PropertyPath(token.path)) continue;
430 const auto* number = value.getIf<double>();
431 if (!number || !inRange(static_cast<float>(*number), token.minimum, token.maximum))
432 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.ui-theme.token-float"),
433 std::string("Theme number token is invalid: ") + token.path);
434 theme.*(token.member) = static_cast<float>(*number);
435 return eve::editing::applied<void>();
436 }
437 for (const LayoutTok& token : kLayout) {
438 if (path != PropertyPath(token.path)) continue;
439 const auto* number = value.getIf<double>();
440 if (!number || !inRange(static_cast<float>(*number), token.minimum, token.maximum))
441 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.ui-theme.token-layout"),
442 std::string("Theme layout token is invalid: ") + token.path);
443 theme.layout.*(token.member) = static_cast<float>(*number);
444 return eve::editing::applied<void>();
445 }
446 if (path == PropertyPath("nav.keyboard")) {
447 const auto* flag = value.getIf<bool>();
448 if (!flag)
449 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.ui-theme.token-nav"),
450 "Theme navigation token is invalid");
451 theme.navEnableKeyboard = *flag;
452 return eve::editing::applied<void>();
453 }
454 if (path == PropertyPath("nav.gamepad")) {
455 const auto* flag = value.getIf<bool>();
456 if (!flag)
457 return eve::editing::failed<void>(EditorStatus::Rejected, RuleId("editor.ui-theme.token-nav"),
458 "Theme navigation token is invalid");
459 theme.navEnableGamepad = *flag;
460 return eve::editing::applied<void>();
461 }
462 return eve::editing::failed<void>(EditorStatus::NotFound, RuleId("editor.ui-theme.token"),
463 "Unknown theme token: " + path.value());
464}
465
467 for (const ColorTok& token : kColors) {
468 if (path == PropertyPath(token.path)) return colorValue(theme.*(token.member));
469 }
470 for (const FloatTok& token : kFloats) {
471 if (path == PropertyPath(token.path)) return static_cast<double>(theme.*(token.member));
472 }
473 for (const LayoutTok& token : kLayout) {
474 if (path == PropertyPath(token.path)) return static_cast<double>(theme.layout.*(token.member));
475 }
476 if (path == PropertyPath("nav.keyboard")) return theme.navEnableKeyboard;
477 if (path == PropertyPath("nav.gamepad")) return theme.navEnableGamepad;
478 return {};
479}
480
482 PropertySchema schema;
483 schema.typeId = "ui.theme";
484 schema.properties.push_back(colorProperty("color.text"));
485 schema.properties.push_back(colorProperty("color.windowBg"));
486 schema.properties.push_back(colorProperty("color.childBg"));
487 schema.properties.push_back(colorProperty("color.frameBg"));
488 schema.properties.push_back(colorProperty("color.button"));
489 schema.properties.push_back(colorProperty("color.buttonHovered"));
490 schema.properties.push_back(colorProperty("color.buttonActive"));
491 schema.properties.push_back(colorProperty("color.header"));
492 schema.properties.push_back(colorProperty("color.checkMark"));
493 schema.properties.push_back(colorProperty("color.sliderGrab"));
494 for (const FloatTok& token : kFloats) schema.properties.push_back(floatProperty(token));
495 for (const LayoutTok& token : kLayout) schema.properties.push_back(layoutProperty(token));
496 PropertyDescriptor keyboard;
497 keyboard.path = PropertyPath("nav.keyboard");
498 keyboard.displayNameKey = "nav.keyboard";
499 keyboard.category = "Typography";
500 keyboard.type = PropertyType::Bool;
501 keyboard.flags = PropertyFlag::Runtime;
502 keyboard.defaultValue = true;
503 schema.properties.push_back(keyboard);
504 PropertyDescriptor gamepad = keyboard;
505 gamepad.path = PropertyPath("nav.gamepad");
506 gamepad.displayNameKey = "nav.gamepad";
507 gamepad.defaultValue = false;
508 schema.properties.push_back(std::move(gamepad));
509 return schema;
510}
511
512std::vector<EditorDiagnostic> validateThemeTokens(const ui::Theme& theme) {
513 std::vector<EditorDiagnostic> diagnostics;
514 for (const ColorTok& token : kColors) {
515 const float* color = theme.*(token.member);
516 for (int i = 0; i < 4; ++i) {
517 if (!inRange(color[i], 0.f, 1.f)) {
518 diagnostics.push_back(tokenDiagnostic(
519 "editor.ui-theme.color-range", std::string("Theme color channel is out of range: ") + token.path));
520 break;
521 }
522 }
523 }
524 for (const FloatTok& token : kFloats) {
525 if (!inRange(theme.*(token.member), token.minimum, token.maximum))
526 diagnostics.push_back(tokenDiagnostic("editor.ui-theme.float-range",
527 std::string("Theme number is out of range: ") + token.path));
528 }
529 for (const LayoutTok& token : kLayout) {
530 if (!inRange(theme.layout.*(token.member), token.minimum, token.maximum))
531 diagnostics.push_back(tokenDiagnostic("editor.ui-theme.layout-range",
532 std::string("Theme layout number is out of range: ") + token.path));
533 }
534 return diagnostics;
535}
536
540
541std::string presetName(UiThemeBasePreset preset) {
542 switch (preset) {
543 case UiThemeBasePreset::Light: return "light";
544 case UiThemeBasePreset::Custom: return "custom";
545 case UiThemeBasePreset::Dark: return "dark";
546 }
547 return "dark";
548}
549
551 if (name == "dark") return eve::editing::applied<UiThemeBasePreset>(UiThemeBasePreset::Dark);
552 if (name == "light") return eve::editing::applied<UiThemeBasePreset>(UiThemeBasePreset::Light);
553 if (name == "custom") return eve::editing::applied<UiThemeBasePreset>(UiThemeBasePreset::Custom);
554 return eve::editing::failed<UiThemeBasePreset>(EditorStatus::Rejected, RuleId("editor.ui-theme.preset"),
555 "Theme base preset must be dark, light, or custom");
556}
557
558} // namespace eve::ui_editing
double y
double x
int root
Definition AnimSmr.cpp:119
std::string descriptor
SQObjectPtr key
Definition ECS.cpp:155
std::string name
Definition ECS.cpp:154
std::string message
float maximum[3]
float minimum[3]
std::uint32_t height
std::uint32_t width
const ColourScope * parent
std::string id
Poco::JSON::Object::Ptr result
Snapshot snapshot
OceanGpuFrameToken token
std::string path
Definition PlayHost.cpp:111
Object::Ptr value
double number
bool found
std::map< Cell, int > best
Json object
const char * category
float(ui::Theme::* member)[4]
std::uint32_t depth
A structured explanation of a failed, degraded, or noteworthy result.
Definition Diagnostic.h:94
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
const std::string & value() const noexcept
Returns the exact legacy or canonical compatibility spelling.
Definition Identity.h:365
std::uint64_t revision() const override
Return the current revision.
Dotted property path (layout.size) compared and persisted as text.
Definition EditingIds.h:78
Deterministic owning value tree shared by authoring hosts.
std::vector< Value > Array
std::map< std::string, Value > Object
const T * getIf() const
Return an immediately borrowed typed value.
Result< EditorValue > anchorGizmo(const UiDocumentTarget &document, const UiPreviewSnapshot &preview, const ObjectId &widget) const
Return anchor point, pivot point and connecting line as numeric pairs.
Definition UiPreview.cpp:84
UiPreviewSnapshot build(const UiDocumentTarget &document, double width, double height) const
Compute absolute rectangles for a viewport without mutating runtime UI.
Definition UiPreview.cpp:15
Result< ObjectId > pick(const UiPreviewSnapshot &preview, double x, double y) const
Pick the deepest visible widget under a preview-space point.
Definition UiPreview.cpp:66
Serializable UI authoring document with hierarchy and inspector capabilities.
Definition UiDocument.h:157
std::vector< EditorDiagnostic > validate() const
Validate style, hierarchy and viewport layout constraints.
std::vector< ObjectId > children(const ObjectId &parent) const override
Children.
Result< UiWidgetSnapshot > widget(const ObjectId &id) const override
Widget.
Serializable catalog of named UI themes with one active publication slot.
Definition UiTheme.h:60
std::string runtimeName(const ObjectId &id) const
Runtime name written to ui::globalThemeName(): dark, light, or custom.
Definition UiTheme.cpp:151
const ObjectId & activeId() const noexcept
Active publication id; empty only if the catalog failed to seed.
Definition UiTheme.h:93
Result< UiThemeAsset > theme(const ObjectId &id) const
Copy one named theme, or NotFound.
Definition UiTheme.cpp:143
UiThemePreviewSnapshot build(const UiThemeCatalogTarget &catalog, const ObjectId &themeId, Revision expectedRevision) const
Copy tokens for themeId when expectedRevision matches the catalog.
Result< void > publish(const UiThemeCatalogTarget &catalog) const
Replace the process global theme with the catalog's active asset.
editing::PropertyDescriptor PropertyDescriptor
editing::PropertyPath PropertyPath
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
Diagnostic ruleDiagnostic(eve::DiagnosticCode code, RuleId rule, DiagnosticSeverity severity, std::string message)
Build an owning common diagnostic carrying an open editing rule identity.
EditorValue readThemeToken(const ui::Theme &theme, const PropertyPath &path)
Reads theme token.
ui::Theme themeFromPreset(UiThemeBasePreset preset)
Theme from preset.
Result< void > assignThemeToken(ui::Theme &theme, const PropertyPath &path, const EditorValue &value)
Assign theme token.
editing::Diagnostic EditorDiagnostic
Definition UiDocument.h:47
std::vector< EditorDiagnostic > validateThemeTokens(const ui::Theme &theme)
Validate theme tokens.
std::string presetName(UiThemeBasePreset preset)
Preset name.
PropertySchema themeTokenSchema()
Theme token schema.
Result< UiThemeBasePreset > parsePreset(const std::string &name)
Parse preset.
UiThemeBasePreset
Base preset used when resetting a named theme asset.
Definition UiTheme.h:44
editing::Value EditorValue
Definition UiDocument.h:46
Result< ui::Theme > parseThemeTokens(const EditorValue &value)
Parse theme tokens.
EditorValue themeTokensValue(const ui::Theme &theme)
Theme tokens value.
void setGlobalTheme(const Theme &theme)
Sets the global theme.
Definition Theme.cpp:281
PropertyDescriptor public API.
EVENGINE_API_PLATFORM public API.
std::vector< PropertyDescriptor > properties
float panelPaddingY
Definition Theme.h:24
float searchIconGap
Definition Theme.h:31
float toolbarHeight
Definition Theme.h:17
float toolboxCellSize
Definition Theme.h:20
float searchMinWidth
Definition Theme.h:30
float panelPaddingX
Definition Theme.h:23
float sectionSpacingY
Definition Theme.h:29
float statusBarHeight
Definition Theme.h:18
Unified UI design tokens (colors, geometry, typography). Applied to ImGui each frame via applyThemeTo...
Definition Theme.h:41
float titleBg[4]
Definition Theme.h:56
float tableBorderLight[4]
Definition Theme.h:81
float navHighlight[4]
Definition Theme.h:89
float frameBg[4]
Definition Theme.h:53
float checkMark[4]
Definition Theme.h:66
float itemSpacingX
Definition Theme.h:110
float scrollbarSize
Definition Theme.h:117
float indentSpacing
Definition Theme.h:116
float sliderGrab[4]
Definition Theme.h:67
float scrollbarGrab[4]
Definition Theme.h:71
float buttonHovered[4]
Definition Theme.h:61
float tableRowBgAlt[4]
Definition Theme.h:83
float itemSpacingY
Definition Theme.h:111
float menuBarBg[4]
Definition Theme.h:59
float buttonActive[4]
Definition Theme.h:62
float windowPaddingX
Definition Theme.h:106
float frameBorderSize
Definition Theme.h:104
float modalDimBg[4]
Definition Theme.h:90
float childRounding
Definition Theme.h:94
float textDisabled[4]
Definition Theme.h:47
float separator[4]
Definition Theme.h:69
float titleBgActive[4]
Definition Theme.h:57
float popupBg[4]
Definition Theme.h:50
float tabActive[4]
Definition Theme.h:76
float fontScale
Definition Theme.h:122
float header[4]
Definition Theme.h:63
float grabMinSize
Definition Theme.h:118
float windowPaddingY
Definition Theme.h:107
float plotHistogram[4]
Definition Theme.h:86
float cellPaddingY
Definition Theme.h:115
float titleBgCollapsed[4]
Definition Theme.h:58
float framePaddingY
Definition Theme.h:109
float scrollbarGrabHovered[4]
Definition Theme.h:72
float tableHeaderBg[4]
Definition Theme.h:79
float text[4]
Definition Theme.h:46
float itemInnerSpacingX
Definition Theme.h:112
float scrollbarGrabActive[4]
Definition Theme.h:73
float scrollbarRounding
Definition Theme.h:97
float borderShadow[4]
Definition Theme.h:52
float grabRounding
Definition Theme.h:98
float frameBgActive[4]
Definition Theme.h:55
float windowBg[4]
Definition Theme.h:48
float windowRounding
Definition Theme.h:93
float windowBorderSize
Definition Theme.h:101
float framePaddingX
Definition Theme.h:108
float tabUnfocusedActive[4]
Definition Theme.h:78
static Theme light()
Light.
Definition Theme.cpp:180
float tabUnfocused[4]
Definition Theme.h:77
float sliderGrabActive[4]
Definition Theme.h:68
float itemInnerSpacingY
Definition Theme.h:113
float headerHovered[4]
Definition Theme.h:64
float tabHovered[4]
Definition Theme.h:75
float frameBgHovered[4]
Definition Theme.h:54
float textSelectedBg[4]
Definition Theme.h:88
float plotLinesHovered[4]
Definition Theme.h:85
float popupBorderSize
Definition Theme.h:103
float tab[4]
Definition Theme.h:74
float cellPaddingX
Definition Theme.h:114
float childBg[4]
Definition Theme.h:49
float plotLines[4]
Definition Theme.h:84
float childBorderSize
Definition Theme.h:102
float frameRounding
Definition Theme.h:95
float headerActive[4]
Definition Theme.h:65
float button[4]
Definition Theme.h:60
float scrollbarBg[4]
Definition Theme.h:70
float plotHistogramHovered[4]
Definition Theme.h:87
float tableBorderStrong[4]
Definition Theme.h:80
float tabRounding
Definition Theme.h:99
static Theme dark()
Built-in presets with matching geometry; only colors differ.
Definition Theme.cpp:174
float border[4]
Definition Theme.h:51
float popupRounding
Definition Theme.h:96
float tableRowBg[4]
Definition Theme.h:82
Deterministic UI layout preview used by canvas rendering and picking.
Definition UiDocument.h:254
std::vector< UiPreviewWidget > widgets
Definition UiDocument.h:258
Computed widget rectangle in a revision-bound UI preview.
Definition UiDocument.h:245
Revision-bound Theme copy used by gallery hosts without mutating globalTheme.
Definition UiTheme.h:163
Immutable widget snapshot used across editor/runtime boundaries.
Definition UiDocument.h:102
std::string widget
Object::Ptr theme
glm::vec4 color