From fdaad55cc667e4f071693edb209ebce88d86b092 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 9 Jun 2022 15:10:33 +0200 Subject: [PATCH] ui: Fix misaligned selection highlighting in very big files --- .../builtin/source/content/views/view_hex_editor.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index a6918d855..86309f8c2 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -421,6 +421,10 @@ namespace hex::plugin::builtin { return { std::string(decoded), advance, color }; } + static auto getCellPosition() { + return ImGui::GetCursorScreenPos() - ImGui::GetStyle().CellPadding; + } + static void drawTooltip(u64 address, const u8 *data, size_t size) { ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, scaled(ImVec2(5, 5))); @@ -683,7 +687,7 @@ namespace hex::plugin::builtin { ImGui::TableNextColumn(); if (x < validBytes) { - auto cellStartPos = (ImGui::GetWindowPos() + ImGui::GetCursorPos()) - ImGui::GetStyle().CellPadding - ImVec2(ImGui::GetScrollX(), ImGui::GetScrollY()); + auto cellStartPos = getCellPosition(); auto cellSize = (CharacterSize * ImVec2(this->m_currDataVisualizer->getMaxCharsPerCell(), 1) + (ImVec2(3, 2) * ImGui::GetStyle().CellPadding) - ImVec2(1, 0) * ImGui::GetStyle().CellPadding) + ImVec2(1, 0); auto [foregroundColor, backgroundColor] = cellColors[x]; @@ -740,7 +744,7 @@ namespace hex::plugin::builtin { const u64 byteAddress = y * this->m_bytesPerRow + x + provider->getBaseAddress() + provider->getCurrentPageAddress(); - const auto cellStartPos = (ImGui::GetWindowPos() + ImGui::GetCursorPos()) - ImGui::GetStyle().CellPadding - ImVec2(ImGui::GetScrollX(), ImGui::GetScrollY()); + const auto cellStartPos = getCellPosition(); const auto cellSize = CharacterSize; const bool cellHovered = ImGui::IsMouseHoveringRect(cellStartPos, cellStartPos + cellSize, false); @@ -795,7 +799,7 @@ namespace hex::plugin::builtin { for (const auto &[address, data] : encodingData) { ImGui::TableNextColumn(); - const auto cellStartPos = (ImGui::GetWindowPos() + ImGui::GetCursorPos()) - ImGui::GetStyle().CellPadding - ImVec2(ImGui::GetScrollX(), ImGui::GetScrollY()); + const auto cellStartPos = getCellPosition(); const auto cellSize = CharacterSize * data.advance; const bool cellHovered = ImGui::IsMouseHoveringRect(cellStartPos, cellStartPos + cellSize, false);