16using property_access::PropertyDescriptor;
21void applyWrite(property_access::IPropertyAccess &
model,
const std::string &
path,
Value value) {
23 .ignore(
"PropertyView UI writes are best-effort until the shell can present Result diagnostics");
26std::string sanitize(std::string
value) {
27 for (
char &character :
value)
28 if (character ==
' ' || character ==
'.' || character ==
'[' || character ==
']' ||
34std::string displayName(
const PropertyDescriptor &property) {
35 if (!property.displayName.empty())
return property.displayName;
36 const std::size_t
separator =
property.path.find_last_of(
"./");
37 return separator == std::string::npos ?
property.path :
property.path.substr(
separator + 1);
41 if (
const auto *
text =
value.getIf<std::string>())
return *
text;
42 if (
const auto *
boolean =
value.getIf<
bool>())
return *
boolean ?
"true" :
"false";
43 if (
const auto *integer =
value.getIf<std::int64_t>())
return std::to_string(*integer);
46 return std::to_string(array->size()) +
" items";
48 return std::to_string(
object->size()) +
" fields";
54 if (
const auto *integer =
value.getIf<std::int64_t>())
return static_cast<double>(*integer);
58bool parseNumber(
const std::string &
text,
bool integer,
Value &
out) {
60 std::int64_t parsed = 0;
61 const auto converted = std::from_chars(
text.data(),
text.data() +
text.size(), parsed);
62 if (converted.ec != std::errc() || converted.ptr !=
text.data() +
text.size())
return false;
68 const double parsed = std::strtod(
text.c_str(), &
end);
69 if (
text.empty() || errno == ERANGE ||
end !=
text.c_str() +
text.size())
return false;
87 case PropertyKind::Integer:
92 case PropertyKind::String:
93 case PropertyKind::AssetRef:
94 case PropertyKind::ObjectRef:
100WidgetDesc scalarElementEditor(
const std::string &elementId,
const std::string &elementLabel,
102 if (
const auto *
boolean =
element.getIf<
bool>()) {
103 return checkbox(elementLabel, *
boolean, elementId,
104 [writeElement = std::move(writeElement)](
bool next) { writeElement(
Value(next)); });
108 [writeElement = std::move(writeElement),
109 integer =
element.getIf<std::int64_t>() !=
nullptr](
const std::string &next) {
111 if (parseNumber(next, integer, parsed)) writeElement(std::move(parsed));
116 [writeElement = std::move(writeElement)](
const std::string &next) {
117 writeElement(
Value(next));
120 return text(elementLabel +
" = " + valueText(
element), elementId);
123WidgetDesc makeCompositeEditor(property_access::IPropertyAccess &
model,
const PropertyViewOptions &
options,
124 const PropertyDescriptor &property,
const Value &
value,
125 const std::vector<std::string> &labels) {
129 children.push_back(
text(displayName(property),
id +
"_label"));
131 const std::string componentId =
id +
"_" + labels[
index];
132 const std::string
path =
property.path;
133 const std::size_t component =
index;
134 const bool useSlider =
property.numeric.minimum &&
property.numeric.maximum;
138 static_cast<float>(*property.numeric.minimum),
static_cast<float>(*property.numeric.maximum),
139 componentId, [&
model,
path, component,
count = labels.size()](
float next) {
140 const std::optional<Value> current = model.read(path);
141 Value::Array updated =
142 componentArray(current ? *current : Value(Value::Array{}),
count);
148 labels[
index], valueText(items[
index]), componentId,
151 if (!parseNumber(next,
false, parsed))
return;
155 updated[component] = std::move(parsed);
163WidgetDesc makeArrayEditor(property_access::IPropertyAccess &
model,
const PropertyViewOptions &
options,
164 const PropertyDescriptor &property,
const Value &
value) {
168 std::vector<WidgetDesc>
rows;
170 const std::string elementId =
id +
"_" + std::to_string(
index);
171 const std::string elementLabel = displayName(property) +
"[" + std::to_string(
index) +
"]";
172 const std::string
path =
property.path;
173 const std::size_t elementIndex =
index;
174 WidgetDesc
cell = scalarElementEditor(
175 elementId, elementLabel, items[
index],
181 if (elementIndex >=
updated.size())
updated.resize(elementIndex + 1);
182 updated[elementIndex] = std::move(next);
185 const auto onStructure =
options.onStructureChange;
188 button(
"x##" + elementId +
"_del", elementId +
"_del",
189 [&
model,
path, elementIndex, onStructure]() {
194 if (elementIndex <
updated.size())
195 updated.erase(
updated.begin() +
static_cast<std::ptrdiff_t
>(elementIndex));
197 if (onStructure) onStructure();
199 elementId +
"_row"));
201 const std::string
path =
property.path;
202 const auto onStructure =
options.onStructureChange;
204 {
button(
"+##" +
id +
"_add",
id +
"_add",
210 updated.emplace_back(std::string{});
212 if (onStructure) onStructure();
215 return collapsingHeader(displayName(property) +
" (array[" + std::to_string(items.size()) +
"])##" +
id,
216 std::move(
rows),
id,
false);
219WidgetDesc makeMapEditor(property_access::IPropertyAccess &
model,
const PropertyViewOptions &
options,
220 const PropertyDescriptor &property,
const Value &
value,
bool allowMutate) {
224 std::vector<WidgetDesc>
rows;
225 for (
const auto &[
key, entry] :
fields) {
226 const std::string elementId =
id +
"_" + sanitize(
key);
227 const std::string
path =
property.path;
228 const std::string fieldKey =
key;
229 WidgetDesc
cell = scalarElementEditor(
235 updated[fieldKey] = std::move(next);
239 const auto onStructure =
options.onStructureChange;
242 button(
"x##" + elementId +
"_del", elementId +
"_del",
243 [&
model,
path, fieldKey, onStructure]() {
250 if (onStructure) onStructure();
252 elementId +
"_row"));
258 const std::string
path =
property.path;
259 const auto onStructure =
options.onStructureChange;
261 {
button(
"+##" +
id +
"_add",
id +
"_add",
267 std::string
key =
"key" + std::to_string(
updated.size());
268 std::size_t suffix = 0;
270 key =
"key" + std::to_string(
updated.size() + (++suffix));
273 if (onStructure) onStructure();
277 const std::string kindLabel =
property.kind == PropertyKind::Struct ?
"struct" :
"map";
278 return collapsingHeader(displayName(property) +
" (" + kindLabel +
")##" +
id, std::move(
rows),
id,
false);
281WidgetDesc makePropertyField(property_access::IPropertyAccess &
model,
const PropertyViewOptions &
options,
282 const PropertyDescriptor &property,
const Value &
value) {
284 const std::string
label = displayName(property);
290 if (property.kind == PropertyKind::Array || property.kind == PropertyKind::Map ||
291 property.kind == PropertyKind::Struct)
293 {
text(valueText(
value),
id +
"_summary")},
id,
false);
297 switch (property.kind) {
298 case PropertyKind::Bool: {
300 const std::string
path =
property.path;
306 case PropertyKind::Integer:
307 case PropertyKind::Number: {
308 const bool integer =
property.kind == PropertyKind::Integer;
309 const std::string
path =
property.path;
310 if (property.numeric.minimum && property.numeric.maximum) {
312 static_cast<float>(*property.numeric.minimum),
313 static_cast<float>(*property.numeric.maximum),
id,
316 applyWrite(model, path, Value(static_cast<std::int64_t>(next)));
318 applyWrite(model, path, Value(static_cast<double>(next)));
322 [&
model,
path, integer](
const std::string &next) {
324 if (parseNumber(next, integer, parsed))
325 applyWrite(
model,
path, std::move(parsed));
330 case PropertyKind::Enum: {
332 int selectedIndex = 0;
335 const std::string
path =
property.path;
336 const std::vector<std::string>
choices =
property.choices;
339 const int index =
static_cast<int>(
next);
345 case PropertyKind::Action: {
346 const std::string
path =
property.path;
350 case PropertyKind::String:
351 case PropertyKind::AssetRef:
352 case PropertyKind::ObjectRef:
353 case PropertyKind::Auto: {
354 const std::string
path =
property.path;
356 [&
model,
path](
const std::string &next) {
361 case PropertyKind::Color:
364 case PropertyKind::Vec2:
367 case PropertyKind::Vec3:
370 case PropertyKind::Vec4:
373 case PropertyKind::Array:
376 case PropertyKind::Map:
379 case PropertyKind::Struct:
382 case PropertyKind::ReadOnlyText:
387 result.tooltip =
property.description;
388 result.accessibilityRole = accessibilityRole(property.kind,
readOnly);
390 result.accessibilityDescription =
property.description;
398bool visible(
const PropertyDescriptor &property,
const PropertyViewOptions &
options) {
402 property.kind == PropertyKind::ReadOnlyText))
407void syncComposite(UIHost &
host,
const std::string &
id,
const Value &
value,
408 const std::vector<std::string> &labels,
const PropertyDescriptor &property) {
411 const std::string componentId =
id +
"_" + labels[
index];
412 if (property.numeric.minimum && property.numeric.maximum)
415 host.setValueTextById(componentId, valueText(items[
index]));
427 auto property =
model.schema().find(
path);
429 if (!property || !
value)
442 for (
const PropertyDescriptor &property :
model.schema().properties) {
444 const std::optional<Value>
value =
model.read(property.path);
445 if (!
value)
continue;
446 if (
options.groupCategories && !property.category.empty() &&
property.category !=
category) {
456 for (
const PropertyDescriptor &property :
model.schema().properties) {
457 const std::optional<Value>
value =
model.read(property.path);
458 if (!
value)
continue;
460 const bool readOnly = property_access::hasFlag(property.flags, PropertyFlag::ReadOnly) ||
461 property.kind == PropertyKind::ReadOnlyText;
463 host.setTextById(
id, displayName(property) +
": " + valueText(*
value));
466 switch (property.kind) {
467 case PropertyKind::Bool:
468 if (
const auto *
boolean =
value->getIf<
bool>())
host.setCheckedById(
id, *
boolean);
470 case PropertyKind::Enum: {
472 const auto found = std::find(property.choices.begin(), property.choices.end(),
selected);
473 host.setValueById(
id,
found == property.choices.end()
475 :
static_cast<float>(
found -
property.choices.begin()));
478 case PropertyKind::Integer:
479 case PropertyKind::Number:
480 if (property.numeric.minimum && property.numeric.maximum)
481 host.setValueById(
id,
static_cast<float>(numericValue(*
value)));
483 host.setValueTextById(
id, valueText(*
value));
485 case PropertyKind::Color:
486 syncComposite(
host,
id, *
value, {
"r",
"g",
"b",
"a"}, property);
488 case PropertyKind::Vec2:
489 syncComposite(
host,
id, *
value, {
"x",
"y"}, property);
491 case PropertyKind::Vec3:
492 syncComposite(
host,
id, *
value, {
"x",
"y",
"z"}, property);
494 case PropertyKind::Vec4:
495 syncComposite(
host,
id, *
value, {
"x",
"y",
"z",
"w"}, property);
497 case PropertyKind::Array:
500 const std::string elementId =
id +
"_" + std::to_string(
index);
501 if (
const auto *
boolean = (*items)[
index].getIf<bool>())
502 host.setCheckedById(elementId, *
boolean);
504 host.setValueTextById(elementId, valueText((*items)[
index]));
508 case PropertyKind::Map:
509 case PropertyKind::Struct:
511 for (
const auto &[
key, entry] : *
fields) {
512 const std::string elementId =
id +
"_" + sanitize(
key);
513 if (
const auto *
boolean = entry.getIf<
bool>())
514 host.setCheckedById(elementId, *
boolean);
516 host.setValueTextById(elementId, valueText(entry));
520 case PropertyKind::String:
521 case PropertyKind::AssetRef:
522 case PropertyKind::ObjectRef:
523 case PropertyKind::Auto:
524 if (
const auto *textValue =
value->getIf<std::string>())
525 host.setValueTextById(
id, *textValue);
527 case PropertyKind::Action:
528 case PropertyKind::ReadOnlyText:
556void PropertyComponent::observe() {
std::vector< std::string > fields
std::set< std::string > choices
std::array< std::uint64_t, kPixelChunkSize *kPixelChunkSize > updated
const SquirrelValueOptions & options
void dispose() noexcept
Cancels this registration; safe to call repeatedly.
The canonical owning dynamic value used by data-facing protocols.
std::map< std::string, Value > Object
std::vector< Value > Array
Renderer- and transaction-independent MVVM property surface.
virtual Subscription subscribe(ChangeCallback callback)=0
Observe changes until the returned token is destroyed.
void markDirty()
Schedule one rebuild; repeated calls before the next preparation phase coalesce. @thread Owner thread...
property_access::IPropertyAccess * model() const
Return the currently bound property model, or null when unbound.
void bind(property_access::IPropertyAccess *model)
Replace the model and reconnect change observation.
void setOptions(PropertyViewOptions options)
Replace generation policy and mark the component dirty.
WidgetDesc build() override
Build the current schema-driven tree.
ECS mount point for one UI panel/screen. Subclass to attach UI to game entities, e....
Result< double > numericValue(const Value &value)
Read an Integer or Number as an owning double without applying domain validation.
constexpr HexDirection next(HexDirection d) noexcept
The next direction clockwise (NW wraps to NE).
constexpr bool hasFlag(PropertyFlag value, PropertyFlag flag)
True when flag.
PropertyFlag
Cross-host property visibility and editing flags.
PropertyKind
Semantic property kind used by renderer-independent presenters.
int64_t integer(const RuntimeTensor &v, size_t i=0)
Integer.
WidgetDesc collapsingHeader(std::string label, std::vector< WidgetDesc > children, std::string id, bool defaultOpen)
Collapsible header containing child widgets.
WidgetDesc buildPropertyView(property_access::IPropertyAccess &model, const PropertyViewOptions &options)
Generate a declarative, two-way property view from any model schema.
WidgetDesc checkbox(std::string label, bool checked, std::string id, std::function< void(bool)> onToggle)
Checkbox with a label; fires onToggle.
WidgetDesc combo(std::string label, std::vector< std::string > options, int selected, std::string id, std::function< void(float)> onValue)
Combo.
WidgetDesc slider(std::string label, float value, float minV, float maxV, std::string id, std::function< void(float)> onValue)
Horizontal slider; fires onValue.
WidgetDesc inputText(std::string label, std::string value, std::string id, std::function< void(const std::string &)> onChange)
Editable text field; fires onTextChange.
std::string propertyWidgetId(const PropertyViewOptions &options, const std::string &path)
Return the stable widget id generated for a property path.
@ Value
UINode.value (normalized HUD fill)
WidgetDesc buildPropertyField(property_access::IPropertyAccess &model, const std::string &path, const PropertyViewOptions &options)
Generate one field from a model property, or a diagnostic text row.
void syncPropertyView(UIHost &host, const property_access::IPropertyAccess &model, const PropertyViewOptions &options)
Pull current model values into an existing compatible UI tree.
WidgetDesc button(std::string label, std::string id, std::function< void()> onClick)
Clickable button; fires onClick.
WidgetDesc row(std::vector< WidgetDesc > children, std::string id)
Horizontal elastic layout row.
WidgetDesc sectionHeader(std::string label, std::string id)
Non-collapsible editor section heading with an accent marker.
WidgetDesc separator(std::string id)
Horizontal separator line.
AccessibilityRole
Platform-neutral accessibility role exposed by controls.
enum EVENGINE_API_FOUNDATION Array
OT_ARRAY (editable via Runtime array APIs / ReflectedPropertyModel).
Immutable notification emitted after a model property changes.
Policy controlling schema-to-widget generation for a UI shell.