docs
Loading...
Searching...
No Matches
Schema.h

Overview

Factories and tags for defining a type's data-binding schema.

#include <Ultralight/dom/data/Schema.h>

Note
This API is a preview and may still change after 2.0.

A schema declares which members of a native type the page can access. Passing entries to Schema() defines how HTML and CSS display your values and route user input back to native code.

This struct declares its schema as a schema member:

struct Buff {
int64_t id = 0;
std::string icon;
};
struct Hud {
int health = 100;
double volume = 0.8;
std::vector<Buff> buffs;
static constexpr auto schema = dd::Schema(
dd::Field("health", &Hud::health), // {{hud.health}}
dd::Field("volume", &Hud::volume, dd::Editable), // ul-value="hud.volume"
dd::List("buffs", &Hud::buffs, &Buff::id), // ul-for="hud.buffs"
dd::Action("respawn"), // ul-on:click="hud.respawn"
dd::Var("--hp", &Hud::health)); // var(--hp) in CSS
};

Choosing Schema Entries

Each task pairs with an entry or tag:

What the Page Needs Entry or Tag
Show a value Field()
Repeat rows List()
Let the page request something Action()
Set a CSS variable Var()
Expose all members of a struct Reflect()
Accept edits from a form control Editable
Hide an entry from page markup Internal
Deliver only the newest action OnlyLatest
Check or clamp edits Validate()

Rules for Every Schema

  • Apply tags directly to an entry or supply them as standalone declarations. Add tags like Editable or Internal to Field() or List(), or target an already declared member by name using dd::Editable("volume") for properties exposed by Reflect().
  • Mistakes fail at compile time. Duplicate entries and malformed declarations produce compilation errors that identify the violated rule (see Schema()).
  • Store the schema in the type itself or in a traits specialization. Define a static constexpr auto schema member inside types you control, or specialize dom::data::TypeTraits for existing classes and lambda accessors (see dom::data::TypeTraits).
  • Include this header on its own in a type's header. A header defining your types needs only <Ultralight/dom/data/Schema.h>, while <Ultralight/dom/data/Context.h> includes it automatically for code that binds instances.
See also
dom::data::Schema(), dom::data::TypeTraits, dom::data::Reflect()

Classes

struct  EditableTag
 Marks a field the page may request changes to. More...
struct  InternalTag
 Marks a field or list that pages can't reach. More...
struct  OnlyLatestTag
 Marks an action whose pending emissions collapse into the newest one. More...
struct  FieldToken< Owner, Value, Accessor, Validator >
 A field entry (the value Field() returns). More...
struct  ListToken< Owner, Container, Accessor, KeyPtr >
 A list entry (the value List() returns). More...
struct  ActionToken< Payload >
 An action entry (the value Action() returns). More...
struct  VarToken< Owner, Value, Accessor >
 A CSS custom property entry (the value Var() returns). More...

Functions

template<typename Fn>
requires std::is_class_v<Fn>
consteval ValidateWith< Fn > Validate (Fn fn)
 Attach a validator to a field (a Field() tag).
template<typename Fn>
requires std::is_class_v<Fn>
consteval ValidateEntry< Fn > Validate (const char *name, Fn fn)
 Attach a validator to an already-declared field (a Schema() entry).
template<detail::IsAccessor A, typename... Tags>
consteval auto Field (const char *name, A accessor, Tags... tags)
 Declare a field.
template<typename Value, typename... Tags>
requires (!detail::IsAccessor<Value>)
consteval auto Field (const char *name, Tags... tags)
 Declare a field without an accessor.
template<detail::IsAccessor A, typename KeyPtr, typename... Tags>
requires std::is_member_object_pointer_v<KeyPtr>
consteval auto List (const char *name, A accessor, KeyPtr key, Tags... tags)
 Declare a keyed list.
template<detail::IsAccessor A, typename... Tags>
requires (!std::is_member_object_pointer_v<Tags> && ...)
consteval auto List (const char *name, A accessor, Tags... tags)
 Declare a list whose rows are matched by position.
template<typename Payload = void, typename... Tags>
consteval ActionToken< Payload > Action (const char *name, Tags... tags)
 Declare an action (a request the page sends to your code).
template<detail::IsAccessor A>
consteval auto Var (const char *name, A accessor)
 Declare a CSS custom property that follows your data.
template<typename... Entries>
consteval auto Schema (Entries... entries)
 Declare a type's schema.

Variables

constexpr EditableTag Editable {}
constexpr InternalTag Internal {}
constexpr OnlyLatestTag OnlyLatest {}

Namespaces

namespace  ultralight
 Root namespace for every public Ultralight type, function, and enumeration.
namespace  ultralight::dom
 Direct C++ access to modify page elements and handle events.
namespace  ultralight::dom::data
 Data-binding API that connects native C++ data to HTML and CSS markup.

Enumerations

enum  EntryFlags : uint8_t {
  kEntryFlags_Editable = 1 << 0 , kEntryFlags_Internal = 1 << 1 , kEntryFlags_OnlyLatest = 1 << 2 , kEntryFlags_Keyed = 1 << 3 ,
  kEntryFlags_Var = 1 << 4 , kEntryFlags_Nullable = 1 << 5
}
 Flags on a schema entry. More...

Go to the source code of this file.