-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tables: Automatic column width becomes zero when the number of columns changes #4046
Comments
Thank you Arek for the careful bug report and repro. I did have that working afaik but condition may have changed, some flags may affect it or maybe there was a regression. I will investigate.
Note that hiding/showing column may be a suitable workaround here, but I agree it would be better to fix that scenario.
|
Thanks for the speedy response as always @ocornut :) |
FYI, The same/similar issue occurs with |
…t changes. (#4046) + .ini skips columns with no data.
Pushed fix 770f9da I didn't attempt to preserve column order on column count change as it may be a more trickier (could be investigated later). if (ImGui::Begin("Test #4046"))
{
// Add a new column every 0.5s, up to a max of 10 columns before rolling over back to 1.
double seconds_per_new_column = 0.5f;
int max_num_columns = 10;
const int column_count = static_cast<int>(ImGui::GetTime() / seconds_per_new_column) % max_num_columns + 1;
if (ImGui::BeginTable("Variable Column Count Table", column_count, ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollX))
{
char label[32];
for (int column = 0; column < column_count; column++)
{
sprintf(label, "Column %d", column);
ImGui::TableSetupColumn(label);
}
ImGui::TableHeadersRow();
int row_count = 10;
for (int row = 0; row < row_count; row++)
{
ImGui::TableNextRow();
for (int column = 0; column < column_count; column++)
{
ImGui::TableNextColumn();
// Just some random contents that varies significantly from cell to cell.
ImGui::Text("%d ^ %d = %d", column, row, (int)powf((float)column, (float)row));
}
}
ImGui::EndTable();
}
ImGui::End();
} |
@ocornut Thank you so much for the prompt fix! Would you mind merging it into the docking branch? Our build setup pulls ImGui from GitHub directly so having a merged commit hash would be very helpful :) |
Sorry I did a docking update yesterday, if you need a temporary commit hash you can fork + cherry-pick + push. |
No worries, I wasn't sure how frequently you usually update the branch. The fix works nicely, though it would be nice for the column width to be initialized with at least the column name. |
Not as simple because what you refer to as “Colum name” is simply content which has been output in each column of the header row, and that is designed to be flexible (you can add leading checkboxes or not even submit the header row, still have columns names).
|
I understand that doing it generically is difficult, but it would be nice to at least use an approximate version of the correct size rather than zero. My thinking is that the min-width could be computed from the text size of the column label provided to However, being able to explicitly provide a minimum column width would be valuable. Perhaps I missed it but I didn't see a method of doing so in the current API. |
@ocornut Would it be reasonable for me to open a new ticket requesting the enhancements described in my previous comment or is there an existing method for achieving this? :) |
Outside of your specific use (appending new columns while table a showing):
In the case of a stretched down table this wouldn't be an adequate use. |
Version/Branch of Dear ImGui:
Version: 1.82 WIP 732cd83
Branch: docking
Back-end/Renderer/Compiler/OS
Not relevant
My Issue/Question:
One of the tables in my application has a variable number of columns.
Since the contents of each column can take up a relatively large amount of space, I need to have horizontal scrolling enabled with
ImGuiTableFlags_ScrollX
.The width of each column is correctly computed on most frames.
However, the width of every column becomes 0 (+ padding) whenever the number of tables changes.
This results in an undesirable flicker that is very noticeable if the application is rendering at a lower frame rate.
I expected ImGui to at least initialize the column widths using the column label.
However, I think it would be desirable for ImGui to preserve the previously column width data when the column count changes, at least for the minimum common number of columns.
It's worth noting that the
TableSetupColumn
does not appear to provide a way to set a reasonable minimum width.I attempted to use the following, but it ended up being the permanent width instead of just an initial default:
GIFs
Standalone, minimal, complete and verifiable example:
The text was updated successfully, but these errors were encountered: