Browse Source

Fix body list format for raygui compatibility

- Convert body names array to semicolon-separated string format
- Fix GuiListView parameter usage with proper format
- Ensure proper memory management for body list text
main
cinnaboot 6 months ago
parent
commit
7988aa7fa7
  1. 28
      src/renderer.cpp

28
src/renderer.cpp

@ -376,12 +376,17 @@ void render_body_list_ui(SimulationState* sim, RenderState* render_state) {
Rectangle panel_bounds = { (float)panel_x, (float)panel_y, (float)panel_width, (float)panel_height }; Rectangle panel_bounds = { (float)panel_x, (float)panel_y, (float)panel_width, (float)panel_height };
// Create body list for raygui // Create body list string for raygui (NULL-terminated)
const char** body_names = (const char**)malloc(sim->body_count * sizeof(char*)); char* body_list_text = (char*)malloc(sim->body_count * 64); // 64 chars per name max
if (!body_names) return; if (!body_list_text) return;
body_list_text[0] = '\0'; // Initialize empty string
for (int i = 0; i < sim->body_count; i++) { for (int i = 0; i < sim->body_count; i++) {
body_names[i] = sim->bodies[i].name; if (i > 0) {
strcat(body_list_text, ";"); // Separator for raygui
}
strcat(body_list_text, sim->bodies[i].name);
} }
// Draw window // Draw window
@ -397,21 +402,18 @@ void render_body_list_ui(SimulationState* sim, RenderState* render_state) {
(float)panel_height - 29 (float)panel_height - 29
}; };
int focus = 0; int focus = render_state->selected_body_index; // 0-based indexing
int active = 0; if (focus < 0) focus = 0;
if (render_state->selected_body_index >= 0 && render_state->selected_body_index < sim->body_count) {
focus = render_state->selected_body_index; // 0-based indexing for scroll
active = 1; // Mark as active
}
int result = GuiListView(list_bounds, (const char*)body_names, &focus, &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) { if (result >= 0 && result < sim->body_count) {
render_state->selected_body_index = result; render_state->selected_body_index = result;
render_state->show_body_info = true; render_state->show_body_info = true;
} }
free(body_names); free(body_list_text);
} }
// Render body information UI panel // Render body information UI panel

Loading…
Cancel
Save