1
0
mirror of synced 2024-11-13 18:50:53 +01:00

sys: Properly center hex view around selection when jumping

This commit is contained in:
WerWolv 2022-10-09 14:47:38 +02:00
parent aa42fb5076
commit 3a9c3f939e
2 changed files with 14 additions and 5 deletions

View File

@ -68,8 +68,11 @@ namespace hex::plugin::builtin {
return data.selectionStart.has_value() && data.selectionEnd.has_value();
}
void jumpToSelection() {
void jumpToSelection(bool center = true) {
this->m_shouldJumpToSelection = true;
if (center)
this->m_centerOnJump = true;
}
void scrollToSelection() {
@ -118,6 +121,7 @@ namespace hex::plugin::builtin {
ContentRegistry::HexEditor::DataVisualizer *m_currDataVisualizer;
bool m_shouldJumpToSelection = false;
bool m_centerOnJump = false;
bool m_shouldScrollToSelection = false;
bool m_shouldJumpWhenOffScreen = false;
bool m_shouldUpdateScrollPosition = false;

View File

@ -1043,9 +1043,9 @@ namespace hex::plugin::builtin {
newSelection.address -= pageAddress;
if ((newSelection.getStartAddress()) < u64(clipper.DisplayStart * this->m_bytesPerRow))
this->jumpToSelection();
this->jumpToSelection(false);
if ((newSelection.getEndAddress()) > u64(clipper.DisplayEnd * this->m_bytesPerRow))
this->jumpToSelection();
this->jumpToSelection(false);
}
}
@ -1062,8 +1062,13 @@ namespace hex::plugin::builtin {
const auto pageAddress = provider->getCurrentPageAddress() + provider->getBaseAddress();
auto scrollPos = (static_cast<long double>(newSelection.getStartAddress() - pageAddress) / this->m_bytesPerRow) * CharacterSize.y;
bool scrollUpwards = scrollPos < ImGui::GetScrollY();
const auto scrollFraction = scrollUpwards ? 0.0F : (1.0F - ((1.0F / this->m_visibleRowCount) * 2));
auto scrollFraction = scrollUpwards ? 0.0F : (1.0F - ((1.0F / this->m_visibleRowCount) * 2));
if (this->m_centerOnJump) {
scrollFraction = 0.5F;
this->m_centerOnJump = false;
}
ImGui::SetScrollFromPosY(ImGui::GetCursorStartPos().y + scrollPos, scrollFraction);
}