From 264da1ed785d04d9cf15fe76b52b442450ba49d3 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 20 Dec 2022 20:56:01 +0100 Subject: [PATCH] pattern: Show array entries directly if there are less than 512 --- cmake/build_helpers.cmake | 2 +- lib/external/pattern_language | 2 +- plugins/builtin/source/ui/pattern_drawer.cpp | 56 +++++++++++--------- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/cmake/build_helpers.cmake b/cmake/build_helpers.cmake index 870f935c1..1a71260f5 100644 --- a/cmake/build_helpers.cmake +++ b/cmake/build_helpers.cmake @@ -392,7 +392,7 @@ function(downloadImHexPatternsFiles dest) ) message(STATUS "Downloading ImHex-Patterns repo branch ${PATTERNS_BRANCH}...") - FetchContent_Populate(imhex_patterns) + FetchContent_MakeAvailable(imhex_patterns) message(STATUS "Finished downloading ImHex-Patterns") else () diff --git a/lib/external/pattern_language b/lib/external/pattern_language index 48c36659e..73bd17254 160000 --- a/lib/external/pattern_language +++ b/lib/external/pattern_language @@ -1 +1 @@ -Subproject commit 48c36659e5c382ccf3e240a34e119fee0a0468cb +Subproject commit 73bd1725401abd12d494bb7211fa1e2ad1abfc80 diff --git a/plugins/builtin/source/ui/pattern_drawer.cpp b/plugins/builtin/source/ui/pattern_drawer.cpp index ab1d21b43..9993ce23a 100644 --- a/plugins/builtin/source/ui/pattern_drawer.cpp +++ b/plugins/builtin/source/ui/pattern_drawer.cpp @@ -591,13 +591,13 @@ namespace hex::plugin::builtin::ui { if (open) { u64 chunkCount = 0; for (u64 i = 0; i < iteratable.getEntryCount(); i += ChunkSize) { - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - chunkCount++; auto &displayEnd = this->getDisplayEnd(pattern); if (chunkCount > displayEnd) { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Selectable(hex::format("... ({})", "hex.builtin.pattern_drawer.double_click"_lang).c_str(), false, ImGuiSelectableFlags_SpanAllColumns); if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) displayEnd += DisplayEndStep; @@ -605,30 +605,37 @@ namespace hex::plugin::builtin::ui { } else { auto endIndex = std::min(iteratable.getEntryCount(), i + ChunkSize); - auto startOffset = iteratable.getEntry(i)->getOffset(); - auto endOffset = iteratable.getEntry(endIndex - 1)->getOffset(); - auto endSize = iteratable.getEntry(endIndex - 1)->getSize(); + bool chunkOpen = true; + if (iteratable.getEntryCount() > ChunkSize) { + auto startOffset = iteratable.getEntry(i)->getOffset(); + auto endOffset = iteratable.getEntry(endIndex - 1)->getOffset(); + auto endSize = iteratable.getEntry(endIndex - 1)->getSize(); - size_t chunkSize = (endOffset - startOffset) + endSize; + size_t chunkSize = (endOffset - startOffset) + endSize; - auto chunkOpen = highlightWhenSelected(startOffset, ((endOffset + endSize) - startOffset) - 1, [&]{ return ImGui::TreeNodeEx(hex::format("[{} ... {}]", i, endIndex - 1).c_str(), ImGuiTreeNodeFlags_SpanFullWidth); }); - ImGui::TableNextColumn(); - drawColorColumn(pattern); - ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", startOffset, startOffset + chunkSize - (pattern.getSize() == 0 ? 0 : 1)); - ImGui::TableNextColumn(); - ImGui::TextFormatted("0x{0:04X}", chunkSize); - ImGui::TableNextColumn(); - ImGui::TextFormattedColored(ImColor(0xFF9BC64D), "{0}", pattern.getTypeName()); - ImGui::SameLine(0, 0); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); - ImGui::TextUnformatted("["); - ImGui::SameLine(0, 0); - ImGui::TextFormattedColored(ImColor(0xFF00FF00), "{0}", endIndex - i); - ImGui::SameLine(0, 0); - ImGui::TextUnformatted("]"); + chunkOpen = highlightWhenSelected(startOffset, ((endOffset + endSize) - startOffset) - 1, [&]{ return ImGui::TreeNodeEx(hex::format("[{} ... {}]", i, endIndex - 1).c_str(), ImGuiTreeNodeFlags_SpanFullWidth); }); + ImGui::TableNextColumn(); + drawColorColumn(pattern); + ImGui::TextFormatted("0x{0:08X} : 0x{1:08X}", startOffset, startOffset + chunkSize - (pattern.getSize() == 0 ? 0 : 1)); + ImGui::TableNextColumn(); + ImGui::TextFormatted("0x{0:04X}", chunkSize); + ImGui::TableNextColumn(); + ImGui::TextFormattedColored(ImColor(0xFF9BC64D), "{0}", pattern.getTypeName()); + ImGui::SameLine(0, 0); + + ImGui::TextUnformatted("["); + ImGui::SameLine(0, 0); + ImGui::TextFormattedColored(ImColor(0xFF00FF00), "{0}", endIndex - i); + ImGui::SameLine(0, 0); + ImGui::TextUnformatted("]"); + + ImGui::TableNextColumn(); + ImGui::TextFormatted("[ ... ]"); + } - ImGui::TableNextColumn(); - ImGui::TextFormatted("[ ... ]"); if (chunkOpen) { iteratable.forEachEntry(i, endIndex, [&](u64, auto *entry){ @@ -637,7 +644,8 @@ namespace hex::plugin::builtin::ui { ImGui::PopID(); }); - ImGui::TreePop(); + if (iteratable.getEntryCount() > ChunkSize) + ImGui::TreePop(); } } }