4#include "Renderer/IRenderer.h"
5#include "InspectorGuiHelper.h"
6#include "Services/Variables.h"
7#include "Utilities/Parsing.h"
9#include "Foundation/Reflection/TypeDatabase.h"
27 int inputCallback(ImGuiInputTextCallbackData* )
34void Cogs::Core::variableInspector(Context * context,
bool * show)
37 ImGui::SetNextWindowSize(ImVec2(600, 1000), ImGuiCond_Once);
39 guiBegin(
"Variables", show);
41 auto & variables = context->variables->getVariables();
43 std::unordered_map<std::string, std::vector<Variable *>> groupedVars;
44 std::vector<std::string> groups;
46 for (
auto & p : variables) {
47 auto splits = split(p.second.getName(),
".");
49 if (splits.size() > 1) {
50 std::string name(splits[0]);
51 auto & group = groupedVars[name];
54 groups.emplace_back(name);
57 group.push_back(&p.second);
58 }
else if (splits.size() > 0) {
59 auto & group = groupedVars[
"global"];
61 group.push_back(&p.second);
65 std::sort(groups.begin(), groups.end());
67 for (
auto & g : groups) {
68 auto gs = groupedVars[g];
70 if (ImGui::CollapsingHeader(g.c_str())) {
74 std::sort(gs.begin(), gs.end(), [](
const Variable* a,
const Variable* b) { return a->getName() < b->getName(); });
75 for (
auto & pp : gs) {
76 auto & variable = *pp;
78 auto pName = variable.getName().data();
79 std::string buffer(variable.getValue());
82 InputUserData userData = {
87 auto type = variable.getType();
90 case ParsedDataType::Bool:
92 bool value = variable.getBool();
93 if (ImGui::Checkbox(pName, &value)) {
94 variable.setBool(value);
98 case ParsedDataType::Float:
100 float value = variable.getFloat();
101 if (ImGui::DragFloat(pName, &value)) {
102 variable.setFloat(value);
106 case ParsedDataType::Double:
108 float value = (float)variable.getDouble();
109 if (ImGui::DragFloat(pName, &value)) {
110 variable.setDouble(value);
114 case ParsedDataType::Int:
116 int value = variable.getInt();
117 if (ImGui::DragInt(pName, &value)) {
118 variable.setInt(value);
123 if (ImGui::InputText(pName, buffer.data(), buffer.size(), ImGuiInputTextFlags_EnterReturnsTrue, inputCallback, &userData)) {
125 ImguiRenderer* guiRenderer = context->renderer->getGuiRenderer();
127 guiRenderer->addTextToGlyphBuilder(buffer.data());
130 variable.setValue(buffer.c_str());
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Contains reflection support.
Contains all Cogs related functionality.
Runtime control variable.