clicking on hovered page updates legend

This commit is contained in:
silverweed 2024-09-24 11:17:18 +02:00
parent cae82ef66f
commit d1dc7f23c1
6 changed files with 54 additions and 5 deletions

View file

@ -60,6 +60,21 @@ void monitor_key(GLFWwindow *window, u8 *key_state, i32 glfw_key, Input_Key key)
} }
} }
internal
void monitor_mouse_btn(GLFWwindow *window, u8 *mouse_btn_state, i32 glfw_btn, Mouse_Button btn)
{
u8 *state = &mouse_btn_state[btn];
if (glfwGetMouseButton(window, glfw_btn) == GLFW_PRESS) {
if (!(*state & MOUSE_BTN_STATE_IS_DOWN))
*state |= MOUSE_BTN_STATE_JUST_PRESSED;
*state |= MOUSE_BTN_STATE_IS_DOWN;
} else if (glfwGetMouseButton(window, glfw_btn) == GLFW_RELEASE) {
if (*state & MOUSE_BTN_STATE_IS_DOWN)
*state |= MOUSE_BTN_STATE_JUST_RELEASED;
*state &= ~MOUSE_BTN_STATE_IS_DOWN;
}
}
internal internal
void run_main_loop(GLFWwindow *window, Arena *arena, App_State &app) void run_main_loop(GLFWwindow *window, Arena *arena, App_State &app)
{ {
@ -75,6 +90,9 @@ void run_main_loop(GLFWwindow *window, Arena *arena, App_State &app)
delta_time_ms = time_since_prev_frame_us * 0.001f; delta_time_ms = time_since_prev_frame_us * 0.001f;
last_saved_time = frame_start; last_saved_time = frame_start;
for (u32 i = 0; i < MOUSE_BTN_COUNT; ++i)
app.user_input.mouse_btn_state[i] &= ~(MOUSE_BTN_STATE_JUST_PRESSED|MOUSE_BTN_STATE_JUST_RELEASED);
glfwPollEvents(); glfwPollEvents();
// Update window size // Update window size
@ -122,6 +140,10 @@ void run_main_loop(GLFWwindow *window, Arena *arena, App_State &app)
f64 mposx, mposy; f64 mposx, mposy;
glfwGetCursorPos(window, &mposx, &mposy); glfwGetCursorPos(window, &mposx, &mposy);
u8 *mouse_btn_state = app.user_input.mouse_btn_state;
monitor_mouse_btn(window, mouse_btn_state, GLFW_MOUSE_BUTTON_LEFT, MOUSE_BTN_LEFT);
monitor_mouse_btn(window, mouse_btn_state, GLFW_MOUSE_BUTTON_RIGHT, MOUSE_BTN_RIGHT);
app.user_input.mouse_pos.x = static_cast<i32>(mposx); app.user_input.mouse_pos.x = static_cast<i32>(mposx);
app.user_input.mouse_pos.y = static_cast<i32>(mposy); app.user_input.mouse_pos.y = static_cast<i32>(mposy);
} }

View file

@ -167,7 +167,7 @@ void viewer_jump_to(App_State &app, u64 addr)
} }
internal internal
void viewer_jump_to_page(App_State &app, u64 page_idx) Page_Info_Node *viewer_jump_to_page(App_State &app, u64 page_idx)
{ {
assert(app.rndata.n_pages > 0); assert(app.rndata.n_pages > 0);
page_idx = (page_idx + app.rndata.n_pages) % app.rndata.n_pages; page_idx = (page_idx + app.rndata.n_pages) % app.rndata.n_pages;
@ -181,6 +181,8 @@ void viewer_jump_to_page(App_State &app, u64 page_idx)
app.viewer.latest_page_gone_to = page_idx; app.viewer.latest_page_gone_to = page_idx;
viewer_jump_to(app, page->range.start); viewer_jump_to(app, page->range.start);
return page;
} }
internal internal
@ -313,23 +315,24 @@ void update_and_render(Arena *arena, App_State &app, f32 delta_time_ms)
ImGui::ColorEdit3("_Page Start", app.viewer.col_page_start, edit_flags); ImGui::ColorEdit3("_Page Start", app.viewer.col_page_start, edit_flags);
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Page Start")) if (ImGui::Button("Page Start"))
viewer_jump_to_page(app, 0); app.viewer.latest_page = viewer_jump_to_page(app, 0);
ImGui::ColorEdit3("_Page", app.viewer.col_section[Sec_Page], edit_flags); ImGui::ColorEdit3("_Page", app.viewer.col_section[Sec_Page], edit_flags);
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Page")) if (ImGui::Button("Page"))
viewer_jump_to_page(app, app.viewer.latest_page_gone_to); app.viewer.latest_page = viewer_jump_to_page(app, app.viewer.latest_page_gone_to);
ImGui::SameLine(); ImGui::SameLine();
{ {
const i64 step_fast_i64 = app.rndata.n_pages / 100; const i64 step_fast_i64 = app.rndata.n_pages / 100;
i64 page_to_go_to = app.viewer.latest_page_gone_to; i64 page_to_go_to = app.viewer.latest_page_gone_to;
ImGui::PushItemWidth(100.f); ImGui::PushItemWidth(100.f);
if (ImGui::InputScalar("##page_viewed", ImGuiDataType_S64, &page_to_go_to, &step_i64, &step_fast_i64, "%u", input_flags)) if (ImGui::InputScalar("##page_viewed", ImGuiDataType_S64, &page_to_go_to, &step_i64, &step_fast_i64, "%u", input_flags))
viewer_jump_to_page(app, page_to_go_to); app.viewer.latest_page = viewer_jump_to_page(app, page_to_go_to);
ImGui::PopItemWidth(); ImGui::PopItemWidth();
} }
ImGui::SameLine(); ImGui::SameLine();
ImGui::Text("%s", to_pretty_size(scratch.arena, app.rndata.tot_page_comp_size).c()); String8 this_page_width = app.viewer.latest_page ? push_str8f(scratch.arena, " (this page: %s)", to_pretty_size(scratch.arena, app.viewer.latest_page->range.len).c()) : str8("");
ImGui::Text("%s%s", to_pretty_size(scratch.arena, app.rndata.tot_page_comp_size).c(), this_page_width.c());
ImGui::ColorEdit3("_Checksum", app.viewer.col_checksum, edit_flags); ImGui::ColorEdit3("_Checksum", app.viewer.col_checksum, edit_flags);
ImGui::SameLine(); ImGui::SameLine();
@ -394,6 +397,12 @@ void update_and_render(Arena *arena, App_State &app, f32 delta_time_ms)
ImGui::TextColored(ImColor(0.5f, 0.5f, 0.5f), "(Hint: press Alt for single-field hover information)"); ImGui::TextColored(ImColor(0.5f, 0.5f, 0.5f), "(Hint: press Alt for single-field hover information)");
imgui_render_string_tree(scratch.arena, hover_info.desc->head); imgui_render_string_tree(scratch.arena, hover_info.desc->head);
app.viewer.hovered_range = hover_info.rng; app.viewer.hovered_range = hover_info.rng;
// Clicking on a page section will update the current page in the legend
if (hovered_section.id == Sec_Page && (app.user_input.mouse_btn_state[MOUSE_BTN_LEFT] & MOUSE_BTN_STATE_JUST_PRESSED)) {
u64 page_id = ((const Page_Info_Node *)hovered_section.info)->page_id;
app.viewer.latest_page = viewer_jump_to_page(app, page_id);
}
} else { } else {
app.viewer.hovered_range = {}; app.viewer.hovered_range = {};
} }

View file

@ -16,6 +16,8 @@ struct Viewer {
b8 highlight_zstd_headers; b8 highlight_zstd_headers;
u64 last_seen_zstd_header_start; u64 last_seen_zstd_header_start;
Page_Info_Node *latest_page;
u64 latest_page_gone_to; u64 latest_page_gone_to;
u64 latest_key_gone_to; u64 latest_key_gone_to;
u64 latest_checksum_gone_to; u64 latest_checksum_gone_to;

View file

@ -290,6 +290,7 @@ void gather_ntuple_metadata(Arena *arena, RMicroFileReader &reader, const RNTupl
for (Page_Info_Node *pinfo = pinfo_head->next; pinfo; pinfo = pinfo->next) { for (Page_Info_Node *pinfo = pinfo_head->next; pinfo; pinfo = pinfo->next) {
assert(prev->range.end() <= pinfo->range.start); assert(prev->range.end() <= pinfo->range.start);
prev = pinfo; prev = pinfo;
pinfo->page_id = idx;
if (pinfo->range.start != chunks_tail->range.end()) { if (pinfo->range.start != chunks_tail->range.end()) {
// close current chunk and open new one // close current chunk and open new one

View file

@ -18,6 +18,8 @@ struct Page_Info_Node {
u32 cluster_id; u32 cluster_id;
b8 is_first_in_cluster; b8 is_first_in_cluster;
u64 page_id;
u8 bits_per_elem; u8 bits_per_elem;
String8 elem_type_name; String8 elem_type_name;
String8 owner_field_name; String8 owner_field_name;

View file

@ -16,8 +16,21 @@ enum Key_State : u8 {
KEY_STATE_JUST_RELEASED = 0x4, KEY_STATE_JUST_RELEASED = 0x4,
}; };
enum Mouse_Button {
MOUSE_BTN_LEFT,
MOUSE_BTN_RIGHT,
MOUSE_BTN_COUNT
};
enum Mouse_Button_State : u8 {
MOUSE_BTN_STATE_IS_DOWN = 0x1,
MOUSE_BTN_STATE_JUST_PRESSED = 0x2,
MOUSE_BTN_STATE_JUST_RELEASED = 0x4,
};
struct User_Input { struct User_Input {
u8 key_state[KEY_COUNT]; u8 key_state[KEY_COUNT];
u8 mouse_btn_state[MOUSE_BTN_COUNT];
struct { i32 x; i32 y; } mouse_pos; struct { i32 x; i32 y; } mouse_pos;
}; };