|
Ultralight C++ API 2.0.0
|
#include <Ultralight/dom/data/ValueTraits.h>
Conversion rules that expose a C++ type as a primitive value in data bindings.
ValueTraits defines how data bindings convert a custom C++ scalar type into a primitive value on the page. Specializing it lets your application bind custom scalar types, such as a fixed-point coordinate, directly as values without schemas.
This specialization binds a fixed-point engine type as a floating-point number:
The library provides built-in traits for primitive C++ types:
| Type | Kind |
|---|---|
| bool | ValueKind::Bool |
| Integer types | ValueKind::Int64 |
| Floating-point types | ValueKind::Double |
| String types | ValueKind::String |
| Enums | ValueKind::String |
| dom::StyleValue | ValueKind::StyleValue |
| Color | ValueKind::Color |
An enum converts to text using its enumerator name. If an enum value doesn't have a matching name in the reflected range (0 to 63 by default), it displays as its decimal number instead (see dom::data::EnumRange).
To bind a custom scalar type, specialize ValueTraits in the ultralight::dom::data namespace with two members:
Specializations follow two priority rules:
Conversion works in one direction only, from native code to the page. When receiving values back, handlers accept primitive representations:
Convert the primitive value back to your custom type inside the handler: