From 2b135cf7e043f3a59901342eaece1a4c6d166b52 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 7 Oct 2022 16:27:29 +0200 Subject: [PATCH] ui: Limit maximum length of data displayed in pattern tooltip --- lib/libimhex/include/hex/helpers/utils.hpp | 7 +++++++ .../builtin/source/content/views/view_pattern_editor.cpp | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/libimhex/include/hex/helpers/utils.hpp b/lib/libimhex/include/hex/helpers/utils.hpp index 4cbcaf782..5dec8b663 100644 --- a/lib/libimhex/include/hex/helpers/utils.hpp +++ b/lib/libimhex/include/hex/helpers/utils.hpp @@ -304,6 +304,13 @@ namespace hex { std::optional getEnvironmentVariable(const std::string &env); + inline std::string limitStringLength(const std::string &string, size_t maxLength) { + if (string.length() <= maxLength) + return string; + + return string.substr(0, maxLength - 3) + "..."; + } + namespace scope_guard { #define SCOPE_GUARD ::hex::scope_guard::ScopeGuardOnExit() + [&]() diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index de3537a7b..8fdac80a2 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -276,6 +276,7 @@ namespace hex::plugin::builtin { auto patterns = ProviderExtraData::getCurrent().patternLanguage.runtime->getPatternsAtAddress(address); if (!patterns.empty() && !std::all_of(patterns.begin(), patterns.end(), [](const auto &pattern) { return pattern->isHidden(); })) { ImGui::BeginTooltip(); + for (const auto &pattern : patterns) { if (pattern->isHidden()) continue; @@ -294,7 +295,6 @@ namespace hex::plugin::builtin { ImGui::PopStyleColor(2); } ImGui::PopID(); - } ImGui::EndTooltip(); } @@ -716,7 +716,7 @@ namespace hex::plugin::builtin { ImGui::SameLine(); ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical); ImGui::SameLine(); - ImGui::TextFormatted("{} ", pattern->getFormattedValue()); + ImGui::TextFormatted("{} ", hex::limitStringLength(pattern->getFormattedValue(), 64)); if (ImGui::GetIO().KeyShift) { ImGui::Indent();