Tables: added flags to TableDrawContextMenu() in order to display selected sections + added internal table->DisableDefaultContextMenu = true way to submit your own contents.

Amend 088ddef
This commit is contained in:
ocornut 2023-11-09 11:40:16 +01:00
parent 0d3b468cb3
commit fea52e29aa
2 changed files with 22 additions and 10 deletions

View File

@ -2792,6 +2792,7 @@ struct IMGUI_API ImGuiTable
bool IsSortSpecsDirty; bool IsSortSpecsDirty;
bool IsUsingHeaders; // Set when the first row had the ImGuiTableRowFlags_Headers flag. bool IsUsingHeaders; // Set when the first row had the ImGuiTableRowFlags_Headers flag.
bool IsContextPopupOpen; // Set when default context menu is open (also see: ContextPopupColumn, InstanceInteracted). bool IsContextPopupOpen; // Set when default context menu is open (also see: ContextPopupColumn, InstanceInteracted).
bool DisableDefaultContextMenu; // Disable default context menu contents. You may submit your own using TableBeginContextMenuPopup()/EndPopup()
bool IsSettingsRequestLoad; bool IsSettingsRequestLoad;
bool IsSettingsDirty; // Set when table settings have changed and needs to be reported into ImGuiTableSetttings data. bool IsSettingsDirty; // Set when table settings have changed and needs to be reported into ImGuiTableSetttings data.
bool IsDefaultDisplayOrder; // Set when display order is unchanged from default (DisplayOrder contains 0...Count-1) bool IsDefaultDisplayOrder; // Set when display order is unchanged from default (DisplayOrder contains 0...Count-1)
@ -3210,7 +3211,7 @@ namespace ImGui
IMGUI_API void TableUpdateBorders(ImGuiTable* table); IMGUI_API void TableUpdateBorders(ImGuiTable* table);
IMGUI_API void TableUpdateColumnsWeightFromWidth(ImGuiTable* table); IMGUI_API void TableUpdateColumnsWeightFromWidth(ImGuiTable* table);
IMGUI_API void TableDrawBorders(ImGuiTable* table); IMGUI_API void TableDrawBorders(ImGuiTable* table);
IMGUI_API void TableDrawContextMenu(ImGuiTable* table); IMGUI_API void TableDrawContextMenu(ImGuiTable* table, ImGuiTableFlags flags_for_section_to_display);
IMGUI_API bool TableBeginContextMenuPopup(ImGuiTable* table); IMGUI_API bool TableBeginContextMenuPopup(ImGuiTable* table);
IMGUI_API void TableMergeDrawChannels(ImGuiTable* table); IMGUI_API void TableMergeDrawChannels(ImGuiTable* table);
inline ImGuiTableInstanceData* TableGetInstanceData(ImGuiTable* table, int instance_no) { if (instance_no == 0) return &table->InstanceDataFirst; return &table->InstanceDataExtra[instance_no - 1]; } inline ImGuiTableInstanceData* TableGetInstanceData(ImGuiTable* table, int instance_no) { if (instance_no == 0) return &table->InstanceDataFirst; return &table->InstanceDataExtra[instance_no - 1]; }

View File

@ -48,7 +48,8 @@ Index of this file:
// - TableUpdateLayout() [Internal] followup to BeginTable(): setup everything: widths, columns positions, clipping rectangles. Automatically called by the FIRST call to TableNextRow() or TableHeadersRow(). // - TableUpdateLayout() [Internal] followup to BeginTable(): setup everything: widths, columns positions, clipping rectangles. Automatically called by the FIRST call to TableNextRow() or TableHeadersRow().
// | TableSetupDrawChannels() - setup ImDrawList channels // | TableSetupDrawChannels() - setup ImDrawList channels
// | TableUpdateBorders() - detect hovering columns for resize, ahead of contents submission // | TableUpdateBorders() - detect hovering columns for resize, ahead of contents submission
// | TableDrawContextMenu() - draw right-click context menu // | TableBeginContextMenuPopup()
// | - TableDrawContextMenu() - draw right-click context menu contents
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// - TableHeadersRow() or TableHeader() user submit a headers row (optional) // - TableHeadersRow() or TableHeader() user submit a headers row (optional)
// | TableSortSpecsClickColumn() - when left-clicked: alter sort order and sort direction // | TableSortSpecsClickColumn() - when left-clicked: alter sort order and sort direction
@ -1190,10 +1191,14 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
if (g.ActiveId == 0 || (table->IsActiveIdInTable || g.DragDropActive)) if (g.ActiveId == 0 || (table->IsActiveIdInTable || g.DragDropActive))
table->HighlightColumnHeader = table->HoveredColumnBody; table->HighlightColumnHeader = table->HoveredColumnBody;
// [Part 11] Context menu // [Part 11] Default context menu
if (TableBeginContextMenuPopup(table)) // - To append to this menu: you can call TableBeginContextMenuPopup()/.../EndPopup().
// - To modify or replace this: set table->IsContextPopupNoDefaultContents = true, then call TableBeginContextMenuPopup()/.../EndPopup().
// - You may call TableDrawContextMenu() with selected flags to display specific sections of the default menu,
// e.g. TableDrawContextMenu(table, table->Flags & ~ImGuiTableFlags_Hideable) will display everything EXCEPT columns visibility options.
if (table->DisableDefaultContextMenu == false && TableBeginContextMenuPopup(table))
{ {
TableDrawContextMenu(table); TableDrawContextMenu(table, table->Flags);
EndPopup(); EndPopup();
} }
@ -3293,7 +3298,13 @@ bool ImGui::TableBeginContextMenuPopup(ImGuiTable* table)
// Output context menu into current window (generally a popup) // 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? // FIXME-TABLE: Ideally this should be writable by the user. Full programmatic access to that data?
void ImGui::TableDrawContextMenu(ImGuiTable* table) // Sections to display are pulled from 'flags_for_section_to_display', which is typically == table->Flags.
// - ImGuiTableFlags_Resizable -> display Sizing menu items
// - ImGuiTableFlags_Reorderable -> display "Reset Order"
////- ImGuiTableFlags_Sortable -> display sorting options (disabled)
// - ImGuiTableFlags_Hideable -> display columns visibility menu items
// It means if you have a custom context menus you can call this section and omit some sections, and add your own.
void ImGui::TableDrawContextMenu(ImGuiTable* table, ImGuiTableFlags flags_for_section_to_display)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow; ImGuiWindow* window = g.CurrentWindow;
@ -3305,7 +3316,7 @@ void ImGui::TableDrawContextMenu(ImGuiTable* table)
ImGuiTableColumn* column = (column_n != -1) ? &table->Columns[column_n] : NULL; ImGuiTableColumn* column = (column_n != -1) ? &table->Columns[column_n] : NULL;
// Sizing // Sizing
if (table->Flags & ImGuiTableFlags_Resizable) if (flags_for_section_to_display & ImGuiTableFlags_Resizable)
{ {
if (column != NULL) if (column != NULL)
{ {
@ -3325,7 +3336,7 @@ void ImGui::TableDrawContextMenu(ImGuiTable* table)
} }
// Ordering // Ordering
if (table->Flags & ImGuiTableFlags_Reorderable) if (flags_for_section_to_display & ImGuiTableFlags_Reorderable)
{ {
if (MenuItem(LocalizeGetMsg(ImGuiLocKey_TableResetOrder), NULL, false, !table->IsDefaultDisplayOrder)) if (MenuItem(LocalizeGetMsg(ImGuiLocKey_TableResetOrder), NULL, false, !table->IsDefaultDisplayOrder))
table->IsResetDisplayOrderRequest = true; table->IsResetDisplayOrderRequest = true;
@ -3339,7 +3350,7 @@ void ImGui::TableDrawContextMenu(ImGuiTable* table)
// Sorting // Sorting
// (modify TableOpenContextMenu() to add _Sortable flag if enabling this) // (modify TableOpenContextMenu() to add _Sortable flag if enabling this)
#if 0 #if 0
if ((table->Flags & ImGuiTableFlags_Sortable) && column != NULL && (column->Flags & ImGuiTableColumnFlags_NoSort) == 0) if ((flags_for_section_to_display & ImGuiTableFlags_Sortable) && column != NULL && (column->Flags & ImGuiTableColumnFlags_NoSort) == 0)
{ {
if (want_separator) if (want_separator)
Separator(); Separator();
@ -3354,7 +3365,7 @@ void ImGui::TableDrawContextMenu(ImGuiTable* table)
#endif #endif
// Hiding / Visibility // Hiding / Visibility
if (table->Flags & ImGuiTableFlags_Hideable) if (flags_for_section_to_display & ImGuiTableFlags_Hideable)
{ {
if (want_separator) if (want_separator)
Separator(); Separator();