-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathosgui_examples.cpp
More file actions
227 lines (189 loc) · 7.43 KB
/
Copy pathosgui_examples.cpp
File metadata and controls
227 lines (189 loc) · 7.43 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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#include "osgui.h"
#include "osgui_examples.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
namespace og {
void ShowSettingsExample(bool* open) {
SetNextWindowSize(Vec2(660, 590), Cond_FirstUseEver);
if (!Begin("Example / Settings", open)) {
End();
return;
}
static bool autosave = true;
static bool telemetry = false;
static int language = 0;
static int autosave_seconds = 30;
static float notification_volume = 0.7f;
static char profile[64] = "Developer";
TextColored(Vec4(0.55f, 0.93f, 0.85f, 1.0f), "PRODUCT SETTINGS");
SameLine();
StatusBadge("Local profile", GetColorU32(Col_Info));
TextDisabled("Scoped state, accessible disabled controls, and precision inputs.");
Separator();
if (BeginGrid("settings-columns", 2, 16.0f)) {
TextDisabled("GENERAL");
InputText("Profile", profile, (int)sizeof(profile));
const char* languages[] = {"English", "Deutsch", "Japanese", "Spanish"};
Combo("Language", &language, languages, 4);
Checkbox("Automatic saves", &autosave);
Checkbox("Anonymous telemetry", &telemetry);
BeginDisabled(!autosave);
DragInt("Save interval", &autosave_seconds, 0.5f, 5, 300);
EndDisabled();
NextGridColumn();
TextDisabled("FEEDBACK");
KnobFloat("Volume", ¬ification_volume, 0.0f, 1.0f,
0.01f, Vec2(96, 108));
ProgressBar(notification_volume, Vec2(-1, 24), "Notification volume");
BeginDisabled(profile[0] == 0);
if (Button("Save settings", Vec2(-1, 36)))
AddToast("Settings saved", Toast_Success);
const bool save_visible = IsItemVisible();
EndDisabled();
TextDisabled("Save action visible: %s", save_visible ? "yes" : "no");
EndGrid();
}
End();
}
void ShowLauncherExample(bool* open) {
SetNextWindowSize(Vec2(720, 520), Cond_FirstUseEver);
if (!Begin("Example / Launcher", open)) {
End();
return;
}
static int channel = 0;
static int parallel_downloads = 6;
static bool verify_assets = true;
static bool loading_manifest = false;
TextColored(Vec4(0.55f, 0.93f, 0.85f, 1.0f), "OSGUI 2.0 ALPHA LAUNCHER");
SameLine();
StatusBadge("Services healthy", GetColorU32(Col_Success), true);
TextDisabled("Version %s / renderer-ready workspace", GetVersion());
GlassCard("Signed manifest / 18 packages / native backends ready", Vec2(-1, 64), 7.0f);
const char* channels[] = {"Stable", "Preview", "Nightly"};
Combo("Release channel", &channel, channels, 3);
Checkbox("Verify assets before launch", &verify_assets);
DragInt("Parallel downloads", ¶llel_downloads, 0.25f, 1, 16);
ProgressBar(0.82f, Vec2(-1, 30), "Preparing shaders");
Spinner("Indexing package graph", 8.0f, 2.0f, GetColorU32(Col_Info));
Checkbox("Preview loading state", &loading_manifest);
if (loading_manifest) {
Skeleton(Vec2(-1, 14));
Skeleton(Vec2(-110, 14));
Skeleton(Vec2(-220, 52), 9.0f);
}
BeginDisabled(loading_manifest);
if (Button("Launch workspace", Vec2(190, 40)))
AddToast("Workspace launched", Toast_Success);
const bool launch_hovered = IsItemHovered();
EndDisabled();
if (launch_hovered)
SetTooltip("Launch emits a frame-local click event and a toast.");
End();
}
void ShowFileBrowserExample(bool* open) {
SetNextWindowSize(Vec2(760, 610), Cond_FirstUseEver);
if (!Begin("Example / Virtual File Browser", open)) {
End();
return;
}
static char filter[96] = "";
static int selected_file = 0;
static int pinned_file = -1;
InputText("Filter", filter, (int)sizeof(filter));
TextDisabled("C:/Projects/osgui-v2 / 250 synthetic entries");
if (filter[0] != 0)
StatusBadge("Host filter active", GetColorU32(Col_Info));
if (BeginChild("virtual-files", Vec2(-1, 350),
ChildFlags_Borders | ChildFlags_AlwaysUseWindowPadding)) {
const float row_step = 27.0f;
ListClipper clipper;
clipper.Begin(250, row_step);
while (clipper.Step()) {
for (int file_index = clipper.display_start;
file_index < clipper.display_end;
++file_index) {
char label[96];
if ((file_index % 11) == 0)
snprintf(label, sizeof(label), "folder_%03d/", file_index);
else
snprintf(label, sizeof(label), "module_%03d.cpp", file_index);
PushID(file_index);
if (Selectable(label, selected_file == file_index,
Vec2(-1, row_step - GetStyle().item_spacing.y))) {
selected_file = file_index;
}
if (BeginDragDropSource()) {
SetDragDropPayload("OSGUI_FILE_INDEX", &file_index, (int)sizeof(file_index));
Text("Pin %s", label);
EndDragDropSource();
}
PopID();
}
}
clipper.End();
}
EndChild();
Button("Drop a row here to pin it", Vec2(-1, 42));
if (BeginDragDropTarget()) {
const Payload* payload = AcceptDragDropPayload("OSGUI_FILE_INDEX");
if (payload && payload->delivery && payload->data_size == (int)sizeof(pinned_file)) {
memcpy(&pinned_file, payload->data, sizeof(pinned_file));
AddToast("File pinned", Toast_Success);
}
EndDragDropTarget();
}
Text("Selected row: %d", selected_file);
if (pinned_file >= 0)
StatusBadge("Pinned to workspace", GetColorU32(Col_Success));
End();
}
void ShowPerformanceMonitorExample(bool* open) {
SetNextWindowSize(Vec2(800, 650), Cond_FirstUseEver);
if (!Begin("Example / Performance Monitor", open)) {
End();
return;
}
static StreamingSeries cpu(240);
static StreamingSeries gpu(240);
static float time = 0.0f;
static float refresh_rate = 60.0f;
time += GetIO().delta_time;
cpu.Push(42.0f + sinf(time * 2.1f) * 18.0f);
gpu.Push(58.0f + sinf(time * 1.4f + 1.0f) * 14.0f);
TextColored(Vec4(0.55f, 0.93f, 0.85f, 1.0f), "LIVE PERFORMANCE");
SameLine();
StatusBadge("Sampling", GetColorU32(Col_Success), true);
SameLine();
Spinner("", 7.0f, 2.0f, GetColorU32(Col_Info));
if (BeginGrid("performance-cards", 3, 12.0f)) {
char value[32];
snprintf(value, sizeof(value), "%.0f", GetIO().framerate);
MetricCard("Frame rate", value, "frames / second", GetColorU32(Col_Success));
NextGridColumn();
MetricCard("CPU", "42%", "rolling average", GetColorU32(Col_Info));
NextGridColumn();
MetricCard("GPU", "58%", "rolling average", GetColorU32(Col_Warning));
EndGrid();
}
DragFloat("Sample rate", &refresh_rate, 0.5f, 10.0f, 240.0f, "%.0f Hz");
if (BeginChart("CPU and GPU / percent", Vec2(-1, 210))) {
ChartLine("CPU", cpu, GetColorU32(Col_Info));
ChartLine("GPU", gpu, GetColorU32(Col_Warning));
EndChart();
}
const Candlestick candles[] = {
Candlestick(32, 48, 28, 43),
Candlestick(43, 51, 39, 41),
Candlestick(41, 56, 40, 53),
Candlestick(53, 57, 45, 47),
Candlestick(47, 61, 46, 59)
};
if (BeginChart("Frame ranges", Vec2(-1, 180))) {
ChartCandlesticks("Frame", candles, 5);
EndChart();
}
End();
}
} // namespace og