MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / TableHeader

Method TableHeader

3rdparty/imgui/src/imgui_tables.cpp:3181–3319  ·  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

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

Callers

nothing calls this directly

Calls 7

ImMaxFunction · 0.85
ImTruncFunction · 0.85
ImFormatStringFunction · 0.85
ImMinFunction · 0.85
ItemSizeFunction · 0.85
ImVec2Function · 0.50
GetIDMethod · 0.45

Tested by

no test coverage detected