Skip to content

Commit 984c4cb

Browse files
committed
Tables: distinguishing per-column IsVisible from IsRequestOutput which is returned to user. Clarified clipping rules/requirements. Comments.
1 parent f70bf69 commit 984c4cb

File tree

4 files changed

+125
-67
lines changed

4 files changed

+125
-67
lines changed

imgui.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ namespace ImGui
669669
// TableNextColumn() will automatically wrap-around into the next row if needed.
670670
// - IMPORTANT: Comparatively to the old Columns() API, we need to call TableNextColumn() for the first column!
671671
// - Both TableSetColumnIndex() and TableNextColumn() return false when the column is not visible, so you can
672-
// skip submitting the contents of a cell BUT ONLY if you know the contents is not going to alter row height.
672+
// skip submitting the contents of a cell BUT ONLY if you know it is not going to contribute to row height.
673673
// In many situations, you may skip submitting contents for every columns but one (e.g. the first one).
674674
// - Summary of possible call flow:
675675
// ----------------------------------------------------------------------------------------------------------
@@ -1055,7 +1055,7 @@ enum ImGuiTableFlags_
10551055
ImGuiTableFlags_None = 0,
10561056
ImGuiTableFlags_Resizable = 1 << 0, // Allow resizing columns.
10571057
ImGuiTableFlags_Reorderable = 1 << 1, // Allow reordering columns in header row (need calling TableSetupColumn() + TableHeadersRow() to display headers)
1058-
ImGuiTableFlags_Hideable = 1 << 2, // Allow hiding columns in context menu.
1058+
ImGuiTableFlags_Hideable = 1 << 2, // Allow hiding/disabling columns in context menu.
10591059
ImGuiTableFlags_Sortable = 1 << 3, // Allow sorting on one column (sort_specs_count will always be == 1). Call TableGetSortSpecs() to obtain sort specs.
10601060
ImGuiTableFlags_MultiSortable = 1 << 4, // Allow sorting on multiple columns by holding Shift (sort_specs_count may be > 1). Call TableGetSortSpecs() to obtain sort specs.
10611061
ImGuiTableFlags_NoSavedSettings = 1 << 5, // Disable persisting columns order, width and sort settings in the .ini file.
@@ -1095,14 +1095,14 @@ enum ImGuiTableFlags_
10951095
enum ImGuiTableColumnFlags_
10961096
{
10971097
ImGuiTableColumnFlags_None = 0,
1098-
ImGuiTableColumnFlags_DefaultHide = 1 << 0, // Default as a hidden column.
1098+
ImGuiTableColumnFlags_DefaultHide = 1 << 0, // Default as a hidden/disabled column.
10991099
ImGuiTableColumnFlags_DefaultSort = 1 << 1, // Default as a sorting column.
11001100
ImGuiTableColumnFlags_WidthStretch = 1 << 2, // Column will stretch. Preferable with horizontal scrolling disabled (default if table sizing policy is _ColumnsWidthStretch).
11011101
ImGuiTableColumnFlags_WidthFixed = 1 << 3, // Column will not stretch. Preferable with horizontal scrolling enabled (default if table sizing policy is _ColumnsWidthFixed and table is resizable).
11021102
ImGuiTableColumnFlags_WidthAutoResize = 1 << 4, // Column will not stretch and keep resizing based on submitted contents (default if table sizing policy is _ColumnsWidthFixed and table is not resizable).
11031103
ImGuiTableColumnFlags_NoResize = 1 << 5, // Disable manual resizing.
11041104
ImGuiTableColumnFlags_NoReorder = 1 << 6, // Disable manual reordering this column, this will also prevent other columns from crossing over this column.
1105-
ImGuiTableColumnFlags_NoHide = 1 << 7, // Disable ability to hide this column.
1105+
ImGuiTableColumnFlags_NoHide = 1 << 7, // Disable ability to hide/disable this column.
11061106
ImGuiTableColumnFlags_NoClip = 1 << 8, // Disable clipping for this column (all NoClip columns will render in a same draw command).
11071107
ImGuiTableColumnFlags_NoSort = 1 << 9, // Disable ability to sort on this field (even if ImGuiTableFlags_Sortable is set on the table).
11081108
ImGuiTableColumnFlags_NoSortAscending = 1 << 10, // Disable ability to sort in the ascending direction.

imgui_demo.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3518,9 +3518,7 @@ static void ShowDemoWindowTables()
35183518
ImGui::TableNextRow();
35193519
for (int column = 0; column < 3; column++)
35203520
{
3521-
if (!ImGui::TableSetColumnIndex(column))
3522-
continue;
3523-
3521+
ImGui::TableSetColumnIndex(column);
35243522
char buf[32];
35253523
sprintf(buf, "Hello %d,%d", column, row);
35263524
if (contents_type == CT_Text)
@@ -3861,20 +3859,22 @@ static void ShowDemoWindowTables()
38613859
{
38623860
ImGui::TableSetupScrollFreeze(freeze_cols, freeze_rows);
38633861
ImGui::TableSetupColumn("Line #", ImGuiTableColumnFlags_NoHide); // Make the first column not hideable to match our use of TableSetupScrollFreeze()
3864-
ImGui::TableSetupColumn("One", ImGuiTableColumnFlags_None);
3865-
ImGui::TableSetupColumn("Two", ImGuiTableColumnFlags_None);
3866-
ImGui::TableSetupColumn("Three", ImGuiTableColumnFlags_None);
3867-
ImGui::TableSetupColumn("Four", ImGuiTableColumnFlags_None);
3868-
ImGui::TableSetupColumn("Five", ImGuiTableColumnFlags_None);
3869-
ImGui::TableSetupColumn("Six", ImGuiTableColumnFlags_None);
3862+
ImGui::TableSetupColumn("One");
3863+
ImGui::TableSetupColumn("Two");
3864+
ImGui::TableSetupColumn("Three");
3865+
ImGui::TableSetupColumn("Four");
3866+
ImGui::TableSetupColumn("Five");
3867+
ImGui::TableSetupColumn("Six");
38703868
ImGui::TableHeadersRow();
38713869
for (int row = 0; row < 20; row++)
38723870
{
38733871
ImGui::TableNextRow();
38743872
for (int column = 0; column < 7; column++)
38753873
{
3876-
// Both TableNextColumn() and TableSetColumnIndex() return false when a column is not visible, which can be used for clipping.
3877-
if (!ImGui::TableSetColumnIndex(column))
3874+
// Both TableNextColumn() and TableSetColumnIndex() return false when a column is not visible.
3875+
// Because here we know that A) all our columns are contributing the same to row height and B) column 0 is always visible,
3876+
// we only always submit this one column.
3877+
if (!ImGui::TableSetColumnIndex(column) && column > 0)
38783878
continue;
38793879
if (column == 0)
38803880
ImGui::Text("Line %d", row);
@@ -4809,8 +4809,8 @@ static void ShowDemoWindowTables()
48094809
}
48104810
}
48114811

4812-
ImGui::TableNextColumn();
4813-
ImGui::TextUnformatted(item->Name);
4812+
if (ImGui::TableNextColumn())
4813+
ImGui::TextUnformatted(item->Name);
48144814

48154815
// Here we demonstrate marking our data set as needing to be sorted again if we modified a quantity,
48164816
// and we are currently sorting on the column showing the Quantity.
@@ -4825,17 +4825,17 @@ static void ShowDemoWindowTables()
48254825
if (sorts_specs_using_quantity && ImGui::IsItemDeactivated()) { items_need_sort = true; }
48264826
}
48274827

4828-
ImGui::TableNextColumn();
4829-
ImGui::Text("%d", item->Quantity);
4828+
if (ImGui::TableNextColumn())
4829+
ImGui::Text("%d", item->Quantity);
48304830

48314831
ImGui::TableNextColumn();
48324832
if (show_wrapped_text)
48334833
ImGui::TextWrapped("Lorem ipsum dolor sit amet");
48344834
else
48354835
ImGui::Text("Lorem ipsum dolor sit amet");
48364836

4837-
ImGui::TableNextColumn();
4838-
ImGui::Text("1234");
4837+
if (ImGui::TableNextColumn())
4838+
ImGui::Text("1234");
48394839

48404840
ImGui::PopID();
48414841
}

imgui_internal.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,7 +1932,9 @@ struct ImGuiTableColumn
19321932
ImGuiTableDrawChannelIdx DrawChannelUnfrozen;
19331933
bool IsEnabled; // Is the column not marked Hidden by the user? (even if off view, e.g. clipped by scrolling).
19341934
bool IsEnabledNextFrame;
1935-
bool IsClipped; // Is not actually in view (e.g. not overlapping the host window clipping rectangle).
1935+
bool IsVisibleX; // Is actually in view (e.g. overlapping the host window clipping rectangle, not scrolled).
1936+
bool IsVisibleY;
1937+
bool IsRequestOutput; // Return value for TableSetColumnIndex() / TableNextColumn(): whether we request user to output contents or not.
19361938
bool IsSkipItems; // Do we want item submissions to this column to be completely ignored (no layout will happen).
19371939
ImS8 NavLayerCurrent; // ImGuiNavLayer in 1 byte
19381940
ImS8 SortDirection; // ImGuiSortDirection_Ascending or ImGuiSortDirection_Descending
@@ -1971,8 +1973,9 @@ struct ImGuiTable
19711973
ImSpan<ImGuiTableColumnIdx> DisplayOrderToIndex; // Point within RawData[]. Store display order of columns (when not reordered, the values are 0...Count-1)
19721974
ImSpan<ImGuiTableCellData> RowCellData; // Point within RawData[]. Store cells background requests for current row.
19731975
ImU64 EnabledMaskByDisplayOrder; // Column DisplayOrder -> IsEnabled map
1974-
ImU64 EnabledUnclippedMaskByIndex;// Enabled and not Clipped, aka "actually visible" "not hidden by some scrolling"
19751976
ImU64 EnabledMaskByIndex; // Column Index -> IsEnabled map (== not hidden by user/api) in a format adequate for iterating column without touching cold data
1977+
ImU64 VisibleMaskByIndex; // Column Index -> IsVisibleX|IsVisibleY map (== not hidden by user/api && not hidden by scrolling/cliprect)
1978+
ImU64 RequestOutputMaskByIndex; // Column Index -> IsVisible || AutoFit (== expect user to submit items)
19761979
ImGuiTableFlags SettingsLoadedFlags; // Which data were loaded from the .ini file (e.g. when order is not altered we won't save order)
19771980
int SettingsOffset; // Offset in g.SettingsTables
19781981
int LastFrameActive;
@@ -2280,7 +2283,7 @@ namespace ImGui
22802283
// Tables: Candidates for public api
22812284
IMGUI_API void TableOpenContextMenu(int column_n = -1);
22822285
IMGUI_API void TableSetColumnWidth(int column_n, float width);
2283-
IMGUI_API bool TableGetColumnIsEnabled(int column_n = -1); // Return false when column is disabled (hidden) by user (e.g. via context menu, or _DefaultHide flag)
2286+
IMGUI_API bool TableGetColumnIsEnabled(int column_n = -1); // Return false when column is disabled (hidden by user/api, e.g. via context menu, or _DefaultHide flag)
22842287
IMGUI_API void TableSetColumnIsEnabled(int column_n, bool enabled);
22852288
IMGUI_API void TableSetColumnSortDirection(int column_n, ImGuiSortDirection sort_direction, bool append_to_sort_specs);
22862289
IMGUI_API float TableGetHeaderRowHeight();

0 commit comments

Comments
 (0)