mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 21:47:40 -05:00
feat: Added hex editor segment separators
This commit is contained in:
@@ -300,6 +300,7 @@ namespace hex::ui {
|
||||
std::reverse(buffer.begin(), buffer.begin() + size);
|
||||
|
||||
m_currDataVisualizer->draw(address, buffer.data(), size, m_upperCaseHex);
|
||||
|
||||
} else {
|
||||
asciiVisualizer.draw(address, data, size, m_upperCaseHex);
|
||||
}
|
||||
@@ -408,6 +409,26 @@ namespace hex::ui {
|
||||
}
|
||||
}
|
||||
|
||||
void HexEditor::drawSeparatorLine(u64 address, bool drawVerticalConnector) {
|
||||
if (m_separatorStride == 0) return;
|
||||
|
||||
const u64 regionProgress = address % m_separatorStride;
|
||||
const u64 cellsPerRow = m_bytesPerRow / m_currDataVisualizer->getBytesPerCell();
|
||||
const auto table = ImGui::GetCurrentTable();
|
||||
if (regionProgress < cellsPerRow) {
|
||||
const auto rect = ImGui::TableGetCellBgRect(table, table->CurrentColumn);
|
||||
|
||||
const auto drawList = ImGui::GetWindowDrawList();
|
||||
|
||||
const auto lineColor = ImGui::GetColorU32(ImGuiCol_SeparatorActive);
|
||||
drawList->AddLine(rect.Min, ImVec2(rect.Max.x, rect.Min.y), lineColor);
|
||||
if (regionProgress == 0 && drawVerticalConnector) {
|
||||
drawList->AddLine(ImFloor(rect.Min), ImFloor(ImVec2(rect.Min.x, rect.Max.y)), lineColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HexEditor::drawSelectionFrame(u32 x, u32 y, Region selection, u64 byteAddress, u16 bytesPerCell, const ImVec2 &cellPos, const ImVec2 &cellSize, const ImColor &backgroundColor) const {
|
||||
auto drawList = ImGui::GetWindowDrawList();
|
||||
|
||||
@@ -565,7 +586,14 @@ namespace hex::ui {
|
||||
// Draw address column
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGuiExt::TextFormatted(m_upperCaseHex ? "{:08X}: " : "{:08x}: ", y * m_bytesPerRow + m_provider->getBaseAddress() + m_provider->getCurrentPageAddress());
|
||||
|
||||
const auto rowAddress = y * m_bytesPerRow + m_provider->getBaseAddress() + m_provider->getCurrentPageAddress();
|
||||
|
||||
if (m_separatorStride > 0 && rowAddress % m_separatorStride < m_bytesPerRow)
|
||||
ImGuiExt::TextFormattedColored(ImGui::GetStyleColorVec4(ImGuiCol_SeparatorActive), "{} {}", "hex.ui.common.segment"_lang, rowAddress / m_separatorStride);
|
||||
else
|
||||
ImGuiExt::TextFormatted(m_upperCaseHex ? "{:08X}: " : "{:08x}: ", rowAddress);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
const u8 validBytes = std::min<u64>(m_bytesPerRow, m_provider->getSize() - y * m_bytesPerRow);
|
||||
@@ -616,8 +644,11 @@ namespace hex::ui {
|
||||
const u64 byteAddress = y * m_bytesPerRow + x * bytesPerCell + m_provider->getBaseAddress() + m_provider->getCurrentPageAddress();
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
if (isColumnSeparatorColumn(x, columnCount))
|
||||
if (y != 0) drawSeparatorLine(byteAddress, x != 0);
|
||||
if (isColumnSeparatorColumn(x, columnCount)) {
|
||||
ImGui::TableNextColumn();
|
||||
if (y != 0) drawSeparatorLine(byteAddress, false);
|
||||
}
|
||||
|
||||
if (x < std::ceil(float(validBytes) / bytesPerCell)) {
|
||||
auto cellStartPos = getCellPosition();
|
||||
@@ -679,6 +710,7 @@ namespace hex::ui {
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
if (y != 0) drawSeparatorLine(y * m_bytesPerRow + m_provider->getBaseAddress() + m_provider->getCurrentPageAddress(), false);
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
// Draw ASCII column
|
||||
@@ -691,10 +723,11 @@ namespace hex::ui {
|
||||
ImGui::TableNextRow();
|
||||
|
||||
for (u64 x = 0; x < m_bytesPerRow; x++) {
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
const u64 byteAddress = y * m_bytesPerRow + x + m_provider->getBaseAddress() + m_provider->getCurrentPageAddress();
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
if (y != 0) drawSeparatorLine(byteAddress, true);
|
||||
|
||||
const auto cellStartPos = getCellPosition();
|
||||
const auto cellSize = CharacterSize + scaled(ImVec2(m_characterCellPadding, 0));
|
||||
|
||||
@@ -1029,6 +1062,11 @@ namespace hex::ui {
|
||||
m_bytesPerRow = bytesPerRow * this->getBytesPerCell();
|
||||
m_encodingLineStartAddresses.clear();
|
||||
}
|
||||
{
|
||||
const auto min = 0;
|
||||
const auto max = m_provider->getActualSize();
|
||||
ImGui::SliderScalar("##separator_stride", ImGuiDataType_U64, &m_separatorStride, &min, &max, m_separatorStride == 0 ? "hex.ui.hex_editor.no_separator"_lang : hex::format("hex.ui.hex_editor.separator_stride"_lang, m_separatorStride).c_str());
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user