diff --git a/plugins/builtin/source/content/data_visualizers.cpp b/plugins/builtin/source/content/data_visualizers.cpp index 1f490266f..43a8a2f0f 100644 --- a/plugins/builtin/source/content/data_visualizers.cpp +++ b/plugins/builtin/source/content/data_visualizers.cpp @@ -235,15 +235,15 @@ namespace hex::plugin::builtin { bool drawEditing(u64 address, u8 *data, size_t size, bool upperCase, bool startedEditing) override { hex::unused(address, data, size, upperCase); + m_currColor = { float(data[0]) / 0xFF, float(data[1]) / 0xFF, float(data[2]) / 0xFF, float(data[3]) / 0xFF }; if (startedEditing) { - m_currColor = { float(data[0]) / 0xFF, float(data[1]) / 0xFF, float(data[2]) / 0xFF, float(data[3]) / 0xFF }; ImGui::OpenPopup("##color_popup"); } ImGui::ColorButton("##color", ImColor(m_currColor[0], m_currColor[1], m_currColor[2], m_currColor[3]), ImGuiColorEditFlags_AlphaPreview | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_NoDragDrop, ImVec2(ImGui::GetColumnWidth(), ImGui::GetTextLineHeight())); if (ImGui::BeginPopup("##color_popup")) { - if (ImGui::ColorPicker4("##picker", m_currColor.data(), ImGuiColorEditFlags_AlphaBar)) { + if (ImGui::ColorPicker4("##picker", m_currColor.data(), ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_InputRGB)) { for (u8 i = 0; i < 4; i++) data[i] = m_currColor[i] * 0xFF; } diff --git a/plugins/builtin/source/ui/hex_editor.cpp b/plugins/builtin/source/ui/hex_editor.cpp index adeea9b81..dd1a11ea8 100644 --- a/plugins/builtin/source/ui/hex_editor.cpp +++ b/plugins/builtin/source/ui/hex_editor.cpp @@ -5,6 +5,7 @@ #include #include +#include namespace hex::plugin::builtin::ui { @@ -197,8 +198,10 @@ namespace hex::plugin::builtin::ui { } } else { - ImGui::SetKeyboardFocusHere(); - ImGui::SetNextFrameWantCaptureKeyboard(true); + if (m_enteredEditingMode) { + ImGui::SetKeyboardFocusHere(); + ImGui::SetNextFrameWantCaptureKeyboard(true); + } bool shouldExitEditingMode = true; if (cellType == m_editingCellType && cellType == CellType::Hex) { @@ -225,7 +228,7 @@ namespace hex::plugin::builtin::ui { size_t writtenBytes = 0; for (size_t i = 0; i < m_editingBytes.size(); i += 1) { if (m_editingBytes[i] != oldData[i]) { - m_provider->write(*m_editingAddress, &m_editingBytes[i], 1); + m_provider->write(*m_editingAddress + i, &m_editingBytes[i], 1); writtenBytes += 1; } } @@ -250,7 +253,7 @@ namespace hex::plugin::builtin::ui { m_shouldUpdateEditingValue = true; } - if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) && !hovered && !m_enteredEditingMode) { + if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) && !hovered && !m_enteredEditingMode && !ImGui::IsPopupOpen("", ImGuiPopupFlags_AnyPopup)) { m_editingAddress = std::nullopt; m_shouldModifyValue = false; } @@ -472,8 +475,12 @@ namespace hex::plugin::builtin::ui { this->handleSelection(byteAddress, bytesPerCell, &bytes[x * bytesPerCell], cellHovered); // Get byte foreground color - if (foregroundColor.has_value()) + + auto popForeground = SCOPE_GUARD { ImGui::PopStyleColor(); }; + if (foregroundColor.has_value() && !m_editingAddress.has_value()) ImGui::PushStyleColor(ImGuiCol_Text, *foregroundColor); + else + popForeground.release(); // Draw cell content ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0)); @@ -484,9 +491,6 @@ namespace hex::plugin::builtin::ui { ImGuiExt::TextFormatted("{}", std::string(maxCharsPerCell, '?')); ImGui::PopItemWidth(); ImGui::PopStyleVar(); - - if (foregroundColor.has_value()) - ImGui::PopStyleColor(); } } ImGui::PopStyleVar(); @@ -925,4 +929,4 @@ namespace hex::plugin::builtin::ui { m_selectionChanged = false; } -} \ No newline at end of file +}