Layout columns for the frame. This is in essence the followup to BeginTable() and this is our largest function. Runs on the first call to TableNextRow(), to give a chance for TableSetupColumn() and other TableSetupXXXXX() functions to be called first. FIXME-TABLE: Our width (and therefore our WorkRect) will be minimal in the first frame for _WidthAuto columns. Increase feedback side-effect with wi
| 847 | // FIXME-TABLE: Our width (and therefore our WorkRect) will be minimal in the first frame for _WidthAuto columns. |
| 848 | // Increase feedback side-effect with widgets relying on WorkRect.Max.x... Maybe provide a default distribution for _WidthAuto columns? |
| 849 | void ImGui::TableUpdateLayout(ImGuiTable* table) |
| 850 | { |
| 851 | ImGuiContext& g = *GImGui; |
| 852 | IM_ASSERT(table->IsLayoutLocked == false); |
| 853 | |
| 854 | const ImGuiTableFlags table_sizing_policy = (table->Flags & ImGuiTableFlags_SizingMask_); |
| 855 | table->IsDefaultDisplayOrder = true; |
| 856 | table->ColumnsEnabledCount = 0; |
| 857 | ImBitArrayClearAllBits(table->EnabledMaskByIndex, table->ColumnsCount); |
| 858 | ImBitArrayClearAllBits(table->EnabledMaskByDisplayOrder, table->ColumnsCount); |
| 859 | table->LeftMostEnabledColumn = -1; |
| 860 | table->MinColumnWidth = ImMax(1.0f, g.Style.FramePadding.x * 1.0f); // g.Style.ColumnsMinSpacing; // FIXME-TABLE |
| 861 | |
| 862 | // [Part 1] Apply/lock Enabled and Order states. Calculate auto/ideal width for columns. Count fixed/stretch columns. |
| 863 | // Process columns in their visible orders as we are building the Prev/Next indices. |
| 864 | int count_fixed = 0; // Number of columns that have fixed sizing policies |
| 865 | int count_stretch = 0; // Number of columns that have stretch sizing policies |
| 866 | int prev_visible_column_idx = -1; |
| 867 | bool has_auto_fit_request = false; |
| 868 | bool has_resizable = false; |
| 869 | float stretch_sum_width_auto = 0.0f; |
| 870 | float fixed_max_width_auto = 0.0f; |
| 871 | for (int order_n = 0; order_n < table->ColumnsCount; order_n++) |
| 872 | { |
| 873 | const int column_n = table->DisplayOrderToIndex[order_n]; |
| 874 | if (column_n != order_n) |
| 875 | table->IsDefaultDisplayOrder = false; |
| 876 | ImGuiTableColumn* column = &table->Columns[column_n]; |
| 877 | |
| 878 | // Clear column setup if not submitted by user. Currently we make it mandatory to call TableSetupColumn() every frame. |
| 879 | // It would easily work without but we're not ready to guarantee it since e.g. names need resubmission anyway. |
| 880 | // We take a slight shortcut but in theory we could be calling TableSetupColumn() here with dummy values, it should yield the same effect. |
| 881 | if (table->DeclColumnsCount <= column_n) |
| 882 | { |
| 883 | TableSetupColumnFlags(table, column, ImGuiTableColumnFlags_None); |
| 884 | column->NameOffset = -1; |
| 885 | column->UserID = 0; |
| 886 | column->InitStretchWeightOrWidth = -1.0f; |
| 887 | } |
| 888 | |
| 889 | // Update Enabled state, mark settings and sort specs dirty |
| 890 | if (!(table->Flags & ImGuiTableFlags_Hideable) || (column->Flags & ImGuiTableColumnFlags_NoHide)) |
| 891 | column->IsUserEnabledNextFrame = true; |
| 892 | if (column->IsUserEnabled != column->IsUserEnabledNextFrame) |
| 893 | { |
| 894 | column->IsUserEnabled = column->IsUserEnabledNextFrame; |
| 895 | table->IsSettingsDirty = true; |
| 896 | } |
| 897 | column->IsEnabled = column->IsUserEnabled && (column->Flags & ImGuiTableColumnFlags_Disabled) == 0; |
| 898 | |
| 899 | if (column->SortOrder != -1 && !column->IsEnabled) |
| 900 | table->IsSortSpecsDirty = true; |
| 901 | if (column->SortOrder > 0 && !(table->Flags & ImGuiTableFlags_SortMulti)) |
| 902 | table->IsSortSpecsDirty = true; |
| 903 | |
| 904 | // Auto-fit unsized columns |
| 905 | const bool start_auto_fit = (column->Flags & ImGuiTableColumnFlags_WidthFixed) ? (column->WidthRequest < 0.0f) : (column->StretchWeight < 0.0f); |
| 906 | if (start_auto_fit) |
nothing calls this directly
no test coverage detected