1
0
mirror of synced 2025-01-29 19:17:28 +01:00

patterns/ui: Limit displaying of array entries to 50 with option to double click last entry for more

This commit is contained in:
WerWolv 2022-01-11 22:38:50 +01:00
parent 3c1f0057ae
commit cbfe52c756
2 changed files with 38 additions and 18 deletions

View File

@ -17,14 +17,14 @@ namespace hex::plugin::builtin {
}
static bool beginPatternDataTable(prv::Provider* &provider, const std::vector<pl::PatternData*> &patterns, std::vector<pl::PatternData*> &sortedPatterns) {
if (ImGui::BeginTable("##patterndatatable", 6, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY)) {
if (ImGui::BeginTable("##patterndatatable", 6, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Sortable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY)) {
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableSetupColumn("hex.builtin.view.pattern_data.var_name"_lang, 0, -1, ImGui::GetID("name"));
ImGui::TableSetupColumn("hex.builtin.view.pattern_data.color"_lang, 0, -1, ImGui::GetID("color"));
ImGui::TableSetupColumn("hex.builtin.view.pattern_data.offset"_lang, 0, -1, ImGui::GetID("offset"));
ImGui::TableSetupColumn("hex.builtin.view.pattern_data.size"_lang, 0, -1, ImGui::GetID("size"));
ImGui::TableSetupColumn("hex.builtin.view.pattern_data.type"_lang, 0, -1, ImGui::GetID("type"));
ImGui::TableSetupColumn("hex.builtin.view.pattern_data.value"_lang, 0, -1, ImGui::GetID("value"));
ImGui::TableSetupColumn("hex.builtin.view.pattern_data.var_name"_lang, 0, 0, ImGui::GetID("name"));
ImGui::TableSetupColumn("hex.builtin.view.pattern_data.color"_lang, 0, 0, ImGui::GetID("color"));
ImGui::TableSetupColumn("hex.builtin.view.pattern_data.offset"_lang, 0, 0, ImGui::GetID("offset"));
ImGui::TableSetupColumn("hex.builtin.view.pattern_data.size"_lang, 0, 0, ImGui::GetID("size"));
ImGui::TableSetupColumn("hex.builtin.view.pattern_data.type"_lang, 0, 0, ImGui::GetID("type"));
ImGui::TableSetupColumn("hex.builtin.view.pattern_data.value"_lang, 0, 0, ImGui::GetID("value"));
auto sortSpecs = ImGui::TableGetSortSpecs();

View File

@ -782,23 +782,28 @@ namespace hex::pl {
}
if (open) {
for (auto &member : this->m_entries)
member->draw(provider);
for (u64 i = 0; i < this->m_entries.size(); i++) {
this->m_entries[i]->draw(provider);
if (i >= (this->m_displayEnd - 1)) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Selectable("... (Double-click to see more items)", false, ImGuiSelectableFlags_SpanAllColumns);
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
this->m_displayEnd += 50;
break;
}
}
if (!this->isInlined())
ImGui::TreePop();
} else {
this->m_displayEnd = 50;
}
}
std::optional<u32> highlightBytes(size_t offset) override{
for (auto &entry : this->m_entries) {
if (auto color = entry->highlightBytes(offset); color.has_value())
return color.value();
}
return { };
}
std::map<u64, u32> getHighlightedAddresses() override {
std::map<u64, u32> result;
@ -843,6 +848,7 @@ namespace hex::pl {
private:
std::vector<PatternData*> m_entries;
u64 m_displayEnd = 50;
};
class PatternDataStaticArray : public PatternData, public Inlinable {
@ -900,11 +906,24 @@ namespace hex::pl {
entry->setVariableName(hex::format("[{0}]", index));
entry->setOffset(this->getOffset() + index * this->m_template->getSize());
entry->draw(provider);
if (index >= (this->m_displayEnd - 1)) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Selectable("... (Double-click to see more items)", false, ImGuiSelectableFlags_SpanAllColumns);
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
this->m_displayEnd += 50;
break;
}
}
delete entry;
if (!this->isInlined())
ImGui::TreePop();
} else {
this->m_displayEnd = 50;
}
}
@ -962,6 +981,7 @@ namespace hex::pl {
private:
PatternData *m_template;
size_t m_entryCount;
u64 m_displayEnd = 50;
};
class PatternDataStruct : public PatternData, public Inlinable {