Skip to content

Commit

Permalink
sys: Improve drag scrolling behaviour in hex editor view
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Oct 7, 2022
1 parent 2b135cf commit 8024b0a
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions plugins/builtin/source/content/views/view_hex_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,20 +1017,21 @@ namespace hex::plugin::builtin {
// Scroll to the cursor if it's either at the top or bottom edge of the screen
if (this->m_shouldScrollToSelection && this->isSelectionValid()) {
// Make sure simply clicking on a byte at the edge of the screen won't cause scrolling
if ((ImGui::IsMouseDown(ImGuiMouseButton_Left) && providerData.selectionStart != providerData.selectionEnd)) {
auto fractionPerLine = 1.0 / (this->m_visibleRowCount + 1);
if ((ImGui::IsMouseDown(ImGuiMouseButton_Left) && providerData.selectionStart != providerData.selectionEnd && providerData.selectionEnd.has_value())) {
auto scrollPerLine = ImGui::GetScrollMaxY() / (provider->getSize() / (long double)(this->m_bytesPerRow));

if (y == (u64(clipper.DisplayStart) + 3)) {
if (i128(*providerData.selectionEnd - provider->getBaseAddress() - provider->getCurrentPageAddress()) <= (i64(clipper.DisplayStart + 3) * this->m_bytesPerRow)) {
this->m_shouldScrollToSelection = false;
ImGui::SetScrollHereY(fractionPerLine * 5);
auto scrollPos = ImGui::GetScrollY();
auto scrollUpStartPos = scrollPos + scrollPerLine * 2;
auto scrollDownStartPos = scrollPos + ImGui::GetWindowHeight() - scrollPerLine * 4;

}
} else if (y == (u64(clipper.DisplayStart) - 3)) {
if (i128(*providerData.selectionEnd - provider->getBaseAddress() - provider->getCurrentPageAddress()) >= (i64(clipper.DisplayEnd - 3) * this->m_bytesPerRow)) {
this->m_shouldScrollToSelection = false;
ImGui::SetScrollHereY(fractionPerLine * (this->m_visibleRowCount - 1));
}
auto cursorPos = float(u64(*providerData.selectionEnd / this->m_bytesPerRow)) * CharacterSize.y;

if (cursorPos <= scrollUpStartPos && y == u64(clipper.DisplayStart)) {
this->m_shouldScrollToSelection = false;
ImGui::SetScrollHereY(0.1F);
} else if (cursorPos >= scrollDownStartPos && y == u64(clipper.DisplayEnd - 1)) {
this->m_shouldScrollToSelection = false;
ImGui::SetScrollHereY(0.95F);
}
}

Expand Down

0 comments on commit 8024b0a

Please sign in to comment.