diff --git a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp index 336ba7170..4e1bffe1c 100644 --- a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp +++ b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp @@ -505,13 +505,23 @@ namespace ImGui { const ImVec2 frame_size = CalcItemSize(ImVec2(0, 0), CalcTextSize(prefix).x, label_size.y + style.FramePadding.y * 2.0f); const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size); - ImGui::SameLine(0, frame_size.x); - bool result = ImGui::InputScalar(label, ImGuiDataType_U64, value, nullptr, nullptr, "%llX", flags); + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + frame_size.x); + + char buf[64]; + DataTypeFormatString(buf, IM_ARRAYSIZE(buf), ImGuiDataType_U64, value, "%llX"); + + bool value_changed = false; + if (InputTextEx(label, nullptr, buf, IM_ARRAYSIZE(buf), ImVec2(CalcItemWidth() - frame_size.x, label_size.y + style.FramePadding.y * 2.0f), flags)) + value_changed = DataTypeApplyOpFromText(buf, GImGui->InputTextState.InitialTextA.Data, ImGuiDataType_U64, value, "%llX"); + + if (value_changed) + MarkItemEdited(GImGui->LastItemData.ID); + RenderNavHighlight(frame_bb, id); RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding); RenderText(ImVec2(frame_bb.Min.x + style.FramePadding.x, frame_bb.Min.y + style.FramePadding.y), prefix); - return result; + return value_changed; } bool InputHexadecimal(const char *label, ImU64 *value, ImGuiInputTextFlags flags) { diff --git a/plugins/builtin/include/content/views/view_hex_editor.hpp b/plugins/builtin/include/content/views/view_hex_editor.hpp index 601b79333..10ee34be0 100644 --- a/plugins/builtin/include/content/views/view_hex_editor.hpp +++ b/plugins/builtin/include/content/views/view_hex_editor.hpp @@ -50,7 +50,8 @@ namespace hex::plugin::builtin { std::vector> m_lastStringSearch; std::vector> m_lastHexSearch; - i64 m_gotoAddress = 0; + u64 m_gotoAddressAbsolute = 0; + i64 m_gotoAddressRelative = 0; char m_baseAddressBuffer[0x20] = { 0 }; u64 m_resizeSize = 0; diff --git a/plugins/builtin/source/content/data_processor_nodes.cpp b/plugins/builtin/source/content/data_processor_nodes.cpp index 941d6b282..763d10172 100644 --- a/plugins/builtin/source/content/data_processor_nodes.cpp +++ b/plugins/builtin/source/content/data_processor_nodes.cpp @@ -104,7 +104,7 @@ namespace hex::plugin::builtin { void drawNode() override { ImGui::PushItemWidth(100); - ImGui::InputScalar("hex", ImGuiDataType_U64, &this->m_value, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal); + ImGui::InputHexadecimal("##integer_value", &this->m_value); ImGui::PopItemWidth(); } diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index 8461c5803..325f68ce3 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -660,6 +660,9 @@ namespace hex::plugin::builtin { ImGui::EndTabBar(); } + if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape))) + ImGui::CloseCurrentPopup(); + ImGui::EndPopup(); } } @@ -677,49 +680,49 @@ namespace hex::plugin::builtin { u64 newOffset = 0; if (ImGui::BeginTabItem("hex.builtin.view.hex_editor.goto.offset.absolute"_lang)) { ImGui::SetKeyboardFocusHere(); - runGoto = ImGui::InputScalar("hex", ImGuiDataType_U64, &this->m_gotoAddress, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_EnterReturnsTrue); + runGoto = ImGui::InputHexadecimal("##goto", &this->m_gotoAddressAbsolute, ImGuiInputTextFlags_EnterReturnsTrue); - if (this->m_gotoAddress < baseAddress || this->m_gotoAddress > baseAddress + dataSize) - this->m_gotoAddress = baseAddress; + if (this->m_gotoAddressAbsolute < baseAddress || this->m_gotoAddressAbsolute > baseAddress + dataSize) + this->m_gotoAddressAbsolute = baseAddress; - newOffset = this->m_gotoAddress; + newOffset = this->m_gotoAddressAbsolute; ImGui::EndTabItem(); } if (ImGui::BeginTabItem("hex.builtin.view.hex_editor.goto.offset.begin"_lang)) { ImGui::SetKeyboardFocusHere(); - runGoto = ImGui::InputScalar("hex", ImGuiDataType_U64, &this->m_gotoAddress, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_EnterReturnsTrue); + runGoto = ImGui::InputScalar("##goto", ImGuiDataType_U64, &this->m_gotoAddressAbsolute, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_EnterReturnsTrue); - if (this->m_gotoAddress < 0 || this->m_gotoAddress > dataSize) - this->m_gotoAddress = 0; + if (this->m_gotoAddressAbsolute < 0 || this->m_gotoAddressAbsolute > dataSize) + this->m_gotoAddressAbsolute = 0; - newOffset = this->m_gotoAddress + baseAddress; + newOffset = this->m_gotoAddressAbsolute + baseAddress; ImGui::EndTabItem(); } if (ImGui::BeginTabItem("hex.builtin.view.hex_editor.goto.offset.current"_lang)) { ImGui::SetKeyboardFocusHere(); - runGoto = ImGui::InputScalar("dec", ImGuiDataType_S64, &this->m_gotoAddress, nullptr, nullptr, "%lld", ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_EnterReturnsTrue); + runGoto = ImGui::InputScalar("##goto", ImGuiDataType_S64, &this->m_gotoAddressRelative, nullptr, nullptr, "%lld", ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_EnterReturnsTrue); i64 currSelectionOffset = std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd); - if (currSelectionOffset + this->m_gotoAddress < 0) - this->m_gotoAddress = -currSelectionOffset; - else if (currSelectionOffset + this->m_gotoAddress > dataSize) - this->m_gotoAddress = dataSize - currSelectionOffset; + if (currSelectionOffset + this->m_gotoAddressRelative < 0) + this->m_gotoAddressRelative = -currSelectionOffset; + else if (currSelectionOffset + this->m_gotoAddressRelative > dataSize) + this->m_gotoAddressRelative = dataSize - currSelectionOffset; - newOffset = currSelectionOffset + this->m_gotoAddress + baseAddress; + newOffset = currSelectionOffset + this->m_gotoAddressRelative + baseAddress; ImGui::EndTabItem(); } if (ImGui::BeginTabItem("hex.builtin.view.hex_editor.goto.offset.end"_lang)) { ImGui::SetKeyboardFocusHere(); - runGoto = ImGui::InputScalar("hex", ImGuiDataType_U64, &this->m_gotoAddress, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_EnterReturnsTrue); + runGoto = ImGui::InputHexadecimal("##goto", &this->m_gotoAddressAbsolute, ImGuiInputTextFlags_EnterReturnsTrue); - if (this->m_gotoAddress < 0 || this->m_gotoAddress > dataSize) - this->m_gotoAddress = 0; + if (this->m_gotoAddressAbsolute < 0 || this->m_gotoAddressAbsolute > dataSize) + this->m_gotoAddressAbsolute = 0; - newOffset = (baseAddress + dataSize) - this->m_gotoAddress - 1; + newOffset = (baseAddress + dataSize) - this->m_gotoAddressAbsolute - 1; ImGui::EndTabItem(); } @@ -732,6 +735,9 @@ namespace hex::plugin::builtin { ImGui::EndTabBar(); } + if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape))) + ImGui::CloseCurrentPopup(); + ImGui::EndPopup(); } } diff --git a/plugins/builtin/source/content/views/view_tools.cpp b/plugins/builtin/source/content/views/view_tools.cpp index 8723d2a5f..ebfb1007e 100644 --- a/plugins/builtin/source/content/views/view_tools.cpp +++ b/plugins/builtin/source/content/views/view_tools.cpp @@ -2,8 +2,6 @@ #include -#include - namespace hex::plugin::builtin { ViewTools::ViewTools() : View("hex.builtin.view.tools.name") { }