This repository was archived by the owner on Sep 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.cpp
146 lines (109 loc) · 4.77 KB
/
example.cpp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "rvmt.hpp"
#include <iostream>
#include <thread>
// How this example works.
// RVMT::Start() sets some necessary terminal config up.
// In the main loop | while (!quit)
// Internal variables are prepared to render a new frame by a function | RVMT::BeginFrame()
// Stuff is written | widgets and things.
// Stuff is rendered | RVMT::Render.
// A function stalls the loop until a new input is detected | RVMT::WaitForNewInput()
// RVMT::Stop() resets the terminal to its previous settings.
enum GUIPage {
GUIPage_Button,
GUIPage_Checkbox,
GUIPage_Slider,
GUIPage_InputText,
};
GUIPage GUIPage_Current = GUIPage_Button;
int main() {
RVMT::Start();
RVMT::SetTerminalTitle("RVMT v2.0 Example");
bool quit = false;
while (!quit) {
RVMT::BeginFrame();
const unsigned short rowCount = RVMT::GetRowCount();
const unsigned short colCount = RVMT::GetColCount();
// === Bottom bar
RVMT::SetCursorY(NewCursorPos_ABSOLUTE, rowCount - 3);
RVMT::SetCursorX(NewCursorPos_ABSOLUTE, 0);
if (RVMT::Button("Button"))
GUIPage_Current = GUIPage_Button;
RVMT::SameLine();
if (RVMT::Button("Checkbox"))
GUIPage_Current = GUIPage_Checkbox;
RVMT::SameLine();
if (RVMT::Button("Slider"))
GUIPage_Current = GUIPage_Slider;
RVMT::SameLine();
if (RVMT::Button("InputText"))
GUIPage_Current = GUIPage_InputText;
RVMT::SameLine();
RVMT::SetCursorX(NewCursorPos_ABSOLUTE, colCount - 8);
if (RVMT::Button(" Quit "))
quit = true;
RVMT::SetCursorY(NewCursorPos_ABSOLUTE, 0);
RVMT::SetCursorX(NewCursorPos_ABSOLUTE, 0);
switch (GUIPage_Current) {
case GUIPage_Button:
static bool textOnlyCB = false;
static unsigned int totalClicks = 0;
RVMT::Text("RVMT::Button | When clicked, return true.\n");
RVMT::Text("WidgetProp_Button_TextOnly ");
RVMT::SameLine();
RVMT::Checkbox("[Disable]", "[Enable]", &textOnlyCB);
RVMT::Text("Draw the button as text only, no box.\n");
if (textOnlyCB)
RVMT::PushPropertyForNextItem(WidgetProp_Button_TextOnly);
if (RVMT::Button("The button"))
totalClicks++;
RVMT::Text("%i clicks.", totalClicks);
break;
case GUIPage_Checkbox:
static bool sampleCB = false;
RVMT::Text("RVMT::Checkbox | When clicked, \"invert\" the assigned bool.\n");
RVMT::Checkbox("[trueText]", "[falseText]", &sampleCB);
break;
case GUIPage_Slider:
static float sampleFloatSlider = 3.0;
RVMT::Text("RVMT::Slider | A draggable slider.\n");
RVMT::Text("RVMT::Slider ");
RVMT::SameLine();
RVMT::Slider("sample float slider", 10, 3.0, 1.31, &sampleFloatSlider);
RVMT::SameLine();
RVMT::Text(" %.2f", sampleFloatSlider);
break;
case GUIPage_InputText:
static char sampleInputChar[33];
static bool censorOutputCB = false;
static bool customCharsetCB = false;
static bool customPlaceholderCB = false;
RVMT::Text("RVMT::InputText | A field to write text into");
RVMT::Text("WidgetProp_InputText_Censor ");
RVMT::SameLine();
RVMT::Checkbox("[Disable]", "[Enable]", &censorOutputCB);
RVMT::Text("Censor typed characters, print an asterisk instead of the actual characters.\n");
RVMT::Text("WidgetProp_InputText_Charset (Numbers only) ");
RVMT::SameLine();
RVMT::Checkbox("[Disable]", "[Enable]", &customCharsetCB);
RVMT::Text("Provide a custom charset so only characters in the charset can be typed.\n");
RVMT::Text("WidgetProp_InputText_Placeholder (hello) ");
RVMT::SameLine();
RVMT::Checkbox("[Disable]", "[Enable]", &customPlaceholderCB);
RVMT::Text("Provide a placeholder that will be shown in the field when it's empty and not active.\n");
if (censorOutputCB)
RVMT::PushPropertyForNextItem(WidgetProp_InputText_Censor);
if (customCharsetCB)
RVMT::PushPropertyForNextItem(WidgetProp_InputText_Charset, "0123456789");
if (customPlaceholderCB)
RVMT::PushPropertyForNextItem(WidgetProp_InputText_Placeholder, "hello");
RVMT::InputText("sampleInputChar field", sampleInputChar, 32, 16);
break;
}
RVMT::Render();
RVMT::WaitForNewInput();
}
std::wcout << "\nExited main loop."; std::wcout.flush();
RVMT::Stop();
return 0;
}