Skip to content

Commit

Permalink
ui-imgui: Add a couple of table helpers
Browse files Browse the repository at this point in the history
Add ui_igVec3TableHeader() to start a table of 3-component vectors and
ui_igVec3Row() to generate a table row from a vector and a string.

Signed-off-by: Alexander Shishkin <[email protected]>
  • Loading branch information
virtuoso committed Oct 30, 2024
1 parent 648e263 commit 85054ab
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/ui-debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ void imgui_done(void);
void imgui_render_begin(int width, int height);
void imgui_render(void);

bool ui_igVec3TableHeader(const char *str_id);
void ui_igVec3Row(float v[3], const char *fmt, ...);

#endif /* __CLAP_UI_DEBUG_H__ */
33 changes: 33 additions & 0 deletions core/ui-imgui.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,36 @@ void imgui_done(void)
#endif
igDestroyContext(ctx);
}

bool ui_igVec3TableHeader(const char *str_id)
{
if (!igBeginTable(str_id, 4, ImGuiTableFlags_Borders, (ImVec2){0,0}, 0))
return false;

igTableSetupColumn("vector", ImGuiTableColumnFlags_WidthStretch, 0, 0);
igTableSetupColumn("X", ImGuiTableColumnFlags_WidthFixed, 0, 0);
igTableSetupColumn("Y", ImGuiTableColumnFlags_WidthFixed, 0, 0);
igTableSetupColumn("Z", ImGuiTableColumnFlags_WidthFixed, 0, 0);

return true;
}

void ui_igVec3Row(float v[3], const char *fmt, ...)
{
char buf[128];
va_list va;

va_start(va, fmt);
vsnprintf(buf, sizeof(buf), fmt, va);
va_end(va);

igTableNextRow(0, 0);
igTableNextColumn();
igText(buf);
igTableNextColumn();
igText("%f", v[0]);
igTableNextColumn();
igText("%f", v[1]);
igTableNextColumn();
igText("%f", v[2]);
}

0 comments on commit 85054ab

Please sign in to comment.