add ReadOnly but allow selecting bytes

This commit is contained in:
silverweed 2024-07-18 17:43:44 +02:00
parent a3743238e8
commit c3ded7b808
4 changed files with 53 additions and 7 deletions

View file

@ -120,7 +120,7 @@ internal
MemoryEditor make_memory_editor(App_State &app) MemoryEditor make_memory_editor(App_State &app)
{ {
MemoryEditor mem_edit; MemoryEditor mem_edit;
// mem_edit.ReadOnly = true; mem_edit.ReadOnly = true;
mem_edit.Cols = 32; mem_edit.Cols = 32;
mem_edit.OptShowDataPreview = true; mem_edit.OptShowDataPreview = true;
mem_edit.BgColorFn = mem_edit_bg_color_fn; mem_edit.BgColorFn = mem_edit_bg_color_fn;
@ -176,6 +176,18 @@ void viewer_jump_to_page(App_State &app, u64 page_idx)
viewer_jump_to(app.viewer, page->range.start); viewer_jump_to(app.viewer, page->range.start);
} }
internal
void viewer_jump_to_page_list(App_State &app, u64 page_list_idx)
{
assert(app.rndata.n_cluster_groups > 0);
page_list_idx = (page_list_idx + app.rndata.n_cluster_groups) % app.rndata.n_cluster_groups;
Cluster_Group_Info &cg_info = app.rndata.cluster_groups[page_list_idx];
app.viewer.latest_page_list_gone_to = page_list_idx;
viewer_jump_to(app.viewer, cg_info.rng_page_list.start);
}
internal internal
void update_and_render(Arena *arena, App_State &app, f32 delta_time_ms) void update_and_render(Arena *arena, App_State &app, f32 delta_time_ms)
{ {
@ -216,6 +228,8 @@ void update_and_render(Arena *arena, App_State &app, f32 delta_time_ms)
// Draw main content // Draw main content
{ {
const u64 step_u64 = 1;
ImGui::BeginTable("Hex View", 2, ImGuiTableFlags_Resizable); ImGui::BeginTable("Hex View", 2, ImGuiTableFlags_Resizable);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
@ -236,14 +250,20 @@ void update_and_render(Arena *arena, App_State &app, f32 delta_time_ms)
ImGui::ColorEdit3("_TFile Object", app.viewer.col_tfile_obj, flags); ImGui::ColorEdit3("_TFile Object", app.viewer.col_tfile_obj, flags);
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("TFile Object")) viewer_jump_to(app.viewer, app.tfile_data.rng_root_file_obj.start); if (ImGui::Button("TFile Object")) viewer_jump_to(app.viewer, app.tfile_data.rng_root_file_obj.start);
ImGui::SameLine();
ImGui::Text("%s", to_pretty_size(scratch.arena, app.tfile_data.rng_root_file_obj.len).c());
ImGui::ColorEdit3("_TFile Info", app.viewer.col_tfile_info, flags); ImGui::ColorEdit3("_TFile Info", app.viewer.col_tfile_info, flags);
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("TFile Info")) viewer_jump_to(app.viewer, app.tfile_data.rng_root_file_info.start); if (ImGui::Button("TFile Info")) viewer_jump_to(app.viewer, app.tfile_data.rng_root_file_info.start);
ImGui::SameLine();
ImGui::Text("%s", to_pretty_size(scratch.arena, app.tfile_data.rng_root_file_info.len).c());
ImGui::ColorEdit3("_TFile FreeList", app.viewer.col_tfile_free, flags); ImGui::ColorEdit3("_TFile FreeList", app.viewer.col_tfile_free, flags);
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("TFile FreeList")) viewer_jump_to(app.viewer, app.tfile_data.rng_root_file_free.start); if (ImGui::Button("TFile FreeList")) viewer_jump_to(app.viewer, app.tfile_data.rng_root_file_free.start);
ImGui::SameLine();
ImGui::Text("%s", to_pretty_size(scratch.arena, app.tfile_data.rng_root_file_free.len).c());
ImGui::ColorEdit3("_RNTuple Anchor", app.viewer.col_anchor, flags); ImGui::ColorEdit3("_RNTuple Anchor", app.viewer.col_anchor, flags);
ImGui::SameLine(); ImGui::SameLine();
@ -276,10 +296,10 @@ void update_and_render(Arena *arena, App_State &app, f32 delta_time_ms)
if (ImGui::Button("Page")) viewer_jump_to_page(app, app.viewer.latest_page_gone_to); if (ImGui::Button("Page")) viewer_jump_to_page(app, app.viewer.latest_page_gone_to);
ImGui::SameLine(); ImGui::SameLine();
{ {
// TODO: support u64 const u64 step_fast_u64 = app.rndata.n_pages / 100;
i32 page_to_go_to = static_cast<i32>(app.viewer.latest_page_gone_to); u64 page_to_go_to = app.viewer.latest_page_gone_to;
ImGui::PushItemWidth(100.f); ImGui::PushItemWidth(100.f);
if (ImGui::InputInt("##page_viewed", &page_to_go_to)) if (ImGui::InputScalar("##page_viewed", ImGuiDataType_U64, &page_to_go_to, &step_u64, &step_fast_u64, "%u"))
viewer_jump_to_page(app, page_to_go_to); viewer_jump_to_page(app, page_to_go_to);
ImGui::PopItemWidth(); ImGui::PopItemWidth();
} }
@ -292,7 +312,15 @@ void update_and_render(Arena *arena, App_State &app, f32 delta_time_ms)
ImGui::ColorEdit3("_Page List", app.viewer.col_page_list, flags); ImGui::ColorEdit3("_Page List", app.viewer.col_page_list, flags);
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Page List")) {} // TODO jump to next page list if (ImGui::Button("Page List")) viewer_jump_to_page_list(app, app.viewer.latest_page_list_gone_to);
ImGui::SameLine();
{
u64 page_list_to_go_to = app.viewer.latest_page_list_gone_to;
ImGui::PushItemWidth(80.f);
if (ImGui::InputScalar("##page_list_viewed", ImGuiDataType_U64, &page_list_to_go_to, &step_u64, nullptr, "%u"))
viewer_jump_to_page_list(app, page_list_to_go_to);
ImGui::PopItemWidth();
}
ImGui::SameLine(); ImGui::SameLine();
ImGui::Text("%s", to_pretty_size(scratch.arena, app.rndata.tot_page_list_size).c()); ImGui::Text("%s", to_pretty_size(scratch.arena, app.rndata.tot_page_list_size).c());

View file

@ -15,7 +15,11 @@ struct Viewer {
f32 col_page_list[3]; f32 col_page_list[3];
u64 base_display_addr; u64 base_display_addr;
u64 latest_page_gone_to; u64 latest_page_gone_to;
u64 latest_key_gone_to;
u64 latest_checksum_gone_to;
u64 latest_page_list_gone_to;
}; };
struct Edit_Bg_Color_Data { struct Edit_Bg_Color_Data {

View file

@ -16,6 +16,12 @@ struct Page_Info_Node {
} }
}; };
// Used to store location information about stuff like checksums, page lists, etc
struct Range_Seq {
Range_Seq *next;
Byte_Range range;
};
static const Page_Info_Node invalid_pinfo {}; static const Page_Info_Node invalid_pinfo {};
struct Page_Info_Group { struct Page_Info_Group {
@ -65,6 +71,12 @@ struct RNTuple_Data {
u64 n_elems; u64 n_elems;
u64 tot_page_size; u64 tot_page_size;
Range_Seq *checksums;
u64 n_checksums;
Range_Seq *page_lists;
u64 n_page_lists;
Cluster_Group_Info *cluster_groups; Cluster_Group_Info *cluster_groups;
u64 n_cluster_groups; u64 n_cluster_groups;
u64 tot_page_list_size; u64 tot_page_list_size;

View file

@ -245,7 +245,7 @@ struct MemoryEditor
bool data_next = false; bool data_next = false;
if (ReadOnly || DataEditingAddr >= mem_size) if (/*ReadOnly ||*/ DataEditingAddr >= mem_size)
DataEditingAddr = (size_t)-1; DataEditingAddr = (size_t)-1;
if (DataPreviewAddr >= mem_size) if (DataPreviewAddr >= mem_size)
DataPreviewAddr = (size_t)-1; DataPreviewAddr = (size_t)-1;
@ -320,6 +320,7 @@ struct MemoryEditor
draw_list->AddRectFilled(pos, ImVec2(pos.x + highlight_width, pos.y + s.LineHeight), BgColorFn(mem_data, addr, BgColorFnUserData)); draw_list->AddRectFilled(pos, ImVec2(pos.x + highlight_width, pos.y + s.LineHeight), BgColorFn(mem_data, addr, BgColorFnUserData));
} }
#if 0
if (DataEditingAddr == addr) if (DataEditingAddr == addr)
{ {
// Display text input on current byte // Display text input on current byte
@ -380,6 +381,7 @@ struct MemoryEditor
ImGui::PopID(); ImGui::PopID();
} }
else else
#endif
{ {
// NB: The trailing space is not visible but ensure there's no gap that the mouse cannot click on. // NB: The trailing space is not visible but ensure there's no gap that the mouse cannot click on.
ImU8 b = ReadFn ? ReadFn(mem_data, addr) : mem_data[addr]; ImU8 b = ReadFn ? ReadFn(mem_data, addr) : mem_data[addr];
@ -402,7 +404,7 @@ struct MemoryEditor
else else
ImGui::Text(format_byte_space, b); ImGui::Text(format_byte_space, b);
} }
if (!ReadOnly && ImGui::IsItemHovered() && ImGui::IsMouseClicked(0)) if (/*!ReadOnly &&*/ ImGui::IsItemHovered() && ImGui::IsMouseClicked(0))
{ {
DataEditingTakeFocus = true; DataEditingTakeFocus = true;
data_editing_addr_next = addr; data_editing_addr_next = addr;