Made data table header a const char* to avoid unnecessary allocations.

This commit is contained in:
Patrick Wuttke 2025-09-20 14:26:18 +02:00
parent d3b56d3fd0
commit 6657606e81

View File

@ -73,7 +73,7 @@ struct DataTableColumn
using renderer_t = std::function<void(const CellRendererArgs&)>; using renderer_t = std::function<void(const CellRendererArgs&)>;
using comparator_t = std::function<bool(const TObject&, const TObject&)>; using comparator_t = std::function<bool(const TObject&, const TObject&)>;
std::string header; const char* header;
renderer_t renderer; renderer_t renderer;
comparator_t comparator; comparator_t comparator;
}; };
@ -85,7 +85,7 @@ struct DataTableOptions
ImGuiTableFlags tableFlags = ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Sortable | ImGuiTableFlags_ScrollY; ImGuiTableFlags tableFlags = ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Sortable | ImGuiTableFlags_ScrollY;
}; };
template<typename TData, typename TObject> template<typename TObject,typename TData>
inline void DataTable(const char* strId, const DataTableOptions<TObject>& options, const TData& data, DataTableState& state, ImVec2 outerSize = {}) inline void DataTable(const char* strId, const DataTableOptions<TObject>& options, const TData& data, DataTableState& state, ImVec2 outerSize = {})
{ {
if (outerSize.y <= 0.f) { if (outerSize.y <= 0.f) {
@ -103,7 +103,7 @@ inline void DataTable(const char* strId, const DataTableOptions<TObject>& option
if (!column.comparator) { if (!column.comparator) {
flags |= ImGuiTableColumnFlags_NoSort; flags |= ImGuiTableColumnFlags_NoSort;
} }
ImGui::TableSetupColumn(column.header.c_str(), flags); ImGui::TableSetupColumn(column.header, flags);
} }
ImGui::TableSetupScrollFreeze(0, 1); ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableHeadersRow(); ImGui::TableHeadersRow();