Runtime/UI/Public/TnxWidget.h file

Widget classes: the code behind widget assets (docs/ui/Widgets.md, Widget Classes).

class PlayerHud : public TnxWidget<PlayerHud>
{
public:
    explicit PlayerHud(TnxContextOf<EPlayer<>> player) : Player(player) {}

    TnxContextOf<EPlayer<>> Player;          // "=Player.CHealth.Value" in the asset
    TnxContextOf<ShopInfo> Shop;             // a view model
    TnxInput<float> Gold;                    // "=Gold"
    StatBar Health{ Player };                // { "name": "Health", "use": "StatBar" }
    void Buy(const ShopOffer& offer);        // { "call": "Buy" } in a row of offers
    void OpenMap();                          // { "call": "OpenMap" }

    TNX_WIDGET(PlayerHud, Player, Shop, Gold, Health, Buy, OpenMap)
};
TNX_REGISTER_WIDGET(PlayerHud)

TnxUI::SetHud<PlayerHud>(world, soul, Body);   // its asset is "PlayerHud", "class": "PlayerHud"

What an asset naming the class is given and can call is declared here, so it is typed, checked when the asset loads, and found by the designer. A context the widget can't do without is a constructor parameter: leaving it out doesn't compile. A member that is a widget class is the element of its name using an asset of that class: given what the member has, calling its methods. Methods run on the UI update, when an action calls them; to change game state they send a command (TnxSim::Send). The asset keeps its layout, look, and animation.

Namespaces

namespace TnxWidgets
namespace TnxUI

Classes

template<typename T>
class TnxContextOf
Game state a widget reads: an entity of type T (TnxContextOf<EPlayer<>>), or a view model (TnxContextOf<ShopInfo>). Empty until given one.
template<typename T>
class TnxInput
A value a widget class gives its asset: a number (float, int32_t, bool), shown as it changes with nothing built again; or text (a string ID) or a colour, which builds the widget again when set to something else.
struct TnxWidgets::ContextSource
Gives a widget's constructor the contexts it takes, by type, when a tool makes one (ClassType::Make).
struct TnxWidgets::ClassType
A registered widget class: what assets see of it, and how its instances are used.
class TnxWidgetBase
The non-template part of every widget class.
template<typename T>
class TnxWidget
The base of a widget class: class PlayerHud : public TnxWidget<PlayerHud>. T lists what its assets see with TNX_WIDGET, and is registered with TNX_REGISTER_WIDGET.
struct TnxWidgets::Deleter
Owns a widget, destroying it as its class does.