From ba6373daa4b824ac0da4b535872151d44995e3f8 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 29 Jan 2024 23:29:18 +0100 Subject: [PATCH] fix: Moving Hex Editor cursor downwards jumping entire page at once --- plugins/ui/include/ui/hex_editor.hpp | 8 +++----- plugins/ui/source/ui/hex_editor.cpp | 19 +++++++------------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/plugins/ui/include/ui/hex_editor.hpp b/plugins/ui/include/ui/hex_editor.hpp index 3cd59cad9..370e1eb95 100644 --- a/plugins/ui/include/ui/hex_editor.hpp +++ b/plugins/ui/include/ui/hex_editor.hpp @@ -181,11 +181,9 @@ namespace hex::ui { return m_selectionStart.has_value() && m_selectionEnd.has_value(); } - void jumpToSelection(bool center = true) { + void jumpToSelection(float pivot = 0.0F) { m_shouldJumpToSelection = true; - - if (center) - m_centerOnJump = true; + m_jumpPivot = pivot; } void scrollToSelection() { @@ -310,7 +308,7 @@ namespace hex::ui { char m_unknownDataCharacter = '?'; bool m_shouldJumpToSelection = false; - bool m_centerOnJump = false; + float m_jumpPivot = 0.0F; bool m_shouldScrollToSelection = false; bool m_shouldJumpWhenOffScreen = false; bool m_shouldUpdateScrollPosition = false; diff --git a/plugins/ui/source/ui/hex_editor.cpp b/plugins/ui/source/ui/hex_editor.cpp index fae52948f..48a4d577e 100644 --- a/plugins/ui/source/ui/hex_editor.cpp +++ b/plugins/ui/source/ui/hex_editor.cpp @@ -489,8 +489,8 @@ namespace hex::ui { } - m_visibleRowCount = ImGui::GetWindowSize().y / CharacterSize.y; - m_visibleRowCount = std::clamp(m_visibleRowCount, 1, numRows - m_scrollPosition); + m_visibleRowCount = size.y / CharacterSize.y; + m_visibleRowCount = std::max(m_visibleRowCount, 1); // Loop over rows for (ImS64 y = m_scrollPosition; y < (m_scrollPosition + m_visibleRowCount + 5) && y < numRows && numRows != 0; y++) { @@ -768,9 +768,9 @@ namespace hex::ui { newSelection.address -= pageAddress; if ((newSelection.getStartAddress()) < u64(m_scrollPosition * m_bytesPerRow)) - this->jumpToSelection(false); + this->jumpToSelection(0.0F); if ((newSelection.getEndAddress()) > u64((m_scrollPosition + m_visibleRowCount) * m_bytesPerRow)) - this->jumpToSelection(false); + this->jumpToSelection(1.0F); } } } @@ -784,15 +784,10 @@ namespace hex::ui { const auto pageAddress = m_provider->getCurrentPageAddress() + m_provider->getBaseAddress(); - if (m_centerOnJump) { - m_scrollPosition = (newSelection.getStartAddress() - pageAddress) / m_bytesPerRow; - m_scrollPosition -= (m_visibleRowCount / 2); - - } else { - m_scrollPosition = (newSelection.getStartAddress() - pageAddress) / m_bytesPerRow; - } - m_centerOnJump = false; + m_scrollPosition = (newSelection.getStartAddress() - pageAddress) / m_bytesPerRow; + m_scrollPosition -= m_visibleRowCount * m_jumpPivot; + m_jumpPivot = 0.0F; } }