UI.h file
UI: the builder a widget function is handed.
A widget is a function taking a UI. Containers come in two forms:
Scope `if (auto row = ui.Row({...})) { ... }` Everything built in the block is a child. Lambda `ui.Row({...}, [&] { ... });` Content passed to the element.
A lambda that takes the UI is stored content: ui.Row({...}, [=](UI& ui) { ... });. It can be built later than its box (BoxProps::Priority, Wait) and re-runs on its own when state or watched data inside it changes. It also follows what the components around it watch, so one ui.Watch at the top of a panel covers its tabs, panes and popups. When the enclosing function re-runs for its own state, stored content with the same captures is skipped. Capture by value.
void HealthRow(UI& ui, int health) { if (auto row = ui.Row({ .Gap = 8, .Align = GGAlign::Center })) { ui.Label("Health"); ui.Button("Reset", [] { ResetHealth(); }); } }
Re-running a function doesn't rebuild the tree. Each element is matched to the node it produced last time and only differences are applied. Elements are identified by source location, so an if that removes one doesn't disturb its siblings. Where one line builds many elements (a loop), give each a key that follows the data:
for (const Item& item : items) { ui.Key(item.ID); // identity survives reordering ui.Label(item.Name); }
Namespaces
- namespace GGUI
Classes
- struct GGUI::RichTextProps
- Properties of ui.RichText: how the text is laid out, as TextProps, and what clicking one of its links does.
- class GGUI::Scope
- An open container. Closes on destruction.
- class GGUI::UI
- The builder a widget function is handed. See the file description.
- struct GGUI::UI::ValueSpec
- Type-erased "what it shows" and "what an edit does" for a value widget.
-
template<typename T>class GGUI::WidgetScope
- WidgetScope<T>: a widget's node while it is being built, plus its state.