MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / TableHeader

Method TableHeader

imgui_tiny_app/imgui/imgui_tables.cpp:3162–3298  ·  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

3160// We cpu-clip text here so that all columns headers can be merged into a same draw call.
3161// Note that because of how we cpu-clip and display sorting indicators, you _cannot_ use SameLine() after a TableHeader()
3162void ImGui::TableHeader(const char* label)
3163{
3164 ImGuiContext& g = *GImGui;
3165 ImGuiWindow* window = g.CurrentWindow;
3166 if (window->SkipItems)
3167 return;
3168
3169 ImGuiTable* table = g.CurrentTable;
3170 IM_ASSERT_USER_ERROR_RET(table != NULL, "Call should only be done while in BeginTable() scope!");
3171 IM_ASSERT(table->CurrentColumn != -1);
3172 const int column_n = table->CurrentColumn;
3173 ImGuiTableColumn* column = &table->Columns[column_n];
3174
3175 // Label
3176 if (label == NULL)
3177 label = "";
3178 const char* label_end = FindRenderedTextEnd(label);
3179 ImVec2 label_size = CalcTextSize(label, label_end, true);
3180 ImVec2 label_pos = window->DC.CursorPos;
3181
3182 // If we already got a row height, there's use that.
3183 // FIXME-TABLE: Padding problem if the correct outer-padding CellBgRect strays off our ClipRect?
3184 ImRect cell_r = TableGetCellBgRect(table, column_n);
3185 float label_height = ImMax(label_size.y, table->RowMinHeight - table->RowCellPaddingY * 2.0f);
3186
3187 // Calculate ideal size for sort order arrow
3188 float w_arrow = 0.0f;
3189 float w_sort_text = 0.0f;
3190 bool sort_arrow = false;
3191 char sort_order_suf[4] = "";
3192 const float ARROW_SCALE = 0.65f;
3193 if ((table->Flags & ImGuiTableFlags_Sortable) && !(column->Flags & ImGuiTableColumnFlags_NoSort))
3194 {
3195 w_arrow = ImTrunc(g.FontSize * ARROW_SCALE + g.Style.FramePadding.x);
3196 if (column->SortOrder != -1)
3197 sort_arrow = true;
3198 if (column->SortOrder > 0)
3199 {
3200 ImFormatString(sort_order_suf, IM_COUNTOF(sort_order_suf), "%d", column->SortOrder + 1);
3201 w_sort_text = g.Style.ItemInnerSpacing.x + CalcTextSize(sort_order_suf).x;
3202 }
3203 }
3204
3205 // We feed our unclipped width to the column without writing on CursorMaxPos, so that column is still considered for merging.
3206 float max_pos_x = label_pos.x + label_size.x + w_sort_text + w_arrow;
3207 column->ContentMaxXHeadersUsed = ImMax(column->ContentMaxXHeadersUsed, sort_arrow ? cell_r.Max.x : ImMin(max_pos_x, cell_r.Max.x));
3208 column->ContentMaxXHeadersIdeal = ImMax(column->ContentMaxXHeadersIdeal, max_pos_x);
3209
3210 // Keep header highlighted when context menu is open.
3211 ImGuiID id = window->GetID(label);
3212 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));
3213 ItemSize(ImVec2(0.0f, label_height)); // Don't declare unclipped width, it'll be fed ContentMaxPosHeadersIdeal
3214 if (!ItemAdd(bb, id))
3215 return;
3216
3217 //GetForegroundDrawList()->AddRect(cell_r.Min, cell_r.Max, IM_COL32(255, 0, 0, 255)); // [DEBUG]
3218 //GetForegroundDrawList()->AddRect(bb.Min, bb.Max, IM_COL32(255, 0, 0, 255)); // [DEBUG]
3219

Callers

nothing calls this directly

Calls 8

ImMaxFunction · 0.85
ImTruncFunction · 0.85
ImFormatStringFunction · 0.85
ImMinFunction · 0.85
ItemSizeFunction · 0.85
ImVec2Function · 0.85
PopStyleColorFunction · 0.85
GetIDMethod · 0.80

Tested by

no test coverage detected