#include #include #include #include #include #include #include #include namespace hex::plugin::visualizers { void drawTableVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span arguments) { static std::vector tableContent; static u128 width = 0, height = 0; if (shouldReset) { tableContent.clear(); width = height = 0; auto pattern = arguments[0].toPattern(); if (dynamic_cast(pattern.get()) == nullptr && dynamic_cast(pattern.get()) == nullptr && dynamic_cast(pattern.get()) == nullptr) { throw std::logic_error("Table visualizer requires an array pattern as the first argument."); } width = arguments[1].toUnsigned(); height = arguments[2].toUnsigned(); auto iterable = dynamic_cast(pattern.get()); iterable->forEachEntry(0, iterable->getEntryCount(), [&](u64, pl::ptrn::Pattern *entry) { tableContent.push_back(entry->toString()); }); } if (width >= IMGUI_TABLE_MAX_COLUMNS) throw std::logic_error(hex::format("Table visualizer cannot have more than {} columns.", IMGUI_TABLE_MAX_COLUMNS)); if (ImGui::BeginTable("##visualizer_table", width, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg)) { for (u128 i = 0; i < height; i += 1) { ImGui::TableNextRow(); for (u128 j = 0; j < width; j += 1) { ImGui::TableSetColumnIndex(j); if (i * width + j < tableContent.size()) ImGui::TextUnformatted(tableContent[(i * width) + j].c_str()); else ImGui::TextUnformatted("??"); } } ImGui::EndTable(); } } }