Skip to content

Commit e126a64

Browse files
committed
Tables: using a typedef in internal code to specify column/draw channel index storage.
1 parent 6aa8388 commit e126a64

File tree

3 files changed

+92
-88
lines changed

3 files changed

+92
-88
lines changed

imgui.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,8 +1896,8 @@ struct ImGuiPayload
18961896
struct ImGuiTableSortSpecsColumn
18971897
{
18981898
ImGuiID ColumnUserID; // User id of the column (if specified by a TableSetupColumn() call)
1899-
ImU8 ColumnIndex; // Index of the column
1900-
ImU8 SortOrder; // Index within parent ImGuiTableSortSpecs (always stored in order starting from 0, tables sorted on a single criteria will always have a 0 here)
1899+
ImS16 ColumnIndex; // Index of the column
1900+
ImS16 SortOrder; // Index within parent ImGuiTableSortSpecs (always stored in order starting from 0, tables sorted on a single criteria will always have a 0 here)
19011901
ImGuiSortDirection SortDirection : 8; // ImGuiSortDirection_Ascending or ImGuiSortDirection_Descending (you can use this or SortSign, whichever is more convenient for your sort function)
19021902

19031903
ImGuiTableSortSpecsColumn() { ColumnUserID = 0; ColumnIndex = 0; SortOrder = 0; SortDirection = ImGuiSortDirection_Ascending; }

imgui_internal.h

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,10 @@ struct ImGuiTabBar
18931893
#define IMGUI_TABLE_MAX_COLUMNS 64 // sizeof(ImU64) * 8. This is solely because we frequently encode columns set in a ImU64.
18941894
#define IMGUI_TABLE_MAX_DRAW_CHANNELS (4 + 64 * 2) // See TableSetupDrawChannels()
18951895

1896+
// Our current column maximum is 64 but we may raise that in the future.
1897+
typedef ImS8 ImGuiTableColumnIdx;
1898+
typedef ImU8 ImGuiTableDrawChannelIdx;
1899+
18961900
// [Internal] sizeof() ~ 104
18971901
// We use the terminology "Visible" to refer to a columns that are not Hidden by user or settings. However it may still be out of view and clipped (and IsClipped would be set).
18981902
// This is in contrast with some user-facing api such as IsItemVisible() / IsRectVisible() which use "Visible" to mean "not clipped".
@@ -1917,22 +1921,22 @@ struct ImGuiTableColumn
19171921
float ContentMaxXHeadersUsed; // Contents maximum position for headers rows (regardless of freezing). TableHeader() automatically softclip itself + report ideal desired size, to avoid creating extraneous draw calls
19181922
float ContentMaxXHeadersIdeal;
19191923
ImS16 NameOffset; // Offset into parent ColumnsNames[]
1924+
ImGuiTableColumnIdx DisplayOrder; // Index within Table's IndexToDisplayOrder[] (column may be reordered by users)
1925+
ImGuiTableColumnIdx IndexWithinEnabledSet; // Index within enabled/visible set (<= IndexToDisplayOrder)
1926+
ImGuiTableColumnIdx PrevEnabledColumn; // Index of prev enabled/visible column within Columns[], -1 if first enabled/visible column
1927+
ImGuiTableColumnIdx NextEnabledColumn; // Index of next enabled/visible column within Columns[], -1 if last enabled/visible column
1928+
ImGuiTableColumnIdx SortOrder; // Index of this column within sort specs, -1 if not sorting on this column, 0 for single-sort, may be >0 on multi-sort
1929+
ImGuiTableDrawChannelIdx DrawChannelCurrent; // Index within DrawSplitter.Channels[]
1930+
ImGuiTableDrawChannelIdx DrawChannelFrozen;
1931+
ImGuiTableDrawChannelIdx DrawChannelUnfrozen;
19201932
bool IsEnabled; // Is the column not marked Hidden by the user? (even if off view, e.g. clipped by scrolling).
19211933
bool IsEnabledNextFrame;
19221934
bool IsClipped; // Is not actually in view (e.g. not overlapping the host window clipping rectangle).
19231935
bool IsSkipItems; // Do we want item submissions to this column to be ignored early on.
19241936
ImS8 NavLayerCurrent; // ImGuiNavLayer in 1 byte
1925-
ImS8 DisplayOrder; // Index within Table's IndexToDisplayOrder[] (column may be reordered by users)
1926-
ImS8 IndexWithinEnabledSet; // Index within enabled/visible set (<= IndexToDisplayOrder)
1927-
ImS8 PrevEnabledColumn; // Index of prev enabled/visible column within Columns[], -1 if first enabled/visible column
1928-
ImS8 NextEnabledColumn; // Index of next enabled/visible column within Columns[], -1 if last enabled/visible column
1929-
ImS8 SortOrder; // Index of this column within sort specs, -1 if not sorting on this column, 0 for single-sort, may be >0 on multi-sort
19301937
ImS8 SortDirection; // ImGuiSortDirection_Ascending or ImGuiSortDirection_Descending
19311938
ImU8 AutoFitQueue; // Queue of 8 values for the next 8 frames to request auto-fit
19321939
ImU8 CannotSkipItemsQueue; // Queue of 8 values for the next 8 frames to disable Clipped/SkipItem
1933-
ImU8 DrawChannelCurrent; // Index within DrawSplitter.Channels[]
1934-
ImU8 DrawChannelFrozen;
1935-
ImU8 DrawChannelUnfrozen;
19361940

19371941
ImGuiTableColumn()
19381942
{
@@ -1952,8 +1956,8 @@ struct ImGuiTableColumn
19521956
// sizeof() ~ 6
19531957
struct ImGuiTableCellData
19541958
{
1955-
ImU32 BgColor; // Actual color
1956-
ImS8 Column; // Column number
1959+
ImU32 BgColor; // Actual color
1960+
ImGuiTableColumnIdx Column; // Column number
19571961
};
19581962

19591963
struct ImGuiTable
@@ -1962,7 +1966,7 @@ struct ImGuiTable
19621966
ImGuiTableFlags Flags;
19631967
void* RawData; // Single allocation to hold Columns[], DisplayOrderToIndex[] and RowCellData[]
19641968
ImSpan<ImGuiTableColumn> Columns; // Point within RawData[]
1965-
ImSpan<ImS8> DisplayOrderToIndex; // Point within RawData[]. Store display order of columns (when not reordered, the values are 0...Count-1)
1969+
ImSpan<ImGuiTableColumnIdx> DisplayOrderToIndex; // Point within RawData[]. Store display order of columns (when not reordered, the values are 0...Count-1)
19661970
ImSpan<ImGuiTableCellData> RowCellData; // Point within RawData[]. Store cells background requests for current row.
19671971
ImU64 EnabledMaskByIndex; // Column Index -> IsEnabled map (== not hidden by user/api) in a format adequate for iterating column without touching cold data
19681972
ImU64 EnabledMaskByDisplayOrder; // Column DisplayOrder -> IsEnabled map
@@ -2020,29 +2024,29 @@ struct ImGuiTable
20202024
ImDrawListSplitter DrawSplitter; // We carry our own ImDrawList splitter to allow recursion (FIXME: could be stored outside, worst case we need 1 splitter per recursing table)
20212025
ImVector<ImGuiTableSortSpecsColumn> SortSpecsData; // FIXME-OPT: Fixed-size array / small-vector pattern, optimize for single sort spec
20222026
ImGuiTableSortSpecs SortSpecs; // Public facing sorts specs, this is what we return in TableGetSortSpecs()
2023-
ImS8 SortSpecsCount;
2024-
ImS8 ColumnsEnabledCount; // Number of enabled columns (<= ColumnsCount)
2025-
ImS8 ColumnsEnabledFixedCount; // Number of enabled columns (<= ColumnsCount)
2026-
ImS8 DeclColumnsCount; // Count calls to TableSetupColumn()
2027-
ImS8 HoveredColumnBody; // Index of column whose visible region is being hovered. Important: == ColumnsCount when hovering empty region after the right-most column!
2028-
ImS8 HoveredColumnBorder; // Index of column whose right-border is being hovered (for resizing).
2029-
ImS8 AutoFitSingleStretchColumn; // Index of single stretch column requesting auto-fit.
2030-
ImS8 ResizedColumn; // Index of column being resized. Reset when InstanceCurrent==0.
2031-
ImS8 LastResizedColumn; // Index of column being resized from previous frame.
2032-
ImS8 HeldHeaderColumn; // Index of column header being held.
2033-
ImS8 ReorderColumn; // Index of column being reordered. (not cleared)
2034-
ImS8 ReorderColumnDir; // -1 or +1
2035-
ImS8 RightMostEnabledColumn; // Index of right-most non-hidden column.
2036-
ImS8 LeftMostStretchedColumnDisplayOrder; // Display order of left-most stretched column.
2037-
ImS8 ContextPopupColumn; // Column right-clicked on, of -1 if opening context menu from a neutral/empty spot
2038-
ImS8 FreezeRowsRequest; // Requested frozen rows count
2039-
ImS8 FreezeRowsCount; // Actual frozen row count (== FreezeRowsRequest, or == 0 when no scrolling offset)
2040-
ImS8 FreezeColumnsRequest; // Requested frozen columns count
2041-
ImS8 FreezeColumnsCount; // Actual frozen columns count (== FreezeColumnsRequest, or == 0 when no scrolling offset)
2042-
ImS8 RowCellDataCurrent; // Index of current RowCellData[] entry in current row
2043-
ImU8 DummyDrawChannel; // Redirect non-visible columns here.
2044-
ImU8 Bg1DrawChannelCurrent; // For Selectable() and other widgets drawing accross columns after the freezing line. Index within DrawSplitter.Channels[]
2045-
ImU8 Bg1DrawChannelUnfrozen;
2027+
ImGuiTableColumnIdx SortSpecsCount;
2028+
ImGuiTableColumnIdx ColumnsEnabledCount; // Number of enabled columns (<= ColumnsCount)
2029+
ImGuiTableColumnIdx ColumnsEnabledFixedCount; // Number of enabled columns (<= ColumnsCount)
2030+
ImGuiTableColumnIdx DeclColumnsCount; // Count calls to TableSetupColumn()
2031+
ImGuiTableColumnIdx HoveredColumnBody; // Index of column whose visible region is being hovered. Important: == ColumnsCount when hovering empty region after the right-most column!
2032+
ImGuiTableColumnIdx HoveredColumnBorder; // Index of column whose right-border is being hovered (for resizing).
2033+
ImGuiTableColumnIdx AutoFitSingleStretchColumn; // Index of single stretch column requesting auto-fit.
2034+
ImGuiTableColumnIdx ResizedColumn; // Index of column being resized. Reset when InstanceCurrent==0.
2035+
ImGuiTableColumnIdx LastResizedColumn; // Index of column being resized from previous frame.
2036+
ImGuiTableColumnIdx HeldHeaderColumn; // Index of column header being held.
2037+
ImGuiTableColumnIdx ReorderColumn; // Index of column being reordered. (not cleared)
2038+
ImGuiTableColumnIdx ReorderColumnDir; // -1 or +1
2039+
ImGuiTableColumnIdx RightMostEnabledColumn; // Index of right-most non-hidden column.
2040+
ImGuiTableColumnIdx LeftMostStretchedColumnDisplayOrder; // Display order of left-most stretched column.
2041+
ImGuiTableColumnIdx ContextPopupColumn; // Column right-clicked on, of -1 if opening context menu from a neutral/empty spot
2042+
ImGuiTableColumnIdx FreezeRowsRequest; // Requested frozen rows count
2043+
ImGuiTableColumnIdx FreezeRowsCount; // Actual frozen row count (== FreezeRowsRequest, or == 0 when no scrolling offset)
2044+
ImGuiTableColumnIdx FreezeColumnsRequest; // Requested frozen columns count
2045+
ImGuiTableColumnIdx FreezeColumnsCount; // Actual frozen columns count (== FreezeColumnsRequest, or == 0 when no scrolling offset)
2046+
ImGuiTableColumnIdx RowCellDataCurrent; // Index of current RowCellData[] entry in current row
2047+
ImGuiTableDrawChannelIdx DummyDrawChannel; // Redirect non-visible columns here.
2048+
ImGuiTableDrawChannelIdx Bg1DrawChannelCurrent; // For Selectable() and other widgets drawing accross columns after the freezing line. Index within DrawSplitter.Channels[]
2049+
ImGuiTableDrawChannelIdx Bg1DrawChannelUnfrozen;
20462050
bool IsLayoutLocked; // Set by TableUpdateLayout() which is called when beginning the first row.
20472051
bool IsInsideRow; // Set when inside TableBeginRow()/TableEndRow().
20482052
bool IsInitializing;
@@ -2064,14 +2068,14 @@ struct ImGuiTable
20642068
// sizeof() ~ 12
20652069
struct ImGuiTableColumnSettings
20662070
{
2067-
float WidthOrWeight;
2068-
ImGuiID UserID;
2069-
ImS8 Index;
2070-
ImS8 DisplayOrder;
2071-
ImS8 SortOrder;
2072-
ImU8 SortDirection : 2;
2073-
ImU8 IsEnabled : 1; // "Visible" in ini file
2074-
ImU8 IsStretch : 1;
2071+
float WidthOrWeight;
2072+
ImGuiID UserID;
2073+
ImGuiTableColumnIdx Index;
2074+
ImGuiTableColumnIdx DisplayOrder;
2075+
ImGuiTableColumnIdx SortOrder;
2076+
ImU8 SortDirection : 2;
2077+
ImU8 IsEnabled : 1; // "Visible" in ini file
2078+
ImU8 IsStretch : 1;
20752079

20762080
ImGuiTableColumnSettings()
20772081
{
@@ -2091,8 +2095,8 @@ struct ImGuiTableSettings
20912095
ImGuiID ID; // Set to 0 to invalidate/delete the setting
20922096
ImGuiTableFlags SaveFlags; // Indicate data we want to save using the Resizable/Reorderable/Sortable/Hideable flags (could be using its own flags..)
20932097
float RefScale; // Reference scale to be able to rescale columns on font/dpi changes.
2094-
ImS8 ColumnsCount;
2095-
ImS8 ColumnsCountMax; // Maximum number of columns this settings instance can store, we can recycle a settings instance with lower number of columns but not higher
2098+
ImGuiTableColumnIdx ColumnsCount;
2099+
ImGuiTableColumnIdx ColumnsCountMax; // Maximum number of columns this settings instance can store, we can recycle a settings instance with lower number of columns but not higher
20962100
bool WantApply; // Set when loaded from .ini data (to enable merging/loading .ini data into an already running context)
20972101

20982102
ImGuiTableSettings() { memset(this, 0, sizeof(*this)); }

0 commit comments

Comments
 (0)