improve hovered_off logic

This commit is contained in:
silverweed 2024-08-01 17:05:37 +02:00
parent 04680e281c
commit 70cd97e92b
2 changed files with 9 additions and 3 deletions

View file

@ -91,7 +91,7 @@ void mem_edit_interact_fn(const u8 *, u64 off, void *user_data)
{
App_State *app = reinterpret_cast<App_State *>(user_data);
off += app->base_display_addr;
app->viewer.hovered_off = off;
app->viewer.hovered_off = off + 1;
}
internal
@ -232,6 +232,8 @@ void update_and_render(Arena *arena, App_State &app, f32 delta_time_ms)
ImGui::TableNextColumn();
app.viewer.hovered_off = 0;
assert(app.base_display_addr < app.inspected_file.size);
void *content = app.inspected_file.mem + app.base_display_addr;
u64 content_size = app.inspected_file.size - app.base_display_addr;
@ -329,9 +331,10 @@ void update_and_render(Arena *arena, App_State &app, f32 delta_time_ms)
// ---------------------------------
ImGui::Separator();
if (app.viewer.hovered_off)
{
Section hovered_section = find_section(app, app.viewer.hovered_off);
Sec_Hover_Info hover_info = get_section_hover_info(scratch.arena, hovered_section, app.viewer.hovered_off, app.inspected_file.mem);
Section hovered_section = find_section(app, app.viewer.hovered_off - 1);
Sec_Hover_Info hover_info = get_section_hover_info(scratch.arena, hovered_section, app.viewer.hovered_off - 1, app.inspected_file.mem);
u8 indent = 0;
for (String8_Node *node = hover_info.desc; node; node = node->next) {
String8 fmt = str8("%s");
@ -344,6 +347,8 @@ void update_and_render(Arena *arena, App_State &app, f32 delta_time_ms)
indent += 2;
}
app.viewer.hovered_range = hover_info.rng;
} else {
app.viewer.hovered_range = {};
}
ImGui::EndTable();

View file

@ -19,6 +19,7 @@ struct Viewer {
u64 latest_page_list_gone_to;
// Absolute byte offset into inspected_file.mem that has been hovered last.
// 0 means "invalid", otherwise the actual offset is `hovered_off - 1`.
u64 hovered_off;
Byte_Range hovered_range;
};