From ca3b5b72cad6ba19ddb385a5ae750be73823594f Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 17 Jul 2022 13:12:28 +0200 Subject: [PATCH] ui: Fixed highlighting color and tooltips --- .../source/content/views/view_bookmarks.cpp | 8 ++-- .../content/views/view_pattern_editor.cpp | 38 +++++++++---------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/plugins/builtin/source/content/views/view_bookmarks.cpp b/plugins/builtin/source/content/views/view_bookmarks.cpp index 7e4d28ee0..ac0f1fd7a 100644 --- a/plugins/builtin/source/content/views/view_bookmarks.cpp +++ b/plugins/builtin/source/content/views/view_bookmarks.cpp @@ -61,11 +61,11 @@ namespace hex::plugin::builtin { ImGui::BeginTooltip(); - if (ImGui::BeginTable("##tooltips", 1, ImGuiTableFlags_NoHostExtendX | ImGuiTableFlags_RowBg | ImGuiTableFlags_NoClip)) { + ImGui::PushID(&bookmark); + if (ImGui::BeginTable("##tooltips", 1, ImGuiTableFlags_RowBg | ImGuiTableFlags_NoClip)) { ImGui::TableNextRow(); ImGui::TableNextColumn(); - ImGui::PushID(&bookmark); { ImGui::ColorButton("##color", ImColor(bookmark.color)); ImGui::SameLine(0, 10); @@ -73,7 +73,7 @@ namespace hex::plugin::builtin { if (ImGui::GetIO().KeyShift) { ImGui::Indent(); - if (ImGui::BeginTable("##extra_info", 2, ImGuiTableFlags_RowBg | ImGuiTableFlags_NoHostExtendX | ImGuiTableFlags_NoClip)) { + if (ImGui::BeginTable("##extra_info", 2, ImGuiTableFlags_RowBg | ImGuiTableFlags_NoClip)) { ImGui::TableNextRow(); ImGui::TableNextColumn(); @@ -98,13 +98,13 @@ namespace hex::plugin::builtin { } } - ImGui::PopID(); ImGui::PushStyleColor(ImGuiCol_TableRowBg, bookmark.color); ImGui::PushStyleColor(ImGuiCol_TableRowBgAlt, bookmark.color); ImGui::EndTable(); ImGui::PopStyleColor(2); } + ImGui::PopID(); ImGui::EndTooltip(); } diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 8c254c207..4a27c25d5 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -234,20 +234,15 @@ namespace hex::plugin::builtin { if (this->m_runningEvaluators != 0) return std::nullopt; - bool foundColor = false; - ImColor color = ImColor(0xFF, 0xFF, 0xFF, 0x70); + std::optional color; for (const auto &pattern : ImHexApi::Provider::get()->getPatternLanguageRuntime().getPatterns(address)) { - color = ImAlphaBlendColors(color, pattern->getColor()); - - foundColor = true; + if (color.has_value()) + color = ImAlphaBlendColors(*color, pattern->getColor()); + else + color = pattern->getColor(); } - if (!foundColor) - return std::nullopt; - else { - color.Value.w = 0x70; - return color; - } + return color; }); ImHexApi::HexEditor::addTooltipProvider([this](u64 address, const u8 *data, size_t size) { @@ -256,20 +251,21 @@ namespace hex::plugin::builtin { auto patterns = ImHexApi::Provider::get()->getPatternLanguageRuntime().getPatterns(address); if (!patterns.empty()) { ImGui::BeginTooltip(); - if (ImGui::BeginTable("##tooltips", 1, ImGuiTableFlags_NoHostExtendX | ImGuiTableFlags_RowBg | ImGuiTableFlags_NoClip)) { - for (const auto &pattern : patterns) { - auto tooltipColor = (pattern->getColor() & 0x00FF'FFFF) | 0x7000'0000; - ImGui::PushStyleColor(ImGuiCol_TableRowBg, tooltipColor); - ImGui::PushStyleColor(ImGuiCol_TableRowBgAlt, tooltipColor); - + for (const auto &pattern : patterns) { + auto tooltipColor = (pattern->getColor() & 0x00FF'FFFF) | 0x7000'0000; + ImGui::PushID(pattern); + if (ImGui::BeginTable("##tooltips", 1, ImGuiTableFlags_RowBg | ImGuiTableFlags_NoClip)) { ImGui::TableNextRow(); ImGui::TableNextColumn(); - ImGui::PopStyleColor(2); - this->drawPatternTooltip(pattern); + + ImGui::PushStyleColor(ImGuiCol_TableRowBg, tooltipColor); + ImGui::PushStyleColor(ImGuiCol_TableRowBgAlt, tooltipColor); + ImGui::EndTable(); + ImGui::PopStyleColor(2); } - ImGui::EndTable(); + ImGui::PopID(); } ImGui::EndTooltip(); } @@ -685,7 +681,7 @@ namespace hex::plugin::builtin { ImGui::TableNextColumn(); ImGui::TextFormatted("{}", pattern->getEndian() == std::endian::little ? "Little" : "Big"); - if (auto comment = pattern->getComment(); comment.has_value()) { + if (const auto &comment = pattern->getComment(); comment.has_value()) { ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::TextFormatted("Comment: ");