mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
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:
parent
5431cbd3f0
commit
f5eee210a0
@ -3940,6 +3940,54 @@ static void ShowDemoWindowTables()
|
|||||||
ImGui::TreePop();
|
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[] =
|
static const char* template_items_names[] =
|
||||||
{
|
{
|
||||||
"Banana", "Apple", "Cherry", "Watermelon", "Grapefruit", "Strawberry", "Mango",
|
"Banana", "Apple", "Cherry", "Watermelon", "Grapefruit", "Strawberry", "Mango",
|
||||||
|
@ -1898,6 +1898,7 @@ struct ImGuiTable
|
|||||||
ImS16 InstanceInteracted; // Mark which instance (generally 0) of the same ID is being interacted with
|
ImS16 InstanceInteracted; // Mark which instance (generally 0) of the same ID is being interacted with
|
||||||
float RowPosY1;
|
float RowPosY1;
|
||||||
float RowPosY2;
|
float RowPosY2;
|
||||||
|
float RowMinHeight; // Height submitted to TableNextRow()
|
||||||
float RowTextBaseline;
|
float RowTextBaseline;
|
||||||
ImGuiTableRowFlags RowFlags : 16; // Current row flags, see ImGuiTableRowFlags_
|
ImGuiTableRowFlags RowFlags : 16; // Current row flags, see ImGuiTableRowFlags_
|
||||||
ImGuiTableRowFlags LastRowFlags : 16;
|
ImGuiTableRowFlags LastRowFlags : 16;
|
||||||
|
@ -1419,7 +1419,7 @@ void ImGui::TableSetupColumn(const char* label, ImGuiTableColumnFlags flags,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Starts into the first cell of a new row
|
// Starts into the first cell of a new row
|
||||||
void ImGui::TableNextRow(ImGuiTableRowFlags row_flags, float min_row_height)
|
void ImGui::TableNextRow(ImGuiTableRowFlags row_flags, float row_min_height)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
ImGuiTable* table = g.CurrentTable;
|
ImGuiTable* table = g.CurrentTable;
|
||||||
@ -1431,12 +1431,13 @@ void ImGui::TableNextRow(ImGuiTableRowFlags row_flags, float min_row_height)
|
|||||||
|
|
||||||
table->LastRowFlags = table->RowFlags;
|
table->LastRowFlags = table->RowFlags;
|
||||||
table->RowFlags = row_flags;
|
table->RowFlags = row_flags;
|
||||||
|
table->RowMinHeight = row_min_height;
|
||||||
TableBeginRow(table);
|
TableBeginRow(table);
|
||||||
|
|
||||||
// We honor min_row_height requested by user, but cannot guarantee per-row maximum height,
|
// We honor min_row_height requested by user, but cannot guarantee per-row maximum height,
|
||||||
// because that would essentially require a unique clipping rectangle per-cell.
|
// because that would essentially require a unique clipping rectangle per-cell.
|
||||||
table->RowPosY2 += table->CellPaddingY * 2.0f;
|
table->RowPosY2 += table->CellPaddingY * 2.0f;
|
||||||
table->RowPosY2 = ImMax(table->RowPosY2, table->RowPosY1 + min_row_height);
|
table->RowPosY2 = ImMax(table->RowPosY2, table->RowPosY1 + row_min_height);
|
||||||
|
|
||||||
TableBeginCell(table, 0);
|
TableBeginCell(table, 0);
|
||||||
}
|
}
|
||||||
@ -1937,6 +1938,7 @@ void ImGui::TableAutoHeaders()
|
|||||||
|
|
||||||
// Emit a column header (text + optional sort order)
|
// 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.
|
// 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()
|
||||||
// FIXME-TABLE: Should hold a selection state.
|
// FIXME-TABLE: Should hold a selection state.
|
||||||
// FIXME-TABLE: Style confusion between CellPadding.y and FramePadding.y
|
// FIXME-TABLE: Style confusion between CellPadding.y and FramePadding.y
|
||||||
void ImGui::TableHeader(const char* label)
|
void ImGui::TableHeader(const char* label)
|
||||||
@ -1961,7 +1963,7 @@ void ImGui::TableHeader(const char* label)
|
|||||||
|
|
||||||
// If we already got a row height, there's use that.
|
// If we already got a row height, there's use that.
|
||||||
ImRect cell_r = TableGetCellRect();
|
ImRect cell_r = TableGetCellRect();
|
||||||
float label_height = ImMax(label_size.y, cell_r.GetHeight() - g.Style.CellPadding.y * 2.0f);
|
float label_height = ImMax(label_size.y, table->RowMinHeight - g.Style.CellPadding.y * 2.0f);
|
||||||
|
|
||||||
//GetForegroundDrawList()->AddRect(cell_r.Min, cell_r.Max, IM_COL32(255, 0, 0, 255)); // [DEBUG]
|
//GetForegroundDrawList()->AddRect(cell_r.Min, cell_r.Max, IM_COL32(255, 0, 0, 255)); // [DEBUG]
|
||||||
ImRect work_r = cell_r;
|
ImRect work_r = cell_r;
|
||||||
|
Loading…
Reference in New Issue
Block a user