From c17a880830be97093155a7b65753fbe63ed51be3 Mon Sep 17 00:00:00 2001 From: scawful Date: Fri, 15 Nov 2024 23:46:44 -0500 Subject: [PATCH] Update KeyPressed reference in imgui_memory_editor --- src/lib/imgui_memory_editor.h | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/lib/imgui_memory_editor.h b/src/lib/imgui_memory_editor.h index 205e6be7..00946246 100644 --- a/src/lib/imgui_memory_editor.h +++ b/src/lib/imgui_memory_editor.h @@ -253,13 +253,23 @@ struct MemoryEditor size_t preview_data_type_size = OptShowDataPreview ? DataTypeGetSize(PreviewDataType) : 0; size_t data_editing_addr_next = (size_t)-1; - if (DataEditingAddr != (size_t)-1) - { - // Move cursor but only apply on next frame so scrolling with be synchronized (because currently we can't change the scrolling while the window is being rendered) - if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_UpArrow)) && (ptrdiff_t)DataEditingAddr >= (ptrdiff_t)Cols) { data_editing_addr_next = DataEditingAddr - Cols; } - else if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_DownArrow)) && (ptrdiff_t)DataEditingAddr < (ptrdiff_t)mem_size - Cols) { data_editing_addr_next = DataEditingAddr + Cols; } - else if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_LeftArrow)) && (ptrdiff_t)DataEditingAddr > (ptrdiff_t)0) { data_editing_addr_next = DataEditingAddr - 1; } - else if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_RightArrow)) && (ptrdiff_t)DataEditingAddr < (ptrdiff_t)mem_size - 1) { data_editing_addr_next = DataEditingAddr + 1; } + if (DataEditingAddr != (size_t)-1) { + // Move cursor but only apply on next frame so scrolling with be + // synchronized (because currently we can't change the scrolling while the + // window is being rendered) + if (ImGui::IsKeyPressed(ImGuiKey_UpArrow) && + (ptrdiff_t)DataEditingAddr >= (ptrdiff_t)Cols) { + data_editing_addr_next = DataEditingAddr - Cols; + } else if (ImGui::IsKeyPressed(ImGuiKey_DownArrow) && + (ptrdiff_t)DataEditingAddr < (ptrdiff_t)mem_size - Cols) { + data_editing_addr_next = DataEditingAddr + Cols; + } else if (ImGui::IsKeyPressed(ImGuiKey_LeftArrow) && + (ptrdiff_t)DataEditingAddr > (ptrdiff_t)0) { + data_editing_addr_next = DataEditingAddr - 1; + } else if (ImGui::IsKeyPressed(ImGuiKey_RightArrow) && + (ptrdiff_t)DataEditingAddr < (ptrdiff_t)mem_size - 1) { + data_editing_addr_next = DataEditingAddr + 1; + } } // Draw vertical separator