Tables: reorder allowed check sweep through columns, checks _NoOrder barrier, and reworked to be easy to use from context menu. (#9312)
The sweep doesn't make a difference for reordering with headers as reordering is currently done 1 by 1. But menu ordering will change that.
This commit is contained in:
+23
-10
@@ -745,24 +745,37 @@ void ImGui::TableSetColumnDisplayOrder(ImGuiTable* table, int column_n, int dst_
|
|||||||
table->IsSettingsDirty = true;
|
table->IsSettingsDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reorder requested by user interaction.
|
static int TableGetMaxDisplayOrderAllowed(ImGuiTable* table, int src_order, int dst_order)
|
||||||
void ImGui::TableQueueSetColumnDisplayOrder(ImGuiTable* table, int column_n, int dst_order)
|
|
||||||
{
|
{
|
||||||
ImGuiTableColumn* src_column = &table->Columns[column_n];
|
dst_order = ImClamp(dst_order, 0, table->ColumnsCount - 1);
|
||||||
int src_order = src_column->DisplayOrder;
|
if (src_order == dst_order)
|
||||||
|
return dst_order;
|
||||||
|
|
||||||
// Verify that we don't cross the frozen column limit.
|
// Cannot cross over the frozen column limit when interactively reordering.
|
||||||
// TableSetupScrollFreeze() enforce a display order range for frozen columns. Reordering across the frozen column barrier is illegal and will be undone.
|
// TableSetupScrollFreeze() enforce a display order range for frozen columns. Reordering across the frozen column barrier is illegal and will be undone.
|
||||||
if (src_column->IsUserEnabled && (src_order < table->FreezeColumnsRequest) != (dst_order < table->FreezeColumnsRequest))
|
if (table->FreezeColumnsRequest > 0)
|
||||||
return;
|
dst_order = (src_order < table->FreezeColumnsRequest) ? ImMin(dst_order, (int)table->FreezeColumnsRequest - 1) : ImMax(dst_order, (int)table->FreezeColumnsRequest);
|
||||||
|
|
||||||
// Verify that we don't reorder columns with the ImGuiTableColumnFlags_NoReorder flag, nor cross through them.
|
// Cannot cross over a column with the ImGuiTableColumnFlags_NoReorder flag.
|
||||||
int reorder_dir = (src_order < dst_order) ? +1 : -1;
|
int reorder_dir = (src_order < dst_order) ? +1 : -1;
|
||||||
for (int order_n = src_order; (src_order < dst_order && order_n <= dst_order) || (dst_order < src_order && order_n >= dst_order); order_n += reorder_dir)
|
for (int order_n = src_order; (src_order < dst_order && order_n <= dst_order) || (dst_order < src_order && order_n >= dst_order); order_n += reorder_dir)
|
||||||
if (table->Columns[table->DisplayOrderToIndex[order_n]].Flags & ImGuiTableColumnFlags_NoReorder)
|
if (table->Columns[table->DisplayOrderToIndex[order_n]].Flags & ImGuiTableColumnFlags_NoReorder)
|
||||||
return;
|
{
|
||||||
|
dst_order = (order_n == src_order) ? src_order : order_n - reorder_dir;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return dst_order;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reorder requested by user interaction.
|
||||||
|
void ImGui::TableQueueSetColumnDisplayOrder(ImGuiTable* table, int column_n, int dst_order)
|
||||||
|
{
|
||||||
|
const int src_order = table->Columns[column_n].DisplayOrder;
|
||||||
table->ReorderColumn = (ImGuiTableColumnIdx)column_n;
|
table->ReorderColumn = (ImGuiTableColumnIdx)column_n;
|
||||||
table->ReorderColumnDstOrder = (ImGuiTableColumnIdx)dst_order;
|
table->ReorderColumnDstOrder = (ImGuiTableColumnIdx)-1;
|
||||||
|
dst_order = TableGetMaxDisplayOrderAllowed(table, src_order, dst_order);
|
||||||
|
if (dst_order != src_order)
|
||||||
|
table->ReorderColumnDstOrder = (ImGuiTableColumnIdx)dst_order;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust flags: default width mode + stretch columns are not allowed when auto extending
|
// Adjust flags: default width mode + stretch columns are not allowed when auto extending
|
||||||
|
|||||||
Reference in New Issue
Block a user