ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
61.33k stars 10.33k forks source link

How do I create a modifiable table? #7947

Open xslendix opened 2 months ago

xslendix commented 2 months ago

Version/Branch of Dear ImGui:

1.90.1

Back-ends:

imgui_impl_sdl2 + imgui_impl_sdlrenderer2

Compiler, OS:

Linux x64 + Odin + odin-imgui

Details:

Hello, I want to create a widget that allows me to not only display tabular data, but also modify it (add, remove, change row positions). How would I go about this? Removal would be done by deleting the data in the first column.

image

If it can help simplify everything, the drag icon doesn't need to be there, for example, you could just double click to edit the values

GamingMinds-DanielC commented 2 months ago

Removing a row by emptying the first column doesn't sound very intuitive. How you should go about it depends on what you need it for, my approach would be to mimic what has been proven to work in established spread sheet applications. Maybe add a context menu to rows with "add row above", "add row below" and "remove row" options. For rearranging you could look for "Drag to reorder items (simple)" in imgui_demo.cpp as an inspiration.

Editing items should be no problem as well, you can submit any widgets you want. Just remember that interactive items need unique IDs, you use f.e. the row id to manipulate the ID stack.