MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / TableHeader

Method TableHeader

extern/imgui/imgui_tables.cpp:2877–3014  ·  view source on GitHub ↗

Emit a column header (text + optional sort order) We cpu-clip text here so that all columns headers can be merged into a same draw call. Note that because of how we cpu-clip and display sorting indicators, you _cannot_ use SameLine() after a TableHeader()

Source from the content-addressed store, hash-verified

2875// We cpu-clip text here so that all columns headers can be merged into a same draw call.
2876// Note that because of how we cpu-clip and display sorting indicators, you _cannot_ use SameLine() after a TableHeader()
2877void ImGui::TableHeader(const char* label)
2878{
2879 ImGuiContext& g = *GImGui;
2880 ImGuiWindow* window = g.CurrentWindow;
2881 if (window->SkipItems)
2882 return;
2883
2884 ImGuiTable* table = g.CurrentTable;
2885 IM_ASSERT(table != NULL && "Need to call TableHeader() after BeginTable()!");
2886 IM_ASSERT(table->CurrentColumn != -1);
2887 const int column_n = table->CurrentColumn;
2888 ImGuiTableColumn* column = &table->Columns[column_n];
2889
2890 // Label
2891 if (label == NULL)
2892 label = "";
2893 const char* label_end = FindRenderedTextEnd(label);
2894 ImVec2 label_size = CalcTextSize(label, label_end, true);
2895 ImVec2 label_pos = window->DC.CursorPos;
2896
2897 // If we already got a row height, there's use that.
2898 // FIXME-TABLE: Padding problem if the correct outer-padding CellBgRect strays off our ClipRect?
2899 ImRect cell_r = TableGetCellBgRect(table, column_n);
2900 float label_height = ImMax(label_size.y, table->RowMinHeight - table->CellPaddingY * 2.0f);
2901
2902 // Calculate ideal size for sort order arrow
2903 float w_arrow = 0.0f;
2904 float w_sort_text = 0.0f;
2905 char sort_order_suf[4] = "";
2906 const float ARROW_SCALE = 0.65f;
2907 if ((table->Flags & ImGuiTableFlags_Sortable) && !(column->Flags & ImGuiTableColumnFlags_NoSort))
2908 {
2909 w_arrow = ImFloor(g.FontSize * ARROW_SCALE + g.Style.FramePadding.x);
2910 if (column->SortOrder > 0)
2911 {
2912 ImFormatString(sort_order_suf, IM_ARRAYSIZE(sort_order_suf), "%d", column->SortOrder + 1);
2913 w_sort_text = g.Style.ItemInnerSpacing.x + CalcTextSize(sort_order_suf).x;
2914 }
2915 }
2916
2917 // We feed our unclipped width to the column without writing on CursorMaxPos, so that column is still considering for merging.
2918 float max_pos_x = label_pos.x + label_size.x + w_sort_text + w_arrow;
2919 column->ContentMaxXHeadersUsed = ImMax(column->ContentMaxXHeadersUsed, column->WorkMaxX);
2920 column->ContentMaxXHeadersIdeal = ImMax(column->ContentMaxXHeadersIdeal, max_pos_x);
2921
2922 // Keep header highlighted when context menu is open.
2923 const bool selected = (table->IsContextPopupOpen && table->ContextPopupColumn == column_n && table->InstanceInteracted == table->InstanceCurrent);
2924 ImGuiID id = window->GetID(label);
2925 ImRect bb(cell_r.Min.x, cell_r.Min.y, cell_r.Max.x, ImMax(cell_r.Max.y, cell_r.Min.y + label_height + g.Style.CellPadding.y * 2.0f));
2926 ItemSize(ImVec2(0.0f, label_height)); // Don't declare unclipped width, it'll be fed ContentMaxPosHeadersIdeal
2927 if (!ItemAdd(bb, id))
2928 return;
2929
2930 //GetForegroundDrawList()->AddRect(cell_r.Min, cell_r.Max, IM_COL32(255, 0, 0, 255)); // [DEBUG]
2931 //GetForegroundDrawList()->AddRect(bb.Min, bb.Max, IM_COL32(255, 0, 0, 255)); // [DEBUG]
2932
2933 // Using AllowItemOverlap mode because we cover the whole cell, and we want user to be able to submit subsequent items.
2934 bool hovered, held;

Callers

nothing calls this directly

Calls 6

ImMaxFunction · 0.85
ImFloorFunction · 0.85
ImFormatStringFunction · 0.85
ItemSizeFunction · 0.85
ImVec2Function · 0.85
GetIDMethod · 0.80

Tested by

no test coverage detected