From 395dd37d339459e8f87990063749fdbad9df41de Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 24 Aug 2025 22:13:01 +0200 Subject: [PATCH] fix: Pattern data section context menu not opening correctly --- .../content/views/view_pattern_data.cpp | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/plugins/builtin/source/content/views/view_pattern_data.cpp b/plugins/builtin/source/content/views/view_pattern_data.cpp index f3a60a862..8a6f42f55 100644 --- a/plugins/builtin/source/content/views/view_pattern_data.cpp +++ b/plugins/builtin/source/content/views/view_pattern_data.cpp @@ -118,6 +118,7 @@ namespace hex::plugin::builtin { } else { static i32 selectedSection = -1; for (auto &[id, drawer] : *m_patternDrawer) { + ImGui::PushID(id + 1); drawer->enablePatternEditing(ImHexApi::Provider::get()->isWritable()); // If the runtime has finished evaluating, draw the patterns @@ -126,31 +127,34 @@ namespace hex::plugin::builtin { if (id != 0 && !sections.contains(id)) continue; - if (ImGui::BeginTabItem(id == 0 ? "hex.builtin.view.pattern_data.section.main"_lang : sections.at(id).name.c_str())) { + const bool open = ImGui::BeginTabItem(id == 0 ? "hex.builtin.view.pattern_data.section.main"_lang : sections.at(id).name.c_str()); + const bool hovered = ImGui::IsItemHovered(); + if (open) { drawer->draw(runtime.getPatterns(id), &runtime, height); ImGui::EndTabItem(); } if (id != 0) { - if (ImGui::IsMouseDown(ImGuiMouseButton_Right) && ImGui::IsItemHovered() && !ImGui::IsMouseDragging(ImGuiMouseButton_Right)) { + if (ImGui::IsMouseDown(ImGuiMouseButton_Right) && hovered && !ImGui::IsMouseDragging(ImGuiMouseButton_Right)) { ImGui::OpenPopup("##PatternDataContextMenu"); selectedSection = id; } - } - } - } - if (ImGui::BeginPopup("##PatternDataContextMenu")) { - if (ImGui::MenuItemEx("hex.builtin.view.pattern_data.section.view_raw"_lang, ICON_VS_OPEN_PREVIEW)) { - if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) { - const auto §ions = runtime.getSections(); - if (auto it = sections.find(selectedSection); it != sections.end()) { - const auto &[id, section] = *it; - ImHexApi::Provider::add(section.data, section.name); + if (ImGui::BeginPopup("##PatternDataContextMenu")) { + if (ImGui::MenuItemEx("hex.builtin.view.pattern_data.section.view_raw"_lang, ICON_VS_OPEN_PREVIEW)) { + if (TRY_LOCK(ContentRegistry::PatternLanguage::getRuntimeLock())) { + if (auto it = sections.find(selectedSection); it != sections.end()) { + const auto &[sectionId, section] = *it; + ImHexApi::Provider::add(section.data, section.name); + } + } + } + ImGui::EndPopup(); } } } - ImGui::EndPopup(); + + ImGui::PopID(); } }