Tables: TableHeader() uses provided row min header rather than incremental one to allow multi-item multi-line in header cells. Demo TableHeader() - will caveat, comments.

This commit is contained in:
omar
2020-01-20 12:41:23 +01:00
committed by ocornut
parent 5431cbd3f0
commit f5eee210a0
3 changed files with 54 additions and 3 deletions

View File

@ -3940,6 +3940,54 @@ static void ShowDemoWindowTables()
ImGui::TreePop();
}
// Demonstrate using TableHeader() calls instead of TableAutoHeaders()
// FIXME-TABLE: Currently this doesn't get us feature-parity with TableAutoHeaders(), e.g. missing context menu. Tables API needs some work!
if (open_action != -1)
ImGui::SetNextItemOpen(open_action != 0);
if (ImGui::TreeNode("Custom headers"))
{
const int COLUMNS_COUNT = 3;
if (ImGui::BeginTable("##table1", COLUMNS_COUNT, ImGuiTableFlags_Borders | ImGuiTableFlags_Reorderable))
{
ImGui::TableSetupColumn("Apricot");
ImGui::TableSetupColumn("Banana");
ImGui::TableSetupColumn("Cherry");
// Dummy entire-column selection storage
// FIXME: It would be nice to actually demonstrate full-featured selection using those checkbox.
static bool column_selected[3] = {};
// Instead of calling TableAutoHeaders() we'll submit custom headers ourselves
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
for (int column = 0; column < COLUMNS_COUNT; column++)
{
ImGui::TableSetColumnIndex(column);
const char* column_name = ImGui::TableGetColumnName(column); // Retrieve name passed to TableSetupColumn()
ImGui::PushID(column);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
ImGui::Checkbox("##checkall", &column_selected[column]);
ImGui::PopStyleVar();
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
ImGui::TableHeader(column_name);
ImGui::PopID();
}
for (int row = 0; row < 5; row++)
{
ImGui::TableNextRow();
for (int column = 0; column < 3; column++)
{
char buf[32];
sprintf(buf, "Cell %d,%d", row, column);
ImGui::TableSetColumnIndex(column);
ImGui::Selectable(buf, column_selected[column]);
}
}
ImGui::EndTable();
}
ImGui::TreePop();
}
static const char* template_items_names[] =
{
"Banana", "Apple", "Cherry", "Watermelon", "Grapefruit", "Strawberry", "Mango",