Note that the NoSortAscending/NoSortDescending flags are processed in TableSortSpecsSanitize(), and they may change/revert the value of SortDirection. We could technically also do it here but it would be unnecessary and duplicate code.
| 2927 | // Note that the NoSortAscending/NoSortDescending flags are processed in TableSortSpecsSanitize(), and they may change/revert |
| 2928 | // the value of SortDirection. We could technically also do it here but it would be unnecessary and duplicate code. |
| 2929 | void ImGui::TableSetColumnSortDirection(int column_n, ImGuiSortDirection sort_direction, bool append_to_sort_specs) |
| 2930 | { |
| 2931 | ImGuiContext& g = *GImGui; |
| 2932 | ImGuiTable* table = g.CurrentTable; |
| 2933 | |
| 2934 | if (!(table->Flags & ImGuiTableFlags_SortMulti)) |
| 2935 | append_to_sort_specs = false; |
| 2936 | if (!(table->Flags & ImGuiTableFlags_SortTristate)) |
| 2937 | IM_ASSERT(sort_direction != ImGuiSortDirection_None); |
| 2938 | |
| 2939 | ImGuiTableColumnIdx sort_order_max = 0; |
| 2940 | if (append_to_sort_specs) |
| 2941 | for (int other_column_n = 0; other_column_n < table->ColumnsCount; other_column_n++) |
| 2942 | sort_order_max = ImMax(sort_order_max, table->Columns[other_column_n].SortOrder); |
| 2943 | |
| 2944 | ImGuiTableColumn* column = &table->Columns[column_n]; |
| 2945 | column->SortDirection = (ImU8)sort_direction; |
| 2946 | if (column->SortDirection == ImGuiSortDirection_None) |
| 2947 | column->SortOrder = -1; |
| 2948 | else if (column->SortOrder == -1 || !append_to_sort_specs) |
| 2949 | column->SortOrder = append_to_sort_specs ? sort_order_max + 1 : 0; |
| 2950 | |
| 2951 | for (int other_column_n = 0; other_column_n < table->ColumnsCount; other_column_n++) |
| 2952 | { |
| 2953 | ImGuiTableColumn* other_column = &table->Columns[other_column_n]; |
| 2954 | if (other_column != column && !append_to_sort_specs) |
| 2955 | other_column->SortOrder = -1; |
| 2956 | TableFixColumnSortDirection(table, other_column); |
| 2957 | } |
| 2958 | table->IsSettingsDirty = true; |
| 2959 | table->IsSortSpecsDirty = true; |
| 2960 | } |
| 2961 | |
| 2962 | void ImGui::TableSortSpecsSanitize(ImGuiTable* table) |
| 2963 | { |