See "COLUMN SIZING POLICIES" comments at the top of this file If (init_width_or_weight <= 0.0f) it is ignored
| 1446 | // See "COLUMN SIZING POLICIES" comments at the top of this file |
| 1447 | // If (init_width_or_weight <= 0.0f) it is ignored |
| 1448 | void ImGui::TableSetupColumn(const char* label, ImGuiTableColumnFlags flags, float init_width_or_weight, ImGuiID user_id) |
| 1449 | { |
| 1450 | ImGuiContext& g = *GImGui; |
| 1451 | ImGuiTable* table = g.CurrentTable; |
| 1452 | IM_ASSERT(table != NULL && "Need to call TableSetupColumn() after BeginTable()!"); |
| 1453 | IM_ASSERT(table->IsLayoutLocked == false && "Need to call call TableSetupColumn() before first row!"); |
| 1454 | IM_ASSERT((flags & ImGuiTableColumnFlags_StatusMask_) == 0 && "Illegal to pass StatusMask values to TableSetupColumn()"); |
| 1455 | if (table->DeclColumnsCount >= table->ColumnsCount) |
| 1456 | { |
| 1457 | IM_ASSERT_USER_ERROR(table->DeclColumnsCount < table->ColumnsCount, "Called TableSetupColumn() too many times!"); |
| 1458 | return; |
| 1459 | } |
| 1460 | |
| 1461 | ImGuiTableColumn* column = &table->Columns[table->DeclColumnsCount]; |
| 1462 | table->DeclColumnsCount++; |
| 1463 | |
| 1464 | // Assert when passing a width or weight if policy is entirely left to default, to avoid storing width into weight and vice-versa. |
| 1465 | // Give a grace to users of ImGuiTableFlags_ScrollX. |
| 1466 | if (table->IsDefaultSizingPolicy && (flags & ImGuiTableColumnFlags_WidthMask_) == 0 && (flags & ImGuiTableFlags_ScrollX) == 0) |
| 1467 | IM_ASSERT(init_width_or_weight <= 0.0f && "Can only specify width/weight if sizing policy is set explicitly in either Table or Column."); |
| 1468 | |
| 1469 | // When passing a width automatically enforce WidthFixed policy |
| 1470 | // (whereas TableSetupColumnFlags would default to WidthAuto if table is not Resizable) |
| 1471 | if ((flags & ImGuiTableColumnFlags_WidthMask_) == 0 && init_width_or_weight > 0.0f) |
| 1472 | if ((table->Flags & ImGuiTableFlags_SizingMask_) == ImGuiTableFlags_SizingFixedFit || (table->Flags & ImGuiTableFlags_SizingMask_) == ImGuiTableFlags_SizingFixedSame) |
| 1473 | flags |= ImGuiTableColumnFlags_WidthFixed; |
| 1474 | |
| 1475 | TableSetupColumnFlags(table, column, flags); |
| 1476 | column->UserID = user_id; |
| 1477 | flags = column->Flags; |
| 1478 | |
| 1479 | // Initialize defaults |
| 1480 | column->InitStretchWeightOrWidth = init_width_or_weight; |
| 1481 | if (table->IsInitializing) |
| 1482 | { |
| 1483 | // Init width or weight |
| 1484 | if (column->WidthRequest < 0.0f && column->StretchWeight < 0.0f) |
| 1485 | { |
| 1486 | if ((flags & ImGuiTableColumnFlags_WidthFixed) && init_width_or_weight > 0.0f) |
| 1487 | column->WidthRequest = init_width_or_weight; |
| 1488 | if (flags & ImGuiTableColumnFlags_WidthStretch) |
| 1489 | column->StretchWeight = (init_width_or_weight > 0.0f) ? init_width_or_weight : -1.0f; |
| 1490 | |
| 1491 | // Disable auto-fit if an explicit width/weight has been specified |
| 1492 | if (init_width_or_weight > 0.0f) |
| 1493 | column->AutoFitQueue = 0x00; |
| 1494 | } |
| 1495 | |
| 1496 | // Init default visibility/sort state |
| 1497 | if ((flags & ImGuiTableColumnFlags_DefaultHide) && (table->SettingsLoadedFlags & ImGuiTableFlags_Hideable) == 0) |
| 1498 | column->IsUserEnabled = column->IsUserEnabledNextFrame = false; |
| 1499 | if (flags & ImGuiTableColumnFlags_DefaultSort && (table->SettingsLoadedFlags & ImGuiTableFlags_Sortable) == 0) |
| 1500 | { |
| 1501 | column->SortOrder = 0; // Multiple columns using _DefaultSort will be reassigned unique SortOrder values when building the sort specs. |
| 1502 | column->SortDirection = (column->Flags & ImGuiTableColumnFlags_PreferSortDescending) ? (ImS8)ImGuiSortDirection_Descending : (ImU8)(ImGuiSortDirection_Ascending); |
| 1503 | } |
| 1504 | } |
| 1505 |
nothing calls this directly
no test coverage detected