#include "views/view_pattern_data.hpp" #include #include namespace hex { ViewPatternData::ViewPatternData(std::vector &patternData) : View("Pattern Data"), m_patternData(patternData) { this->subscribeEvent(Events::PatternChanged, [this](auto data) { this->m_sortedPatternData.clear(); }); } ViewPatternData::~ViewPatternData() { this->unsubscribeEvent(Events::PatternChanged); } static bool beginPatternDataTable(prv::Provider* &provider, const std::vector &patterns, std::vector &sortedPatterns) { if (ImGui::BeginTable("##patterndatatable", 6, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY)) { ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableSetupColumn("Name", 0, -1, ImGui::GetID("name")); ImGui::TableSetupColumn("Color", 0, -1, ImGui::GetID("color")); ImGui::TableSetupColumn("Offset", 0, -1, ImGui::GetID("offset")); ImGui::TableSetupColumn("Size", 0, -1, ImGui::GetID("size")); ImGui::TableSetupColumn("Type", 0, -1, ImGui::GetID("type")); ImGui::TableSetupColumn("Value", 0, -1, ImGui::GetID("value")); auto sortSpecs = ImGui::TableGetSortSpecs(); if (sortSpecs->SpecsDirty || sortedPatterns.empty()) { sortedPatterns = patterns; std::sort(sortedPatterns.begin(), sortedPatterns.end(), [&sortSpecs, &provider](lang::PatternData* left, lang::PatternData* right) -> bool { return lang::PatternData::sortPatternDataTable(sortSpecs, provider, left, right); }); for (auto &pattern : sortedPatterns) pattern->sort(sortSpecs, provider); sortSpecs->SpecsDirty = false; } return true; } return false; } void ViewPatternData::drawContent() { if (ImGui::Begin("Pattern Data", &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) { auto provider = SharedData::currentProvider; if (provider != nullptr && provider->isReadable()) { if (beginPatternDataTable(provider, this->m_patternData, this->m_sortedPatternData)) { ImGui::TableHeadersRow(); if (this->m_sortedPatternData.size() > 0) { for (auto &patternData : this->m_sortedPatternData) patternData->createEntry(provider); } ImGui::EndTable(); } } } ImGui::End(); } void ViewPatternData::drawMenu() { } }