MCPcopy Create free account
hub / github.com/RenderKit/embree / TableHeader

Method TableHeader

tutorials/common/imgui/imgui_tables.cpp:2878–3015  ·  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

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