Repository navigation
Expand file tree
/
Copy pathhello_world.cpp
More file actions
65 lines (56 loc) · 1.82 KB
/
Copy pathhello_world.cpp
File metadata and controls
65 lines (56 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Hello world: one window with a text field and a few buttons.
#include <gui_controls/gui_application.h>
#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:
tachyon::ID windowID = tachyon::ID::Invalid();
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;
}