TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
hello_world/hello_world.cpp

The smallest app: a window, a text field and buttons, and the program around them.

The smallest app: a window, a text field and buttons, and the program around them.Walkthrough: Hello world.

// Hello world: one window with a text field and a few buttons.
#include <cstdio>
#include <string>
class HelloApp : public tachyon::GUIApplication
{
public:
tachyon::Result<void> Initialize(const InitializeOptions& options = {}) override
{
if (tachyon::Result<void> result = GUIApplication::Initialize(options); !result)
return result;
// Windows need IDs that stay the same from frame to frame.
windowID = idManager.CreateStaticID();
return {};
}
// Called every frame: describe the whole UI, the library keeps the state.
void OnGUI() override
{
if (BeginWindow(windowID, "Hello", tachyon::LayoutOverride{}.Size(360, 160)))
{
// A window lays its children out in wrapping rows; stack them instead.
BeginVertical(tachyon::LayoutOverride{}.FlexGrow(1));
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();
Text(greeting);
EndVertical();
}
EndWindow();
}
private:
std::string name = "world";
std::string greeting;
};
int main()
{
HelloApp app;
tachyon::Result<void> result = app.Initialize();
if (result)
result = app.Run(); // until the last window closes
app.Cleanup();
if (!result)
{
std::fprintf(stderr, "%s\n", result.GetError().message.c_str());
return 1;
}
return 0;
}
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
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
A 64-bit element ID whose bit layout depends on its IDMode.
Definition gui_id.h:23
static constexpr ID Invalid()
The "no element" ID (all bits zero); also the default for optional ID parameters.
Definition gui_id.h:66
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