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()
| 3048 | // We cpu-clip text here so that all columns headers can be merged into a same draw call. |
| 3049 | // Note that because of how we cpu-clip and display sorting indicators, you _cannot_ use SameLine() after a TableHeader() |
| 3050 | void ImGui::TableHeader(const char* label) |
| 3051 | { |
| 3052 | ImGuiContext& g = *GImGui; |
| 3053 | ImGuiWindow* window = g.CurrentWindow; |
| 3054 | if (window->SkipItems) |
| 3055 | return; |
| 3056 | |
| 3057 | ImGuiTable* table = g.CurrentTable; |
| 3058 | IM_ASSERT(table != NULL && "Need to call TableHeader() after BeginTable()!"); |
| 3059 | IM_ASSERT(table->CurrentColumn != -1); |
| 3060 | const int column_n = table->CurrentColumn; |
| 3061 | ImGuiTableColumn* column = &table->Columns[column_n]; |
| 3062 | |
| 3063 | // Label |
| 3064 | if (label == NULL) |
| 3065 | label = ""; |
| 3066 | const char* label_end = FindRenderedTextEnd(label); |
| 3067 | ImVec2 label_size = CalcTextSize(label, label_end, true); |
| 3068 | ImVec2 label_pos = window->DC.CursorPos; |
| 3069 | |
| 3070 | // If we already got a row height, there's use that. |
| 3071 | // FIXME-TABLE: Padding problem if the correct outer-padding CellBgRect strays off our ClipRect? |
| 3072 | ImRect cell_r = TableGetCellBgRect(table, column_n); |
| 3073 | float label_height = ImMax(label_size.y, table->RowMinHeight - table->RowCellPaddingY * 2.0f); |
| 3074 | |
| 3075 | // Calculate ideal size for sort order arrow |
| 3076 | float w_arrow = 0.0f; |
| 3077 | float w_sort_text = 0.0f; |
| 3078 | bool sort_arrow = false; |
| 3079 | char sort_order_suf[4] = ""; |
| 3080 | const float ARROW_SCALE = 0.65f; |
| 3081 | if ((table->Flags & ImGuiTableFlags_Sortable) && !(column->Flags & ImGuiTableColumnFlags_NoSort)) |
| 3082 | { |
| 3083 | w_arrow = ImTrunc(g.FontSize * ARROW_SCALE + g.Style.FramePadding.x); |
| 3084 | if (column->SortOrder != -1) |
| 3085 | sort_arrow = true; |
| 3086 | if (column->SortOrder > 0) |
| 3087 | { |
| 3088 | ImFormatString(sort_order_suf, IM_ARRAYSIZE(sort_order_suf), "%d", column->SortOrder + 1); |
| 3089 | w_sort_text = g.Style.ItemInnerSpacing.x + CalcTextSize(sort_order_suf).x; |
| 3090 | } |
| 3091 | } |
| 3092 | |
| 3093 | // We feed our unclipped width to the column without writing on CursorMaxPos, so that column is still considered for merging. |
| 3094 | float max_pos_x = label_pos.x + label_size.x + w_sort_text + w_arrow; |
| 3095 | column->ContentMaxXHeadersUsed = ImMax(column->ContentMaxXHeadersUsed, sort_arrow ? cell_r.Max.x : ImMin(max_pos_x, cell_r.Max.x)); |
| 3096 | column->ContentMaxXHeadersIdeal = ImMax(column->ContentMaxXHeadersIdeal, max_pos_x); |
| 3097 | |
| 3098 | // Keep header highlighted when context menu is open. |
| 3099 | ImGuiID id = window->GetID(label); |
| 3100 | 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)); |
| 3101 | ItemSize(ImVec2(0.0f, label_height)); // Don't declare unclipped width, it'll be fed ContentMaxPosHeadersIdeal |
| 3102 | if (!ItemAdd(bb, id)) |
| 3103 | return; |
| 3104 | |
| 3105 | //GetForegroundDrawList()->AddRect(cell_r.Min, cell_r.Max, IM_COL32(255, 0, 0, 255)); // [DEBUG] |
| 3106 | //GetForegroundDrawList()->AddRect(bb.Min, bb.Max, IM_COL32(255, 0, 0, 255)); // [DEBUG] |
| 3107 |