GGUI::GGWidgetFile class

A widget asset's JSON and the tree of elements read out of it.

Public types

struct Step
A step to an element in the JSON: a key of an object, then, if it is a list, an index.
struct Element
An element of the asset, as read out of the JSON.

Public static functions

static auto IdOf(std::string_view name) -> ItemID
The ID an element of that name has.
static auto Holds(const Element& element) -> bool
True if elements of this kind hold others.
static auto NewElement(std::string_view kind, bool bUse, const std::string& name) -> JsonValue
A new element of type kind (or, with bUse, a use of the asset kind), with what it needs to show something.

Public functions

void Read()
Read the element tree out of Root.
auto Find(ItemID item) const -> const Element*
The element with that ID; null if there is none.
auto At(const std::vector<Step>& path) -> JsonValue*
The element's JSON; null if the path leads nowhere.
auto FreeName(std::string_view base, const std::vector<std::string>& taken = {}) const -> std::string
A name no element has, from base without the number it ends in (Label3 gives Label4), and none of taken.
void NameAfresh(JsonValue& element) const
Give every element in element (a subtree, as a copy or a paste is) a name no element of this file has.
auto Insert(JsonValue element, ItemID onto, GGDropPlace place) -> bool
Put element before, after, or inside onto (0: inside the root). False if it can't go there: inside something that holds nothing, or beside the root.
auto Remove(ItemID item) -> JsonValue
Take item out and return it. Nothing for the root.
auto Move(const std::vector<ItemID>& items, ItemID onto, GGDropPlace place) -> bool
Move items, in order, before, after, or inside onto. False, with nothing changed, if that would put one inside itself.
auto Wrap(ItemID item, std::string_view type, const std::string& name) -> bool
Put item in a new element of type type, named name, where it was. False if it isn't there.
auto Replace(ItemID item, std::string_view type) -> bool
Make item an element of type type: its name, layout, and children stay. False if it isn't there.
auto Rename(ItemID item, std::string_view name) -> bool
Rename item, and what names it in animations, triggers, and actions. False if the name isn't a word (letters, digits, underscores, not starting with a digit) or is taken.
auto CommentToNote(ItemID item) -> bool
Make the comment written before item its note. False if there is none.
auto Migrate() -> std::vector<std::string>
Write what the file calls by an old name by its new one (Switch is Switcher, layer is zOrder, an image's region is crop, ...), keys staying where they were.

Public variables

JsonValue Root
the whole file, comments kept
std::vector<Element> Elements
the root first, then each element before what it holds

Function documentation

std::vector<std::string> GGUI::GGWidgetFile::Migrate()

Write what the file calls by an old name by its new one (Switch is Switcher, layer is zOrder, an image's region is crop, ...), keys staying where they were.

Returns what it changed, "old → new", each once.