| 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; |
no test coverage detected