ocornut / imgui

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

ImGui::TableSetColumnWidth missing from public API? #6704

Open hdclark opened 11 months ago

hdclark commented 11 months ago

Version/Branch of Dear ImGui:

Version: current master Branch: master

My Issue/Question:

The function ImGui::TableSetColumnWidth is not provided in imgui.h as part of the public API. However, it is marked as a non-internal function in imgui_tables.cpp. Adding the function declaration to imgui.h seems to work as expected without (obvious?) side-effects.

See 'non-internal' definition around https://github.com/ocornut/imgui/blob/bc3c0ce7728f39530020a979a19bfc176e4e8596/imgui_tables.cpp#L2081-L2090 compared with lack of public API declaration around https://github.com/ocornut/imgui/blob/bc3c0ce7728f39530020a979a19bfc176e4e8596/imgui.h#L775-L789

Is there rationale for explicitly omitting this function from the public API, or was it accidentally omitted?

I need this function to support content-based resizing when widgets inside cells expand to fill available space. From what I can tell, ImGui::TableSetColumnWidth is the only way to emulate user-driven column resizing. All other widths in the public tables API seem to be treated as defaults.

Just wondering if it's safe to rely on ImGui::TableSetColumnWidth going forward.

ocornut commented 10 months ago

If you want the column to fit available contents you can set the column flags to use ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_WidthFixed and it should auto-resizing?

The function is unlikely to change. The rationale is that even though people intuitively want this function it is more often not the exact feature they need, and encouraging people to manipulate column width tends to put them in situation when they easily break things.

hdclark commented 10 months ago

If you want the column to fit available contents ...

I need to support both (1) the column resizing to fit the contents, and (2) the contents expanding to fill the available space in the column. It sounds contradictory, but there is a very sensible use-case here.

This is needed to support what is essentially a spreadsheet where the cells are rendered as Text widgets, but then switch to InputText widgets when the cell is clicked[*].

Calling ImGui::TableSetColumnWidth explicitly (e.g., when the user pushes button) completely solves the problem, so it's slightly painful that it's not part of the public API.

This could also be solved with a custom widget, but there is literally this one missing function that causes the issue. Adding the declaration is a one-line fix, so it's extremely hard to justify making a custom widget that correctly handles input text.


[*] Rationale for splitting Text and InputText in a cell: to support multiple cell selection for copy-and-paste.