See "COLUMNS SIZING POLICIES" comments at the top of this file If (init_width_or_weight <= 0.0f) it is ignored
| 1638 | // See "COLUMNS SIZING POLICIES" comments at the top of this file |
| 1639 | // If (init_width_or_weight <= 0.0f) it is ignored |
| 1640 | void ImGui::TableSetupColumn(const char* label, ImGuiTableColumnFlags flags, float init_width_or_weight, ImGuiID user_id) |
| 1641 | { |
| 1642 | ImGuiContext& g = *GImGui; |
| 1643 | ImGuiTable* table = g.CurrentTable; |
| 1644 | IM_ASSERT_USER_ERROR_RET(table != NULL, "Call should only be done while in BeginTable() scope!"); |
| 1645 | IM_ASSERT_USER_ERROR_RET(table->DeclColumnsCount < table->ColumnsCount, "TableSetupColumn(): called too many times!"); |
| 1646 | IM_ASSERT_USER_ERROR_RET(table->IsLayoutLocked == false, "TableSetupColumn(): need to call before first row!"); |
| 1647 | IM_ASSERT((flags & ImGuiTableColumnFlags_StatusMask_) == 0 && "Illegal to pass StatusMask values to TableSetupColumn()"); |
| 1648 | |
| 1649 | ImGuiTableColumn* column = &table->Columns[table->DeclColumnsCount]; |
| 1650 | table->DeclColumnsCount++; |
| 1651 | |
| 1652 | // Assert when passing a width or weight if policy is entirely left to default, to avoid storing width into weight and vice-versa. |
| 1653 | // Give a grace to users of ImGuiTableFlags_ScrollX. |
| 1654 | if (table->IsDefaultSizingPolicy && (flags & ImGuiTableColumnFlags_WidthMask_) == 0 && (flags & ImGuiTableFlags_ScrollX) == 0) |
| 1655 | IM_ASSERT_USER_ERROR_RET(init_width_or_weight <= 0.0f, "TableSetupColumn(): can only specify width/weight if sizing policy is set explicitly in either Table or Column."); |
| 1656 | |
| 1657 | // When passing a width automatically enforce WidthFixed policy |
| 1658 | // (whereas TableSetupColumnFlags would default to WidthAuto if table is not resizable) |
| 1659 | if ((flags & ImGuiTableColumnFlags_WidthMask_) == 0 && init_width_or_weight > 0.0f) |
| 1660 | if ((table->Flags & ImGuiTableFlags_SizingMask_) == ImGuiTableFlags_SizingFixedFit || (table->Flags & ImGuiTableFlags_SizingMask_) == ImGuiTableFlags_SizingFixedSame) |
| 1661 | flags |= ImGuiTableColumnFlags_WidthFixed; |
| 1662 | if (flags & ImGuiTableColumnFlags_AngledHeader) |
| 1663 | { |
| 1664 | flags |= ImGuiTableColumnFlags_NoHeaderLabel; |
| 1665 | table->AngledHeadersCount++; |
| 1666 | } |
| 1667 | |
| 1668 | TableSetupColumnFlags(table, column, flags); |
| 1669 | column->UserID = user_id; |
| 1670 | flags = column->Flags; |
| 1671 | |
| 1672 | // Initialize defaults |
| 1673 | column->InitStretchWeightOrWidth = init_width_or_weight; |
| 1674 | if (table->IsInitializing) |
| 1675 | { |
| 1676 | ImGuiTableFlags init_flags = ~table->SettingsLoadedFlags; |
| 1677 | if (column->WidthRequest < 0.0f && column->StretchWeight < 0.0f) |
| 1678 | init_flags |= ImGuiTableFlags_Resizable; |
| 1679 | TableInitColumnDefaults(table, column, init_flags); |
| 1680 | } |
| 1681 | |
| 1682 | // Store name (append with zero-terminator in contiguous buffer) |
| 1683 | // FIXME: If we recorded the number of \n in names we could compute header row height |
| 1684 | column->NameOffset = -1; |
| 1685 | if (label != NULL && label[0] != 0) |
| 1686 | { |
| 1687 | column->NameOffset = (ImS16)table->ColumnsNames.size(); |
| 1688 | table->ColumnsNames.append(label, label + ImStrlen(label) + 1); |
| 1689 | } |
| 1690 | } |
| 1691 | |
| 1692 | // [Public] |
| 1693 | void ImGui::TableSetupScrollFreeze(int columns, int rows) |
nothing calls this directly
no test coverage detected