One window with a text field and three buttons: the smallest complete TachyonUI program. Full source: examples/hello_world/hello_world.cpp.
The application class
- A TachyonUI program is a class derived from tachyon::GUIApplication:
- GUIApplication owns the windows and runs the frame loop
- your class adds the UI and the values it shows
- Set up anything that lasts between frames in Initialize, after calling the base class's Initialize.
{
public:
{
return result;
windowID = idManager.CreateStaticID();
return {};
}
The application: owns the windows, the systems and the frame loop.
Definition gui_application.h:185
A value, or the Error saying why there is none.
Definition gui_result.h:36
- Every control and window has an ID. The library uses it to find the control's state again in the next frame, such as whether it has focus.
- A control makes its ID from the place in your code it is called from, so you don't pass one.
- A window needs a static ID:
- create it once with idManager.CreateStaticID() and keep it in a member
- the library stores the window's position and size by that ID, so it must stay the same from frame to frame
- More about IDs: IDs.
Describing the UI
- OnGUI runs every frame and describes the whole UI. The library lays out and draws what it describes.
- The values the UI shows live in your class. Here they are the members name and greeting.
- The library keeps the rest:
- which control has focus
- the text cursor
- each window's position and size
void OnGUI() override
{
{
Text("Hello from TachyonUI!");
BeginLabelGroup();
Label("Name");
Field(name);
EndLabelGroup();
BeginHorizontal();
Button("Greet", [this] { greeting = "Hello, " + name + "!"; });
Button("Clear", [this] { greeting.clear(); });
Button("Quit", [this] { applicationQuit = true; });
EndHorizontal();
EndVertical();
}
EndWindow();
}
Per-element overrides of style layout properties.
Definition gui_constraints.h:150
LayoutOverride & FlexGrow(int16_t v) &
Overrides the style's flex-grow / flex-shrink.
Definition gui_constraints.h:317
int2 Size() const
The explicit sizes; kAuto on axes without one.
Definition gui_constraints.h:205
The program
- main creates the app, then calls Initialize, Run and Cleanup.
- Run returns when the last window closes.
- No resource files (themes, fonts) are needed next to the program.
int main()
{
HelloApp app;
if (result)
result = app.Run();
app.Cleanup();
if (!result)
{
return 1;
}
return 0;
}
const Error & GetError() const
The error; only valid when !HasValue().
Definition gui_result.h:61
std::string message
what went wrong, for logs and users
Definition gui_result.h:28
- Initialize and Run return Result<void>:
- it converts to true on success
- on failure, GetError().message says why, for example that the GPU lacks a feature
- see Errors and saved state
Examples | Next: Controls