ImHex/source/views/view_pattern_data.cpp

76 lines
3.0 KiB
C++
Raw Normal View History

2020-11-10 20:31:04 +00:00
#include "views/view_pattern_data.hpp"
#include <hex/providers/provider.hpp>
#include <hex/lang/pattern_data.hpp>
2020-11-10 20:31:04 +00:00
namespace hex {
ViewPatternData::ViewPatternData() : View("hex.view.pattern_data.name") {
2020-11-10 20:31:04 +00:00
EventManager::subscribe<EventPatternChanged>(this, [this]() {
2020-11-14 23:46:18 +00:00
this->m_sortedPatternData.clear();
});
2020-11-10 20:31:04 +00:00
}
ViewPatternData::~ViewPatternData() {
EventManager::unsubscribe<EventPatternChanged>(this);
2020-11-10 20:31:04 +00:00
}
2020-11-19 20:19:03 +00:00
static bool beginPatternDataTable(prv::Provider* &provider, const std::vector<lang::PatternData*> &patterns, std::vector<lang::PatternData*> &sortedPatterns) {
if (ImGui::BeginTable("##patterndatatable", 6, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY)) {
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableSetupColumn("hex.view.pattern_data.name"_lang, 0, -1, ImGui::GetID("name"));
ImGui::TableSetupColumn("hex.view.pattern_data.color"_lang, 0, -1, ImGui::GetID("color"));
ImGui::TableSetupColumn("hex.view.pattern_data.offset"_lang, 0, -1, ImGui::GetID("offset"));
ImGui::TableSetupColumn("hex.view.pattern_data.size"_lang, 0, -1, ImGui::GetID("size"));
ImGui::TableSetupColumn("hex.view.pattern_data.type"_lang, 0, -1, ImGui::GetID("type"));
ImGui::TableSetupColumn("hex.view.pattern_data.value"_lang, 0, -1, ImGui::GetID("value"));
2020-11-19 20:19:03 +00:00
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(View::toWindowName("hex.view.pattern_data.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
auto provider = SharedData::currentProvider;
if (provider != nullptr && provider->isReadable()) {
2020-11-10 20:31:04 +00:00
if (beginPatternDataTable(provider, SharedData::patternData, this->m_sortedPatternData)) {
ImGui::TableHeadersRow();
if (this->m_sortedPatternData.size() > 0) {
2020-11-22 19:41:54 +00:00
for (auto &patternData : this->m_sortedPatternData)
2021-06-17 21:42:43 +00:00
patternData->draw(provider);
2020-11-14 23:46:18 +00:00
}
ImGui::EndTable();
}
2020-11-14 23:46:18 +00:00
2020-11-10 20:31:04 +00:00
}
}
ImGui::End();
2020-11-10 20:31:04 +00:00
}
void ViewPatternData::drawMenu() {
2020-11-10 20:31:04 +00:00
}
}