1
0
mirror of synced 2025-02-21 12:29:47 +01:00

fix: Hex editor displaying invalid bytes when no data is available

This commit is contained in:
WerWolv 2023-12-23 23:04:40 +01:00
parent 8a428df7df
commit 61accd9569

View File

@ -319,14 +319,17 @@ namespace hex::ui {
const auto scrollbarWidth = ImGui::GetStyle().ScrollbarSize; const auto scrollbarWidth = ImGui::GetStyle().ScrollbarSize;
const ImRect bb = ImRect(ImMax(outerRect.Min.x, outerRect.Max.x - borderSize - scrollbarWidth), innerRect.Min.y, outerRect.Max.x, innerRect.Max.y); const ImRect bb = ImRect(ImMax(outerRect.Min.x, outerRect.Max.x - borderSize - scrollbarWidth), innerRect.Min.y, outerRect.Max.x, innerRect.Max.y);
const ImDrawFlags roundingCorners = ImDrawFlags_RoundCornersTopRight | ImDrawFlags_RoundCornersBottomRight; const ImDrawFlags roundingCorners = ImDrawFlags_RoundCornersTopRight | ImDrawFlags_RoundCornersBottomRight;
ImGui::ScrollbarEx(
bb, if (numRows > 0) {
ImGui::GetWindowScrollbarID(window, axis), ImGui::ScrollbarEx(
axis, bb,
&m_scrollPosition, ImGui::GetWindowScrollbarID(window, axis),
(std::ceil(innerRect.Max.y - innerRect.Min.y) / CharacterSize.y) - (m_visibleRowCount - 1), axis,
std::nextafterf(numRows, std::numeric_limits<float>::max()), &m_scrollPosition,
roundingCorners); (std::ceil(innerRect.Max.y - innerRect.Min.y) / CharacterSize.y) - (m_visibleRowCount - 1),
std::nextafterf(numRows, std::numeric_limits<float>::max()),
roundingCorners);
}
if (ImGui::IsWindowHovered()) { if (ImGui::IsWindowHovered()) {
m_scrollPosition += ImS64(ImGui::GetIO().MouseWheel * -5); m_scrollPosition += ImS64(ImGui::GetIO().MouseWheel * -5);
@ -395,16 +398,18 @@ namespace hex::ui {
}; };
ImS64 numRows = (m_provider->getSize() / m_bytesPerRow) + ((m_provider->getSize() % m_bytesPerRow) == 0 ? 0 : 1); ImS64 numRows = (m_provider->getSize() / m_bytesPerRow) + ((m_provider->getSize() % m_bytesPerRow) == 0 ? 0 : 1);
if (numRows == 0) { if (numRows == 0) {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGuiExt::TextFormatted(" "); ImGuiExt::TextFormatted(" ");
} }
m_visibleRowCount = ImGui::GetWindowSize().y / CharacterSize.y; m_visibleRowCount = ImGui::GetWindowSize().y / CharacterSize.y;
// Loop over rows // Loop over rows
for (ImS64 y = m_scrollPosition; y < (m_scrollPosition + m_visibleRowCount + 5) && y < numRows; y++) { for (ImS64 y = m_scrollPosition; y < (m_scrollPosition + m_visibleRowCount + 5) && y < numRows && numRows != 0; y++) {
// Draw address column // Draw address column
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();