diff --git a/src/main.cpp b/src/main.cpp index 6de4694..b464f6e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,6 +40,8 @@ void run_gui_simulation(SimulationState* sim) { render_state.selected_body_index = -1; // No selection initially render_state.show_body_list = false; render_state.show_body_info = false; + render_state.body_list_scroll = 0; // Initial scroll position + render_state.body_list_active = -1; // No active item initially bool paused = false; double speed_multiplier = 1.0; diff --git a/src/renderer.cpp b/src/renderer.cpp index 8e00388..ba8d138 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -402,14 +402,13 @@ void render_body_list_ui(SimulationState* sim, RenderState* render_state) { (float)panel_height - 29 }; - int focus = render_state->selected_body_index; // 0-based indexing - if (focus < 0) focus = 0; + int previous_active = render_state->body_list_active; + GuiListView(list_bounds, body_list_text, &render_state->body_list_scroll, &render_state->body_list_active); - int active = 0; // Raygui uses this internally - int result = GuiListView(list_bounds, body_list_text, &focus, &active); - - if (result >= 0 && result < sim->body_count) { - render_state->selected_body_index = result; + // Check if a body was selected (active changed from -1 or previous value) + if (render_state->body_list_active >= 0 && render_state->body_list_active < sim->body_count && + render_state->body_list_active != previous_active) { + render_state->selected_body_index = render_state->body_list_active; render_state->show_body_info = true; } diff --git a/src/renderer.h b/src/renderer.h index a986937..5453cae 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -13,6 +13,8 @@ struct RenderState { int selected_body_index; // -1 = no selection bool show_body_list; // Toggle for list panel bool show_body_info; // Toggle for info panel + int body_list_scroll; // Scroll position for body list + int body_list_active; // Active item index in body list }; // Renderer initialization and cleanup