From 2c2d3b2de387234c0b7544f2b9acd9316f3f9645 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 29 Nov 2024 20:23:36 +0100 Subject: [PATCH] feat: Display visualizers in pattern tooltips --- .../content/views/view_pattern_editor.hpp | 3 +++ .../content/views/view_pattern_editor.cpp | 20 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/plugins/builtin/include/content/views/view_pattern_editor.hpp b/plugins/builtin/include/content/views/view_pattern_editor.hpp index 11564352e..074ce86ca 100644 --- a/plugins/builtin/include/content/views/view_pattern_editor.hpp +++ b/plugins/builtin/include/content/views/view_pattern_editor.hpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -243,6 +244,8 @@ namespace hex::plugin::builtin { std::map> m_sectionWindowDrawer; ui::HexEditor m_sectionHexEditor; + PerProvider m_visualizerDrawer; + bool m_tooltipJustOpened = false; PatternSourceCode m_sourceCode; PerProvider> m_console; diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index c785715d3..c66752a31 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -1559,7 +1559,16 @@ namespace hex::plugin::builtin { ImGui::SameLine(); ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical); ImGui::SameLine(); - ImGuiExt::TextFormatted("{: <{}} ", hex::limitStringLength(pattern->getFormattedValue(), 64), shiftHeld ? 40 : 0); + + if (const auto &inlineVisualizeArgs = pattern->getAttributeArguments("hex::inline_visualize"); !inlineVisualizeArgs.empty()) { + auto x = ImGui::GetCursorPosX(); + ImGui::Dummy(ImVec2(125_scaled, ImGui::GetTextLineHeight())); + ImGui::SameLine(); + ImGui::SetCursorPos(ImVec2(x, ImGui::GetCursorPosY() + ImGui::GetStyle().FramePadding.y)); + m_visualizerDrawer->drawVisualizer(ContentRegistry::PatternLanguage::impl::getInlineVisualizers(), inlineVisualizeArgs, *pattern, true); + } else { + ImGuiExt::TextFormatted("{: <{}} ", hex::limitStringLength(pattern->getFormattedValue(), 64), shiftHeld ? 40 : 0); + } if (shiftHeld) { ImGui::Indent(); @@ -1661,7 +1670,16 @@ namespace hex::plugin::builtin { ImGui::EndTable(); } + + if (const auto &visualizeArgs = pattern->getAttributeArguments("hex::visualize"); !visualizeArgs.empty()) { + m_visualizerDrawer->drawVisualizer(ContentRegistry::PatternLanguage::impl::getVisualizers(), visualizeArgs, *pattern, m_tooltipJustOpened); + } + ImGui::Unindent(); + + m_tooltipJustOpened = false; + } else { + m_tooltipJustOpened = true; } }