fix: Rendering of insert cursor in hex editor

This commit is contained in:
WerWolv
2025-07-24 18:13:02 +02:00
parent 99a9752ee9
commit f6860015eb

View File

@@ -106,8 +106,6 @@ namespace hex::ui {
color = m_selectionColor;
}
}
} else {
color = 0x00;
}
if (color.has_value())
@@ -487,6 +485,9 @@ namespace hex::ui {
auto drawList = ImGui::GetWindowDrawList();
auto window = ImGui::GetCurrentWindowRead();
drawList->PushClipRect(window->Rect().Min, window->Rect().Max, false);
ON_SCOPE_EXIT {
drawList->PopClipRect();
};
if (!this->isSelectionValid()) return;
@@ -509,7 +510,6 @@ namespace hex::ui {
// Draw horizontal line at the bottom of the bytes
if ((byteAddress + bytesPerRow) > region.getEndAddress())
drawList->AddLine(ImTrunc(cellPos + ImVec2(0, cellSize.y)), ImTrunc(cellPos + cellSize), frameColor, 1_scaled);
drawList->PopClipRect();
}
void HexEditor::drawInsertCursor(Region region, u64 byteAddress, const ImVec2 &cellPos, const ImVec2 &cellSize, const ImColor &frameColor) const {
@@ -523,7 +523,12 @@ namespace hex::ui {
bool cursorVisible = (!ImGui::GetIO().ConfigInputTextCursorBlink) || (m_cursorBlinkTimer <= 0.0F) || std::fmod(m_cursorBlinkTimer, 1.20F) <= 0.80F;
if (cursorVisible && byteAddress == region.getStartAddress()) {
// Draw vertical line at the left of first byte and the start of the line
auto window = ImGui::GetCurrentWindowRead();
drawList->PushClipRect(window->Rect().Min, window->Rect().Max, false);
drawList->AddLine(ImTrunc(cellPos), ImTrunc(cellPos + ImVec2(0, cellSize.y)), frameColor, 1_scaled);
drawList->PopClipRect();
}
}
@@ -740,11 +745,11 @@ namespace hex::ui {
// Draw highlights and selection
if (backgroundColor.has_value()) {
this->drawBackgroundHighlight(cellStartPos, adjustedCellSize, backgroundColor.value());
// Draw frame around mouse selection
this->drawSelection(x, y, selection, byteAddress, bytesPerCell, cellStartPos, adjustedCellSize, ImGui::GetStyleColorVec4(ImGuiCol_Text));
}
// Draw frame around mouse selection
this->drawSelection(x, y, selection, byteAddress, bytesPerCell, cellStartPos, adjustedCellSize, ImGui::GetStyleColorVec4(ImGuiCol_Text));
const bool cellHovered = ImGui::IsMouseHoveringRect(cellStartPos, cellStartPos + adjustedCellSize, false) && ImGui::IsWindowHovered();
this->handleSelection(byteAddress, bytesPerCell, &bytes[x * bytesPerCell], cellHovered);
@@ -811,10 +816,10 @@ namespace hex::ui {
// Draw highlights and selection
if (backgroundColor.has_value()) {
this->drawBackgroundHighlight(cellStartPos, asciiCellSize, backgroundColor.value());
this->drawSelection(x, y, selection, byteAddress, 1, cellStartPos, asciiCellSize, ImGui::GetStyleColorVec4(ImGuiCol_Text));
}
this->drawSelection(x, y, selection, byteAddress, 1, cellStartPos, asciiCellSize, ImGui::GetStyleColorVec4(ImGuiCol_Text));
// Set cell foreground color
auto popForeground = SCOPE_GUARD { ImGui::PopStyleColor(); };
if (foregroundColor.has_value() && m_editingAddress != byteAddress)
@@ -913,10 +918,10 @@ namespace hex::ui {
// Draw highlights and selection
if (backgroundColor.has_value()) {
this->drawBackgroundHighlight(cellStartPos, cellSize, backgroundColor.value());
this->drawSelection(x, y, selection, address, 1, cellStartPos, cellSize, ImGui::GetStyleColorVec4(ImGuiCol_Text));
}
this->drawSelection(x, y, selection, address, 1, cellStartPos, cellSize, ImGui::GetStyleColorVec4(ImGuiCol_Text));
auto startPos = ImGui::GetCursorPos();
ImGuiExt::TextFormattedColored(data.color, "{}", data.displayValue);
ImGui::SetCursorPosX(startPos.x + cellSize.x);