Skip to content

Commit 4f52238

Browse files
committed
Add click-to-jump from heap viewer to memory editor
Clicking a block in the visual bar or a row in the block table fires a JumpToMemory event that opens the main memory editor at that location. For allocated blocks, the jump targets the user data (past the 8-byte header). For free blocks, it targets the block start. Signed-off-by: Nicolas 'Pixel' Noble <nicolas@nobis-crew.org>
1 parent 2258a53 commit 4f52238

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

src/gui/widgets/heap_viewer.cc

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "gui/widgets/heap_viewer.h"
2121

2222
#include "core/psxmem.h"
23+
#include "core/system.h"
2324
#include "fmt/format.h"
2425
#include "imgui.h"
2526

@@ -270,7 +271,7 @@ void PCSX::Widgets::HeapViewer::draw(Memory* memory, const char* title) {
270271
IM_COL32(200, 200, 200, 255));
271272
ImGui::Dummy(ImVec2(barWidth, barHeight));
272273

273-
// Tooltip on hover.
274+
// Tooltip on hover, jump to memory on click.
274275
if (ImGui::IsItemHovered()) {
275276
float mouseX = ImGui::GetMousePos().x - barPos.x;
276277
uint32_t hoverAddr = bottomPtr + (uint32_t)((float)heapSize * mouseX / barWidth);
@@ -279,9 +280,19 @@ void PCSX::Widgets::HeapViewer::draw(Memory* memory, const char* title) {
279280
ImGui::BeginTooltip();
280281
ImGui::Text("%s at %08x, %u bytes", b.free ? "Free" : "Allocated", b.address, b.size);
281282
if (!b.free && b.size > 8) {
282-
ImGui::Text("User payload: %u bytes", b.size - 8);
283+
ImGui::Text("User payload: %u bytes (click to jump)", b.size - 8);
284+
} else {
285+
ImGui::TextUnformatted("Click to jump");
283286
}
284287
ImGui::EndTooltip();
288+
if (ImGui::IsMouseClicked(0)) {
289+
// For allocated blocks, jump to user data (past the 8-byte header).
290+
// For free blocks, jump to the block start.
291+
uint32_t jumpAddr = b.free ? b.address : b.address + 8;
292+
uint32_t jumpSize = b.free ? b.size : (b.size > 8 ? b.size - 8 : b.size);
293+
g_system->m_eventBus->signal(
294+
Events::GUI::JumpToMemory{jumpAddr | 0x80000000, jumpSize});
295+
}
285296
break;
286297
}
287298
}
@@ -313,10 +324,20 @@ void PCSX::Widgets::HeapViewer::draw(Memory* memory, const char* title) {
313324
ImGui::TableSetupScrollFreeze(0, 1);
314325
ImGui::TableHeadersRow();
315326

316-
for (auto& b : blocks) {
327+
for (size_t i = 0; i < blocks.size(); i++) {
328+
auto& b = blocks[i];
317329
ImGui::TableNextRow();
318330
ImGui::TableNextColumn();
319-
ImGui::Text("%08x", b.address);
331+
332+
// Make the entire row clickable via a Selectable spanning all columns.
333+
char label[32];
334+
snprintf(label, sizeof(label), "%08x##block%zu", b.address, i);
335+
if (ImGui::Selectable(label, false,
336+
ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap)) {
337+
uint32_t jumpAddr = b.free ? b.address : b.address + 8;
338+
uint32_t jumpSize = b.free ? b.size : (b.size > 8 ? b.size - 8 : b.size);
339+
g_system->m_eventBus->signal(Events::GUI::JumpToMemory{jumpAddr | 0x80000000, jumpSize});
340+
}
320341
ImGui::TableNextColumn();
321342
ImGui::Text("%u", b.size);
322343
ImGui::TableNextColumn();

0 commit comments

Comments
 (0)