Tables: Comments, better assert, moved some internal flags out of the way.

This commit is contained in:
omar
2019-12-29 17:10:42 +01:00
committed by ocornut
parent 0c3d7bb154
commit 81453ac42c
3 changed files with 43 additions and 30 deletions

View File

@ -106,6 +106,7 @@ inline ImGuiTableFlags TableFixFlags(ImGuiTableFlags flags)
flags |= ImGuiTableFlags_BordersV;
// Adjust flags: disable top rows freezing if there's no scrolling
// In theory we could want to assert if ScrollFreeze was set without the corresponding scroll flag, but that would hinder demos.
if ((flags & ImGuiTableFlags_ScrollX) == 0)
flags &= ~ImGuiTableFlags_ScrollFreezeColumnsMask_;
if ((flags & ImGuiTableFlags_ScrollY) == 0)
@ -154,6 +155,8 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
{
ImGuiContext& g = *GImGui;
ImGuiWindow* outer_window = GetCurrentWindow();
// Sanity checks
IM_ASSERT(columns_count > 0 && columns_count < IMGUI_TABLE_MAX_COLUMNS && "Only 0..63 columns allowed!");
if (flags & ImGuiTableFlags_ScrollX)
IM_ASSERT(inner_width >= 0.0f);
@ -840,7 +843,7 @@ void ImGui::EndTable()
{
ImGuiContext& g = *GImGui;
ImGuiTable* table = g.CurrentTable;
IM_ASSERT(table != NULL);
IM_ASSERT(table != NULL && "Only call EndTable() is BeginTable() returns true!");
const ImGuiTableFlags flags = table->Flags;
ImGuiWindow* inner_window = table->InnerWindow;
@ -1292,8 +1295,8 @@ void ImGui::TableSetupColumn(const char* label, ImGuiTableColumnFlags flags,
{
ImGuiContext& g = *GImGui;
ImGuiTable* table = g.CurrentTable;
IM_ASSERT(table != NULL && "Can only call TableSetupColumn() after BeginTable()!");
IM_ASSERT(!table->IsLayoutLocked && "Can only call TableSetupColumn() before first row!");
IM_ASSERT(table != NULL && "Need to call TableSetupColumn() after BeginTable()!");
IM_ASSERT(!table->IsLayoutLocked && "Need to call call TableSetupColumn() before first row!");
IM_ASSERT(table->DeclColumnsCount >= 0 && table->DeclColumnsCount < table->ColumnsCount && "Called TableSetupColumn() too many times!");
ImGuiTableColumn* column = &table->Columns[table->DeclColumnsCount];
@ -1505,7 +1508,8 @@ void ImGui::TableEndRow(ImGuiTable* table)
table->IsInsideRow = false;
}
// [Internal] This is called a lot, so we need to be mindful of unnecessary overhead!
// [Internal] Called by TableNextRow()TableNextCell()!
// This is called a lot, so we need to be mindful of unnecessary overhead.
void ImGui::TableBeginCell(ImGuiTable* table, int column_no)
{
table->CurrentColumn = column_no;
@ -1550,7 +1554,7 @@ void ImGui::TableBeginCell(ImGuiTable* table, int column_no)
}
}
// [Internal]
// [Internal] Called by TableNextRow()TableNextCell()!
void ImGui::TableEndCell(ImGuiTable* table)
{
ImGuiTableColumn* column = &table->Columns[table->CurrentColumn];
@ -1684,6 +1688,7 @@ void ImGui::PopTableBackground()
PopClipRect();
}
// Output context menu into current window (generally a popup)
// FIXME-TABLE: Ideally this should be writable by the user. Full programmatic access to that data?
void ImGui::TableDrawContextMenu(ImGuiTable* table, int selected_column_n)
{
@ -1751,7 +1756,7 @@ void ImGui::TableDrawContextMenu(ImGuiTable* table, int selected_column_n)
}
}
// This is a helper to output headers based on the column names declared in TableSetupColumn()
// This is a helper to output TableHeader() calls based on the column names declared in TableSetupColumn().
// The intent is that advanced users would not need to use this helper and may create their own.
void ImGui::TableAutoHeaders()
{
@ -1761,7 +1766,8 @@ void ImGui::TableAutoHeaders()
return;
ImGuiTable* table = g.CurrentTable;
IM_ASSERT(table && table->CurrentRow == -1);
IM_ASSERT(table != NULL && "Need to call TableAutoHeaders() after BeginTable()!");
IM_ASSERT(table->CurrentRow == -1);
int open_context_popup = INT_MAX;
@ -1852,6 +1858,7 @@ void ImGui::TableHeader(const char* label)
return;
ImGuiTable* table = g.CurrentTable;
IM_ASSERT(table != NULL && "Need to call TableAutoHeaders() after BeginTable()!");
IM_ASSERT(table->CurrentColumn != -1);
const int column_n = table->CurrentColumn;
ImGuiTableColumn* column = &table->Columns[column_n];