Added hover tooltip for bookmarks in hex editor

This commit is contained in:
WerWolv 2021-01-13 16:45:31 +01:00
parent 4328a335ec
commit c1ad816211
3 changed files with 38 additions and 6 deletions

View File

@ -89,6 +89,7 @@ struct MemoryEditor
ImU8 (*ReadFn)(const ImU8* data, size_t off); // = 0 // optional handler to read bytes.
void (*WriteFn)(ImU8* data, size_t off, ImU8 d); // = 0 // optional handler to write bytes.
bool (*HighlightFn)(const ImU8* data, size_t off, bool next);//= 0 // optional handler to return Highlight property (to support non-contiguous highlighting).
void (*HoverFn)(const ImU8 *data, size_t off);
// [Internal State]
bool ContentsWidthChanged;
@ -121,6 +122,7 @@ struct MemoryEditor
ReadFn = NULL;
WriteFn = NULL;
HighlightFn = NULL;
HoverFn = NULL;
// State/Internals
ContentsWidthChanged = false;
@ -324,6 +326,7 @@ struct MemoryEditor
const char* format_byte = OptUpperCaseHex ? "%02X" : "%02x";
const char* format_byte_space = OptUpperCaseHex ? "%02X " : "%02x ";
bool tooltipShown = false;
for (int line_i = clipper.DisplayStart; line_i < clipper.DisplayEnd; line_i++) // display only visible lines
{
size_t addr = (size_t)(line_i * Cols);
@ -458,6 +461,12 @@ struct MemoryEditor
if (ImGui::IsItemHovered() && ((ImGui::IsMouseClicked(0) && ImGui::GetIO().KeyShift) || ImGui::IsMouseDragging(0))) {
DataPreviewAddrEnd = addr;
}
if (ImGui::IsItemHovered() && !tooltipShown) {
if (HoverFn) {
HoverFn(mem_data, addr);
tooltipShown = true;
}
}
}
}

View File

@ -84,35 +84,37 @@ namespace hex {
ImGui::TextColored(ImColor(0xFF9BC64D), bytesString.c_str());
}
ImGui::PushID(id);
if (ImGui::Button("Jump to"))
View::postEvent(Events::SelectionChangeRequest, &region);
ImGui::PopID();
ImGui::SameLine(0, 15);
ImGui::PushID(id + 1);
if (ImGui::Button("Remove"))
bookmarkToRemove = iter;
ImGui::PopID();
ImGui::NewLine();
ImGui::TextUnformatted("Name");
ImGui::Separator();
ImGui::PushID(id);
ImGui::PushID(id + 2);
ImGui::InputText("##nolabel", name.data(), 64);
ImGui::PopID();
ImGui::SameLine();
ImGui::PushID(id + 1);
ImGui::PushID(id + 3);
ImGui::ColorEdit4("Color", (float*)&headerColor.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_NoAlpha);
color = headerColor;
ImGui::PopID();
ImGui::NewLine();
ImGui::TextUnformatted("Comment");
ImGui::Separator();
ImGui::PushID(id + 2);
ImGui::PushID(id + 4);
ImGui::InputTextMultiline("##nolabel", comment.data(), 0xF'FFFF);
ImGui::PopID();
ImGui::NewLine();
id += 3;
id += 5;
}
ImGui::PopStyleColor(3);
}

View File

@ -69,6 +69,27 @@ namespace hex {
return false;
};
this->m_memoryEditor.HoverFn = [](const ImU8 *data, size_t addr) {
ViewHexEditor *_this = (ViewHexEditor *) data;
bool tooltipShown = false;
for (const auto &[region, name, comment, color] : _this->m_bookmarks) {
if (addr >= region.address && addr < (region.address + region.size)) {
if (!tooltipShown) {
ImGui::BeginTooltip();
tooltipShown = true;
}
ImGui::ColorButton(name.data(), ImColor(color).Value);
ImGui::SameLine(0, 10);
ImGui::TextUnformatted(name.data());
}
}
if (tooltipShown)
ImGui::EndTooltip();
};
View::subscribeEvent(Events::FileDropped, [this](const void *userData) {
auto filePath = static_cast<const char*>(userData);