diff --git a/lib/libimhex/source/helpers/encoding_file.cpp b/lib/libimhex/source/helpers/encoding_file.cpp index 410908e7c..911d63a8e 100644 --- a/lib/libimhex/source/helpers/encoding_file.cpp +++ b/lib/libimhex/source/helpers/encoding_file.cpp @@ -38,8 +38,6 @@ namespace hex { { auto delimiterPos = line.find('='); - if (delimiterPos == std::string::npos) - continue; if (delimiterPos >= line.length()) continue; @@ -47,12 +45,16 @@ namespace hex { to = line.substr(delimiterPos + 1); if (from.empty()) continue; - if (to.empty()) to = " "; } auto fromBytes = hex::parseByteString(from); if (fromBytes.empty()) continue; + if (to.length() > 1) + hex::trim(to); + if (to.empty()) + to = " "; + if (!this->m_mapping.contains(fromBytes.size())) this->m_mapping.insert({ fromBytes.size(), {} }); this->m_mapping[fromBytes.size()].insert({ fromBytes, to }); diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index feacc2a98..3ffb0c87f 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "math_evaluator.hpp" @@ -434,15 +435,15 @@ namespace hex::plugin::builtin { const auto [decoded, advance] = encodingFile.getEncodingFor(buffer); const ImColor color = [&decoded = decoded, &advance = advance]{ if (decoded.length() == 1 && std::isalnum(decoded[0])) - return 0xFFFF8000; + return ImGui::GetCustomColorU32(ImGuiCustomCol_ToolbarBlue); else if (decoded.length() == 1 && advance == 1) - return 0xFF0000FF; + return ImGui::GetCustomColorU32(ImGuiCustomCol_ToolbarRed); else if (decoded.length() > 1 && advance == 1) - return 0xFF00FFFF; + return ImGui::GetCustomColorU32(ImGuiCustomCol_ToolbarYellow); else if (advance > 1) - return 0xFFFFFFFF; + return ImGui::GetColorU32(ImGuiCol_Text); else - return 0xFFFF8000; + return ImGui::GetCustomColorU32(ImGuiCustomCol_ToolbarBlue); }(); return { std::string(decoded), advance, color }; @@ -830,16 +831,18 @@ namespace hex::plugin::builtin { } while (offset < this->m_bytesPerRow); ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(0, 0)); - if (ImGui::BeginTable("##encoding_cell", encodingData.size(), ImGuiTableFlags_SizingFixedFit)) { + ImGui::PushID(y); + if (ImGui::BeginTable("##encoding_cell", encodingData.size(), ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoKeepColumnsVisible)) { ImGui::TableNextRow(); for (const auto &[address, data] : encodingData) { ImGui::TableNextColumn(); const auto cellStartPos = getCellPosition(); - const auto cellSize = CharacterSize * data.advance; + const auto cellSize = CharacterSize * ImVec2(std::max(1, data.displayValue.length()), 1); const bool cellHovered = ImGui::IsMouseHoveringRect(cellStartPos, cellStartPos + cellSize, true); + const auto x = address % this->m_bytesPerRow; if (x < validBytes) { auto [foregroundColor, backgroundColor] = cellColors[x]; @@ -854,7 +857,9 @@ namespace hex::plugin::builtin { this->drawSelectionFrame(x, y, address, 1, cellStartPos, cellSize); } + ImGui::PushItemWidth(cellSize.x); ImGui::TextFormattedColored(data.color, "{}", data.displayValue); + ImGui::PopItemWidth(); this->handleSelection(address, data.advance, &bytes[address % this->m_bytesPerRow], cellHovered); } @@ -863,6 +868,7 @@ namespace hex::plugin::builtin { ImGui::EndTable(); } ImGui::PopStyleVar(); + ImGui::PopID(); }