Errors
Functions that can fail return Result<T>:
- It holds either the value or an Error.
- An Error has an ErrorCode and a message.
- It converts to true when it holds the value.
std::fprintf(stderr, "%s\n", result.GetError().message.c_str());
A value, or the Error saying why there is none.
Definition gui_result.h:36
Saved UI state
The library saves UI state as JSON text, and you store that text where you like. Register once what to keep:
- Each thing is registered under a key, a string you choose. Keys must stay the same between runs.
- The objects you name must outlive the call.
PersistWindow("main", mainWindowID);
PersistDocking("dock", dockingLayout);
PersistTable("assets", tableState, columns);
PersistValue("zoom", zoom);
There is also:
Save and restore:
std::string json = app.SaveUIState();
std::fprintf(stderr, "UI state not restored: %s\n", restored.GetError().message.c_str());
- RestoreUIState applies everything at once, except windows. Those apply the next time you declare them.
- Unknown keys, panels and columns are skipped.
Window placement on restore, in order:
- The monitor it was saved on.
- If that is gone, the same place on a monitor of the same size.
- Otherwise the primary monitor, resized to fit its work area.
- If the top edge would still be off every monitor, only the size is restored.
The demo calls the Persist* functions and RestoreUIState at the end of Initialize, and SaveUIState after Run() returns.
Previous: Return values, content and units | Overview