MCPcopy Create free account
hub / github.com/SatDump/SatDump / JSONTreeEditor

Function JSONTreeEditor

src-core/common/widgets/json_editor.cpp:108–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106
107 template <typename T>
108 void JSONTreeEditor(T& json, const char* id, bool allow_add)
109 {
110 ImGui::PushID(id);
111 int array_index = 0;
112 float start_pos = ImGui::GetCursorPosX();
113 bool delete_item = false;
114
115 for (auto jsonItem = json.begin(); jsonItem != json.end(); )
116 {
117 std::string this_key;
118 if (json.is_array())
119 this_key = std::to_string(array_index++);
120 else
121 this_key = jsonItem.key();
122
123 ImGui::PushID(this_key.c_str());
124 if (jsonItem.value().is_object())
125 {
126 bool nodeOpen = ImGui::TreeNode(std::string((json.is_array() ? "##" : "") + this_key).c_str());
127 ImGui::SameLine();
128 ImGui::TextDisabled("%s", "[Object]");
129 delete_item = DeleteButton();
130 if (nodeOpen)
131 {
132 JSONTreeEditor(jsonItem.value(), this_key.c_str());
133 ImGui::TreePop();
134 }
135 }
136 else if (jsonItem.value().is_array())
137 {
138 bool nodeOpen = ImGui::TreeNode(std::string((json.is_array() ? "##" : "") + this_key).c_str());
139 ImGui::SameLine();
140 ImGui::TextDisabled("%s", jsonItem.value().dump().c_str());
141 delete_item = DeleteButton();
142 if (nodeOpen)
143 {
144 JSONTreeEditor(jsonItem.value(), this_key.c_str());
145 ImGui::TreePop();
146 }
147 }
148 else if (jsonItem.value().is_boolean())
149 {
150 if (!json.is_array())
151 {
152 ImGui::BulletText("%s", this_key.c_str());
153 ImGui::SameLine();
154 }
155 bool val = jsonItem.value();
156 if (ImGui::Checkbox(std::string("##" + this_key).c_str(), &val))
157 jsonItem.value() = val;
158 delete_item = DeleteButton();
159 }
160 else if (jsonItem.value().is_number_integer() || jsonItem.value().is_number_unsigned())
161 {
162 if (!json.is_array())
163 {
164 ImGui::BulletText("%s", this_key.c_str());
165 ImGui::SameLine();

Callers 2

renderFunction · 0.85
JSONTableEditorFunction · 0.85

Calls 15

to_stringFunction · 0.85
DeleteButtonFunction · 0.85
SetNextItemWidthFunction · 0.85
InputIntFunction · 0.85
InputDoubleFunction · 0.85
c_strMethod · 0.80
stringFunction · 0.50
SameLineFunction · 0.50
CheckboxFunction · 0.50
InputTextFunction · 0.50
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected