-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxframes-runner.h
147 lines (100 loc) · 3.85 KB
/
xframes-runner.h
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
#ifndef XFRAMES_RUNNER_H
#define XFRAMES_RUNNER_H
#include <cstdio>
#include <utility>
#include <vector>
#include <optional>
#include <functional>
#include <string>
#include <set>
#include <jni.h>
#include <GLFW/glfw3.h>
#include <GLES3/gl3.h>
#include "imgui.h"
#include "implot.h"
#include "implot_internal.h"
#include <nlohmann/json.hpp>
#include "color_helpers.h"
#include "xframes.h"
#include "implot_renderer.h"
#include <nlohmann/json.hpp>
#include "callbacks-handler.h"
using json = nlohmann::json;
typedef void (*OnInitCb)();
typedef void (*OnTextChangedCb)(int, const char*);
typedef void (*OnComboChangedCb)(int, int);
typedef void (*OnNumericValueChangedCb)(int, float);
typedef void (*OnBooleanValueChangedCb)(int, bool);
typedef void (*OnMultipleNumericValuesChangedCb)(int, float*, int numValues);
typedef void (*OnClickCb)(int);
template <typename T>
std::vector<T> JsonToVector(std::string& data) {
auto parsedData = json::parse(data);
std::vector<T> vec;
for (auto& [key, item] : parsedData.items()) {
vec.push_back(item.template get<T>());
}
return vec;
}
template <typename T>
std::set<T> JsonToSet(std::string& data) {
auto parsedData = json::parse(data);
std::set<T> set;
for (auto& [key, item] : parsedData.items()) {
set.insert(item.template get<T>());
}
return set;
}
json IntVectorToJson(const std::vector<int>& data);
json IntSetToJson(const std::set<int>& data);
class Runner {
protected:
XFrames* m_xframes{};
ImGuiRenderer* m_renderer{};
std::string m_rawFontDefs;
std::string m_assetsBasePath;
std::optional<std::string> m_rawStyleOverridesDefs;
std::function<void()> m_onInit;
std::function<void(int, const std::string&)> m_onTextChange;
std::function<void(int, int)> m_onComboChange;
std::function<void(int, float)> m_onNumericValueChange;
std::function<void(int, bool)> m_onBooleanValueChange;
std::function<void(int, std::vector<float>)> m_onMultipleNumericValuesChange;
std::function<void(int)> m_onClick;
std::unique_ptr<CallbackHandler> m_callbackHandler;
static Runner* instance;
Runner();
public:
static Runner* getInstance();
~Runner();
static void OnInit();
static void OnTextChange(const int id, const std::string& value);
static void OnComboChange(const int id, const int value);
static void OnNumericValueChange(const int id, const float value);
static void OnBooleanValueChange(const int id, const bool value);
// todo: improve
static void OnMultipleNumericValuesChange(const int id, const float* values, const int numValues);
static void OnClick(int id);
void SetHandlers(CallbackHandler& callbackHandler);
void SetRawFontDefs(std::string rawFontDefs);
void SetAssetsBasePath(std::string basePath);
void SetRawStyleOverridesDefs(const std::string& rawStyleOverridesDefs);
void Init();
void Run();
void StartThread();
void Exit();
void ResizeWindow(const int width, const int height);
void SetElement(std::string& elementJsonAsString);
void PatchElement(const int id, std::string& elementJsonAsString);
void ElementInternalOp(const int id, std::string& elementJsonAsString);
void SetChildren(const int id, const std::vector<int>& childrenIds);
void AppendChild(const int parentId, const int childId);
std::vector<int> GetChildren(const int id);
std::string GetAvailableFonts();
void AppendTextToClippedMultiLineTextRenderer(const int id, const std::string& data);
std::string GetStyle();
void PatchStyle(std::string& styleDef);
void SetDebug(const bool debug);
void ShowDebugWindow();
};
#endif // XFRAMES_RUNNER_H