Skip to content

Commit 738606a

Browse files
committed
Tables: added ImGuiTableFlags_SortTristate. Renamed ImGuiTableFlags_MultiSortable to ImGuiTableFlags_SortMulti. Removed now unused FlagsIn storage.
1 parent cad8935 commit 738606a

File tree

4 files changed

+120
-84
lines changed

4 files changed

+120
-84
lines changed

imgui.h

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,38 +1055,40 @@ enum ImGuiTableFlags_
10551055
ImGuiTableFlags_Reorderable = 1 << 1, // Allow reordering columns in header row (need calling TableSetupColumn() + TableHeadersRow() to display headers)
10561056
ImGuiTableFlags_Hideable = 1 << 2, // Allow hiding/disabling columns in context menu.
10571057
ImGuiTableFlags_Sortable = 1 << 3, // Allow sorting on one column (sort_specs_count will always be == 1). Call TableGetSortSpecs() to obtain sort specs.
1058-
ImGuiTableFlags_MultiSortable = 1 << 4, // Allow sorting on multiple columns by holding Shift (sort_specs_count may be > 1). Call TableGetSortSpecs() to obtain sort specs.
1059-
ImGuiTableFlags_NoSavedSettings = 1 << 5, // Disable persisting columns order, width and sort settings in the .ini file.
1060-
ImGuiTableFlags_ContextMenuInBody = 1 << 6, // Right-click on columns body/contents will display table context menu. By default it is available in TableHeadersRow().
1058+
ImGuiTableFlags_NoSavedSettings = 1 << 4, // Disable persisting columns order, width and sort settings in the .ini file.
1059+
ImGuiTableFlags_ContextMenuInBody = 1 << 5, // Right-click on columns body/contents will display table context menu. By default it is available in TableHeadersRow().
10611060
// Decorations
1062-
ImGuiTableFlags_RowBg = 1 << 7, // Set each RowBg color with ImGuiCol_TableRowBg or ImGuiCol_TableRowBgAlt (equivalent of calling TableSetBgColor with ImGuiTableBgFlags_RowBg0 on each row manually)
1063-
ImGuiTableFlags_BordersInnerH = 1 << 8, // Draw horizontal borders between rows.
1064-
ImGuiTableFlags_BordersOuterH = 1 << 9, // Draw horizontal borders at the top and bottom.
1065-
ImGuiTableFlags_BordersInnerV = 1 << 10, // Draw vertical borders between columns.
1066-
ImGuiTableFlags_BordersOuterV = 1 << 11, // Draw vertical borders on the left and right sides.
1061+
ImGuiTableFlags_RowBg = 1 << 6, // Set each RowBg color with ImGuiCol_TableRowBg or ImGuiCol_TableRowBgAlt (equivalent of calling TableSetBgColor with ImGuiTableBgFlags_RowBg0 on each row manually)
1062+
ImGuiTableFlags_BordersInnerH = 1 << 7, // Draw horizontal borders between rows.
1063+
ImGuiTableFlags_BordersOuterH = 1 << 8, // Draw horizontal borders at the top and bottom.
1064+
ImGuiTableFlags_BordersInnerV = 1 << 9, // Draw vertical borders between columns.
1065+
ImGuiTableFlags_BordersOuterV = 1 << 10, // Draw vertical borders on the left and right sides.
10671066
ImGuiTableFlags_BordersH = ImGuiTableFlags_BordersInnerH | ImGuiTableFlags_BordersOuterH, // Draw horizontal borders.
10681067
ImGuiTableFlags_BordersV = ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_BordersOuterV, // Draw vertical borders.
10691068
ImGuiTableFlags_BordersInner = ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_BordersInnerH, // Draw inner borders.
10701069
ImGuiTableFlags_BordersOuter = ImGuiTableFlags_BordersOuterV | ImGuiTableFlags_BordersOuterH, // Draw outer borders.
10711070
ImGuiTableFlags_Borders = ImGuiTableFlags_BordersInner | ImGuiTableFlags_BordersOuter, // Draw all borders.
1072-
ImGuiTableFlags_NoBordersInBody = 1 << 12, // Disable vertical borders in columns Body (borders will always appears in Headers).
1073-
ImGuiTableFlags_NoBordersInBodyUntilResize = 1 << 13, // Disable vertical borders in columns Body until hovered for resize (borders will always appears in Headers).
1071+
ImGuiTableFlags_NoBordersInBody = 1 << 11, // Disable vertical borders in columns Body (borders will always appears in Headers).
1072+
ImGuiTableFlags_NoBordersInBodyUntilResize = 1 << 12, // Disable vertical borders in columns Body until hovered for resize (borders will always appears in Headers).
10741073
// Sizing
1075-
ImGuiTableFlags_ColumnsWidthStretch = 1 << 14, // Default if ScrollX is off. Columns will default to use _WidthStretch. Read description above for more details.
1076-
ImGuiTableFlags_ColumnsWidthFixed = 1 << 15, // Default if ScrollX is on. Columns will default to use _WidthFixed or _WidthAutoResize policy (if Resizable is off). Read description above for more details.
1077-
ImGuiTableFlags_SameWidths = 1 << 16, // Make all columns the same widths which is useful with Fixed columns policy (but granted by default with Stretch policy + no resize). Implicitly enable ImGuiTableFlags_NoKeepColumnsVisible and disable ImGuiTableFlags_Resizable.
1078-
ImGuiTableFlags_NoHeadersWidth = 1 << 17, // Disable headers' contribution to automatic width calculation.
1079-
ImGuiTableFlags_NoHostExtendY = 1 << 18, // Disable extending past the limit set by outer_size.y, only meaningful when neither of ScrollX|ScrollY are set (data below the limit will be clipped and not visible)
1080-
ImGuiTableFlags_NoKeepColumnsVisible = 1 << 19, // Disable keeping column always minimally visible when ScrollX is off and table gets too small.
1081-
ImGuiTableFlags_PreciseWidths = 1 << 20, // Disable distributing remainder width to stretched columns (width allocation on a 100-wide table with 3 columns: Without this flag: 33,33,34. With this flag: 33,33,33). With larger number of columns, resizing will appear to be less smooth.
1082-
ImGuiTableFlags_NoClip = 1 << 21, // Disable clipping rectangle for every individual columns (reduce draw command count, items will be able to overflow into other columns). Generally incompatible with TableSetupScrollFreeze().
1074+
ImGuiTableFlags_ColumnsWidthStretch = 1 << 13, // Default if ScrollX is off. Columns will default to use _WidthStretch. Read description above for more details.
1075+
ImGuiTableFlags_ColumnsWidthFixed = 1 << 14, // Default if ScrollX is on. Columns will default to use _WidthFixed or _WidthAutoResize policy (if Resizable is off). Read description above for more details.
1076+
ImGuiTableFlags_SameWidths = 1 << 15, // Make all columns the same widths which is useful with Fixed columns policy (but granted by default with Stretch policy + no resize). Implicitly enable ImGuiTableFlags_NoKeepColumnsVisible and disable ImGuiTableFlags_Resizable.
1077+
ImGuiTableFlags_NoHeadersWidth = 1 << 16, // Disable headers' contribution to automatic width calculation.
1078+
ImGuiTableFlags_NoHostExtendY = 1 << 17, // Disable extending past the limit set by outer_size.y, only meaningful when neither of ScrollX|ScrollY are set (data below the limit will be clipped and not visible)
1079+
ImGuiTableFlags_NoKeepColumnsVisible = 1 << 18, // Disable keeping column always minimally visible when ScrollX is off and table gets too small.
1080+
ImGuiTableFlags_PreciseWidths = 1 << 19, // Disable distributing remainder width to stretched columns (width allocation on a 100-wide table with 3 columns: Without this flag: 33,33,34. With this flag: 33,33,33). With larger number of columns, resizing will appear to be less smooth.
1081+
ImGuiTableFlags_NoClip = 1 << 20, // Disable clipping rectangle for every individual columns (reduce draw command count, items will be able to overflow into other columns). Generally incompatible with TableSetupScrollFreeze().
10831082
// Padding
1084-
ImGuiTableFlags_PadOuterX = 1 << 22, // Default if BordersOuterV is on. Enable outer-most padding.
1085-
ImGuiTableFlags_NoPadOuterX = 1 << 23, // Default if BordersOuterV is off. Disable outer-most padding.
1086-
ImGuiTableFlags_NoPadInnerX = 1 << 24, // Disable inner padding between columns (double inner padding if BordersOuterV is on, single inner padding if BordersOuterV is off).
1083+
ImGuiTableFlags_PadOuterX = 1 << 21, // Default if BordersOuterV is on. Enable outer-most padding.
1084+
ImGuiTableFlags_NoPadOuterX = 1 << 22, // Default if BordersOuterV is off. Disable outer-most padding.
1085+
ImGuiTableFlags_NoPadInnerX = 1 << 23, // Disable inner padding between columns (double inner padding if BordersOuterV is on, single inner padding if BordersOuterV is off).
10871086
// Scrolling
1088-
ImGuiTableFlags_ScrollX = 1 << 25, // Enable horizontal scrolling. Require 'outer_size' parameter of BeginTable() to specify the container size. Changes default sizing policy. Because this create a child window, ScrollY is currently generally recommended when using ScrollX.
1089-
ImGuiTableFlags_ScrollY = 1 << 26 // Enable vertical scrolling. Require 'outer_size' parameter of BeginTable() to specify the container size.
1087+
ImGuiTableFlags_ScrollX = 1 << 24, // Enable horizontal scrolling. Require 'outer_size' parameter of BeginTable() to specify the container size. Changes default sizing policy. Because this create a child window, ScrollY is currently generally recommended when using ScrollX.
1088+
ImGuiTableFlags_ScrollY = 1 << 25, // Enable vertical scrolling. Require 'outer_size' parameter of BeginTable() to specify the container size.
1089+
// Sorting
1090+
ImGuiTableFlags_SortMulti = 1 << 26, // Hold shift when clicking headers to sort on multiple column. TableGetSortSpecs() may return specs where (SpecsCount > 1).
1091+
ImGuiTableFlags_SortTristate = 1 << 27 // Allow no sorting, disable default sorting. TableGetSortSpecs() may return specs where (SpecsCount == 0).
10901092
};
10911093

10921094
// Flags for ImGui::TableSetupColumn()
@@ -1915,7 +1917,7 @@ struct ImGuiTableColumnSortSpecs
19151917
struct ImGuiTableSortSpecs
19161918
{
19171919
const ImGuiTableColumnSortSpecs* Specs; // Pointer to sort spec array.
1918-
int SpecsCount; // Sort spec count. Most often 1 unless e.g. ImGuiTableFlags_MultiSortable is enabled.
1920+
int SpecsCount; // Sort spec count. Most often 1. May be > 1 when ImGuiTableFlags_SortMulti is enabled. May be == 0 when ImGuiTableFlags_SortTristate is enabled.
19191921
bool SpecsDirty; // Set to true when specs have changed since last time! Use this to sort again, then clear the flag.
19201922

19211923
ImGuiTableSortSpecs() { memset(this, 0, sizeof(*this)); }

imgui_demo.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4572,8 +4572,6 @@ static void ShowDemoWindowTables()
45724572
ImGui::SetNextItemOpen(open_action != 0);
45734573
if (ImGui::TreeNode("Sorting"))
45744574
{
4575-
HelpMarker("Use Shift+Click to sort on multiple columns");
4576-
45774575
// Create item list
45784576
static ImVector<MyItem> items;
45794577
if (items.Size == 0)
@@ -4589,10 +4587,16 @@ static void ShowDemoWindowTables()
45894587
}
45904588
}
45914589

4592-
ImGuiTableFlags flags =
4593-
ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_MultiSortable
4590+
// Options
4591+
static ImGuiTableFlags flags =
4592+
ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Sortable | ImGuiTableFlags_SortMulti
45944593
| ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_NoBordersInBody
45954594
| ImGuiTableFlags_ScrollY;
4595+
ImGui::CheckboxFlags("ImGuiTableFlags_SortMulti", &flags, ImGuiTableFlags_SortMulti);
4596+
ImGui::SameLine(); HelpMarker("When sorting is enabled: hold shift when clicking headers to sort on multiple column. TableGetSortSpecs() may return specs where (SpecsCount > 1).");
4597+
ImGui::CheckboxFlags("ImGuiTableFlags_SortTristate", &flags, ImGuiTableFlags_SortTristate);
4598+
ImGui::SameLine(); HelpMarker("When sorting is enabled: allow no sorting, disable default sorting. TableGetSortSpecs() may return specs where (SpecsCount == 0).");
4599+
45964600
if (ImGui::BeginTable("##table", 4, flags, ImVec2(0, TEXT_BASE_HEIGHT * 15), 0.0f))
45974601
{
45984602
// Declare columns
@@ -4651,11 +4655,11 @@ static void ShowDemoWindowTables()
46514655
if (ImGui::TreeNode("Advanced"))
46524656
{
46534657
static ImGuiTableFlags flags =
4654-
ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_MultiSortable
4658+
ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable
4659+
| ImGuiTableFlags_Sortable | ImGuiTableFlags_SortMulti
46554660
| ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders | ImGuiTableFlags_NoBordersInBody
46564661
| ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY
4657-
| ImGuiTableFlags_ColumnsWidthFixed
4658-
;
4662+
| ImGuiTableFlags_ColumnsWidthFixed;
46594663

46604664
enum ContentsType { CT_Text, CT_Button, CT_SmallButton, CT_FillButton, CT_Selectable, CT_SelectableSpanRow };
46614665
static int contents_type = CT_Button;
@@ -4683,7 +4687,6 @@ static void ShowDemoWindowTables()
46834687
ImGui::CheckboxFlags("ImGuiTableFlags_Reorderable", &flags, ImGuiTableFlags_Reorderable);
46844688
ImGui::CheckboxFlags("ImGuiTableFlags_Hideable", &flags, ImGuiTableFlags_Hideable);
46854689
ImGui::CheckboxFlags("ImGuiTableFlags_Sortable", &flags, ImGuiTableFlags_Sortable);
4686-
ImGui::CheckboxFlags("ImGuiTableFlags_MultiSortable", &flags, ImGuiTableFlags_MultiSortable);
46874690
ImGui::CheckboxFlags("ImGuiTableFlags_NoSavedSettings", &flags, ImGuiTableFlags_NoSavedSettings);
46884691
ImGui::CheckboxFlags("ImGuiTableFlags_ContextMenuInBody", &flags, ImGuiTableFlags_ContextMenuInBody);
46894692
ImGui::TreePop();
@@ -4744,6 +4747,15 @@ static void ShowDemoWindowTables()
47444747
ImGui::TreePop();
47454748
}
47464749

4750+
if (ImGui::TreeNodeEx("Sorting:", ImGuiTreeNodeFlags_DefaultOpen))
4751+
{
4752+
ImGui::CheckboxFlags("ImGuiTableFlags_SortMulti", &flags, ImGuiTableFlags_SortMulti);
4753+
ImGui::SameLine(); HelpMarker("When sorting is enabled: hold shift when clicking headers to sort on multiple column. TableGetSortSpecs() may return specs where (SpecsCount > 1).");
4754+
ImGui::CheckboxFlags("ImGuiTableFlags_SortTristate", &flags, ImGuiTableFlags_SortTristate);
4755+
ImGui::SameLine(); HelpMarker("When sorting is enabled: allow no sorting, disable default sorting. TableGetSortSpecs() may return specs where (SpecsCount == 0).");
4756+
ImGui::TreePop();
4757+
}
4758+
47474759
if (ImGui::TreeNodeEx("Other:", ImGuiTreeNodeFlags_DefaultOpen))
47484760
{
47494761
ImGui::Checkbox("show_headers", &show_headers);
@@ -4799,13 +4811,13 @@ static void ShowDemoWindowTables()
47994811
// Declare columns
48004812
// We use the "user_id" parameter of TableSetupColumn() to specify a user id that will be stored in the sort specifications.
48014813
// This is so our sort function can identify a column given our own identifier. We could also identify them based on their index!
4802-
ImGui::TableSetupScrollFreeze(freeze_cols, freeze_rows);
48034814
ImGui::TableSetupColumn("ID", ImGuiTableColumnFlags_DefaultSort | ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoHide, -1.0f, MyItemColumnID_ID);
48044815
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, -1.0f, MyItemColumnID_Name);
48054816
ImGui::TableSetupColumn("Action", ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_WidthFixed, -1.0f, MyItemColumnID_Action);
48064817
ImGui::TableSetupColumn("Quantity (Long Label)", ImGuiTableColumnFlags_PreferSortDescending | ImGuiTableColumnFlags_WidthStretch, 1.0f, MyItemColumnID_Quantity);// , ImGuiTableColumnFlags_WidthAutoResize);
48074818
ImGui::TableSetupColumn("Description", ImGuiTableColumnFlags_WidthStretch, 1.0f, MyItemColumnID_Description);
48084819
ImGui::TableSetupColumn("Hidden", ImGuiTableColumnFlags_DefaultHide | ImGuiTableColumnFlags_NoSort);
4820+
ImGui::TableSetupScrollFreeze(freeze_cols, freeze_rows);
48094821

48104822
// Sort our data if sort specs have been changed!
48114823
ImGuiTableSortSpecs* sorts_specs = ImGui::TableGetSortSpecs();

imgui_internal.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,8 +1906,7 @@ struct ImGuiTableColumn
19061906
{
19071907
ImRect ClipRect; // Clipping rectangle for the column
19081908
ImGuiID UserID; // Optional, value passed to TableSetupColumn()
1909-
ImGuiTableColumnFlags FlagsIn; // Flags as they were provided by user. See ImGuiTableColumnFlags_
1910-
ImGuiTableColumnFlags Flags; // Effective flags. See ImGuiTableColumnFlags_
1909+
ImGuiTableColumnFlags Flags; // Flags after some patching (not directly same as provided by user). See ImGuiTableColumnFlags_
19111910
float MinX; // Absolute positions
19121911
float MaxX;
19131912
float InitStretchWeightOrWidth; // Value passed to TableSetupColumn(). For Width it is a content width (_without padding_).
@@ -1939,9 +1938,12 @@ struct ImGuiTableColumn
19391938
bool IsSkipItems; // Do we want item submissions to this column to be completely ignored (no layout will happen).
19401939
bool IsPreserveWidthAuto;
19411940
ImS8 NavLayerCurrent; // ImGuiNavLayer in 1 byte
1942-
ImS8 SortDirection; // ImGuiSortDirection_Ascending or ImGuiSortDirection_Descending
19431941
ImU8 AutoFitQueue; // Queue of 8 values for the next 8 frames to request auto-fit
19441942
ImU8 CannotSkipItemsQueue; // Queue of 8 values for the next 8 frames to disable Clipped/SkipItem
1943+
ImU8 SortDirection : 2; // ImGuiSortDirection_Ascending or ImGuiSortDirection_Descending
1944+
ImU8 SortDirectionsAvailCount : 2; // Number of available sort directions (0 to 3)
1945+
ImU8 SortDirectionsAvailMask : 4; // Mask of available sort directions (1-bit each)
1946+
ImU8 SortDirectionsAvailList; // Ordered of available sort directions (2-bits each)
19451947

19461948
ImGuiTableColumn()
19471949
{
@@ -2307,7 +2309,8 @@ namespace ImGui
23072309
IMGUI_API void TableMergeDrawChannels(ImGuiTable* table);
23082310
IMGUI_API void TableSortSpecsSanitize(ImGuiTable* table);
23092311
IMGUI_API void TableSortSpecsBuild(ImGuiTable* table);
2310-
IMGUI_API void TableFixColumnSortDirection(ImGuiTableColumn* column);
2312+
IMGUI_API ImGuiSortDirection TableGetColumnNextSortDirection(ImGuiTableColumn* column);
2313+
IMGUI_API void TableFixColumnSortDirection(ImGuiTable* table, ImGuiTableColumn* column);
23112314
IMGUI_API void TableBeginRow(ImGuiTable* table);
23122315
IMGUI_API void TableEndRow(ImGuiTable* table);
23132316
IMGUI_API void TableBeginCell(ImGuiTable* table, int column_n);

0 commit comments

Comments
 (0)