Browse Source

Fix raygui body selection - GuiListView return value bug

Issue: GuiListView() always returns 0 (known raygui bug), causing
body selection to never work.

Fix:
- Added body_list_scroll and body_list_active to RenderState for persistence
- Check body_list_active parameter changes instead of return value
- Initialize active state to -1 in main.cpp

Reference: https://github.com/raysan5/raygui/issues/448
main
cinnaboot 6 months ago
parent
commit
85bd9eed80
  1. 2
      src/main.cpp
  2. 13
      src/renderer.cpp
  3. 2
      src/renderer.h

2
src/main.cpp

@ -40,6 +40,8 @@ void run_gui_simulation(SimulationState* sim) {
render_state.selected_body_index = -1; // No selection initially render_state.selected_body_index = -1; // No selection initially
render_state.show_body_list = false; render_state.show_body_list = false;
render_state.show_body_info = 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; bool paused = false;
double speed_multiplier = 1.0; double speed_multiplier = 1.0;

13
src/renderer.cpp

@ -402,14 +402,13 @@ void render_body_list_ui(SimulationState* sim, RenderState* render_state) {
(float)panel_height - 29 (float)panel_height - 29
}; };
int focus = render_state->selected_body_index; // 0-based indexing int previous_active = render_state->body_list_active;
if (focus < 0) focus = 0; GuiListView(list_bounds, body_list_text, &render_state->body_list_scroll, &render_state->body_list_active);
int active = 0; // Raygui uses this internally // Check if a body was selected (active changed from -1 or previous value)
int result = GuiListView(list_bounds, body_list_text, &focus, &active); if (render_state->body_list_active >= 0 && render_state->body_list_active < sim->body_count &&
render_state->body_list_active != previous_active) {
if (result >= 0 && result < sim->body_count) { render_state->selected_body_index = render_state->body_list_active;
render_state->selected_body_index = result;
render_state->show_body_info = true; render_state->show_body_info = true;
} }

2
src/renderer.h

@ -13,6 +13,8 @@ struct RenderState {
int selected_body_index; // -1 = no selection int selected_body_index; // -1 = no selection
bool show_body_list; // Toggle for list panel bool show_body_list; // Toggle for list panel
bool show_body_info; // Toggle for info 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 // Renderer initialization and cleanup

Loading…
Cancel
Save