See "COLUMNS SIZING POLICIES" comments at the top of this file If (init_width_or_weight <= 0.0f) it is ignored
| 1597 | // See "COLUMNS SIZING POLICIES" comments at the top of this file |
| 1598 | // If (init_width_or_weight <= 0.0f) it is ignored |
| 1599 | void ImGui::TableSetupColumn(const char* label, ImGuiTableColumnFlags flags, float init_width_or_weight, ImGuiID user_id) |
| 1600 | { |
| 1601 | ImGuiContext& g = *GImGui; |
| 1602 | ImGuiTable* table = g.CurrentTable; |
| 1603 | if (table == NULL) |
| 1604 | { |
| 1605 | IM_ASSERT_USER_ERROR(table != NULL, "Call should only be done while in BeginTable() scope!"); |
| 1606 | return; |
| 1607 | } |
| 1608 | IM_ASSERT(table->IsLayoutLocked == false && "Need to call TableSetupColumn() before first row!"); |
| 1609 | IM_ASSERT((flags & ImGuiTableColumnFlags_StatusMask_) == 0 && "Illegal to pass StatusMask values to TableSetupColumn()"); |
| 1610 | if (table->DeclColumnsCount >= table->ColumnsCount) |
| 1611 | { |
| 1612 | IM_ASSERT_USER_ERROR(table->DeclColumnsCount < table->ColumnsCount, "Called TableSetupColumn() too many times!"); |
| 1613 | return; |
| 1614 | } |
| 1615 | |
| 1616 | ImGuiTableColumn* column = &table->Columns[table->DeclColumnsCount]; |
| 1617 | table->DeclColumnsCount++; |
| 1618 | |
| 1619 | // Assert when passing a width or weight if policy is entirely left to default, to avoid storing width into weight and vice-versa. |
| 1620 | // Give a grace to users of ImGuiTableFlags_ScrollX. |
| 1621 | if (table->IsDefaultSizingPolicy && (flags & ImGuiTableColumnFlags_WidthMask_) == 0 && (flags & ImGuiTableFlags_ScrollX) == 0) |
| 1622 | IM_ASSERT(init_width_or_weight <= 0.0f && "Can only specify width/weight if sizing policy is set explicitly in either Table or Column."); |
| 1623 | |
| 1624 | // When passing a width automatically enforce WidthFixed policy |
| 1625 | // (whereas TableSetupColumnFlags would default to WidthAuto if table is not resizable) |
| 1626 | if ((flags & ImGuiTableColumnFlags_WidthMask_) == 0 && init_width_or_weight > 0.0f) |
| 1627 | if ((table->Flags & ImGuiTableFlags_SizingMask_) == ImGuiTableFlags_SizingFixedFit || (table->Flags & ImGuiTableFlags_SizingMask_) == ImGuiTableFlags_SizingFixedSame) |
| 1628 | flags |= ImGuiTableColumnFlags_WidthFixed; |
| 1629 | if (flags & ImGuiTableColumnFlags_AngledHeader) |
| 1630 | { |
| 1631 | flags |= ImGuiTableColumnFlags_NoHeaderLabel; |
| 1632 | table->AngledHeadersCount++; |
| 1633 | } |
| 1634 | |
| 1635 | TableSetupColumnFlags(table, column, flags); |
| 1636 | column->UserID = user_id; |
| 1637 | flags = column->Flags; |
| 1638 | |
| 1639 | // Initialize defaults |
| 1640 | column->InitStretchWeightOrWidth = init_width_or_weight; |
| 1641 | if (table->IsInitializing) |
| 1642 | { |
| 1643 | ImGuiTableFlags init_flags = ~table->SettingsLoadedFlags; |
| 1644 | if (column->WidthRequest < 0.0f && column->StretchWeight < 0.0f) |
| 1645 | init_flags |= ImGuiTableFlags_Resizable; |
| 1646 | TableInitColumnDefaults(table, column, init_flags); |
| 1647 | } |
| 1648 | |
| 1649 | // Store name (append with zero-terminator in contiguous buffer) |
| 1650 | // FIXME: If we recorded the number of \n in names we could compute header row height |
| 1651 | column->NameOffset = -1; |
| 1652 | if (label != NULL && label[0] != 0) |
| 1653 | { |
| 1654 | column->NameOffset = (ImS16)table->ColumnsNames.size(); |
| 1655 | table->ColumnsNames.append(label, label + ImStrlen(label) + 1); |
| 1656 | } |
nothing calls this directly
no test coverage detected