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

Function JSONTableEditor

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

Source from the content-addressed store, hash-verified

216 }
217
218 bool JSONTableEditor(nlohmann::json &json, const char* id)
219 {
220 ImGui::PushID(id);
221 ImVec2 start_pos = ImGui::GetCursorPos();
222 ImGui::SetCursorPos({ start_pos.x + 3 * ui_scale, start_pos.y + 10 * ui_scale });
223 ImGui::AlignTextToFramePadding();
224 ImGui::TextUnformatted(id);
225 ImGui::SameLine();
226 AddButton<nlohmann::json>(json, true);
227 ImGui::SameLine();
228 bool ret = ImGui::Button(std::string("Reset##" + std::string(id)).c_str());
229
230 if (json.size() > 0)
231 {
232 if (ImGui::BeginTable(std::string(std::string(id) + "##table").c_str(), 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg))
233 {
234 int array_index = 0;
235 bool delete_item = false;
236
237 for (auto jsonItem = json.begin(); jsonItem != json.end(); )
238 {
239 std::string this_key;
240 if (json.is_array())
241 this_key = std::to_string(array_index++);
242 else
243 this_key = jsonItem.key();
244
245 ImGui::PushID(this_key.c_str());
246 ImGui::TableNextRow();
247 ImGui::TableSetColumnIndex(0);
248 if (!json.is_array())
249 ImGui::TextUnformatted(this_key.c_str());
250
251 ImGui::TableSetColumnIndex(1);
252 if (jsonItem.value().is_object())
253 {
254 ImGui::TextDisabled("%s", "[Object]");
255 delete_item = DeleteButton();
256 JSONTreeEditor(jsonItem.value(), this_key.c_str());
257 }
258 else if (jsonItem.value().is_array())
259 {
260 ImGui::TextDisabled("%s", jsonItem.value().dump().c_str());
261 delete_item = DeleteButton();
262 JSONTreeEditor(jsonItem.value(), this_key.c_str());
263 }
264 else if (jsonItem.value().is_boolean())
265 {
266 bool val = jsonItem.value();
267 if (ImGui::Checkbox(std::string("##" + this_key).c_str(), &val))
268 jsonItem.value() = val;
269 delete_item = DeleteButton();
270 }
271 else if (jsonItem.value().is_number_integer() || jsonItem.value().is_number_unsigned())
272 {
273 int val = jsonItem.value();
274 if (ImGui::InputInt(std::string("##" + this_key).c_str(), &val))
275 jsonItem.value() = val;

Callers 2

drawProjectionPanelMethod · 0.85
renderParamTableMethod · 0.85

Calls 15

GetCursorPosFunction · 0.85
BeginTableFunction · 0.85
to_stringFunction · 0.85
TableNextRowFunction · 0.85
TableSetColumnIndexFunction · 0.85
DeleteButtonFunction · 0.85
JSONTreeEditorFunction · 0.85
InputIntFunction · 0.85
InputDoubleFunction · 0.85
EndTableFunction · 0.85
SeparatorFunction · 0.85
c_strMethod · 0.80

Tested by

no test coverage detected