mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-06 04:58:47 +02:00
Tables: Added ImGuiTableFlags_ContextMenuInBody flag.
Worked to get TableOpenContextMenu() in public API but kept it internal.
This commit is contained in:
@ -4104,54 +4104,91 @@ static void ShowDemoWindowTables()
|
||||
ImGui::SetNextItemOpen(open_action != 0);
|
||||
if (ImGui::TreeNode("Context menus"))
|
||||
{
|
||||
HelpMarker("By default, TableHeadersRow()/TableHeader() will open a context-menu on right-click.");
|
||||
ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingPolicyFixedX | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders;
|
||||
HelpMarker("By default, right-clicking over a TableHeadersRow()/TableHeader() line will open the default context-menu.\nUsing ImGuiTableFlags_ContextMenuInBody we also allow right-clicking over columns body.");
|
||||
static ImGuiTableFlags flags1 = ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders | ImGuiTableFlags_ContextMenuInBody;
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_ContextMenuInBody", (unsigned int*)&flags1, ImGuiTableFlags_ContextMenuInBody);
|
||||
|
||||
// Context Menus: first example
|
||||
// [1.1] Right-click on the TableHeadersRow() line to open the default table context menu.
|
||||
// [1.2] Right-click in columns also open the default table context menu (if ImGuiTableFlags_ContextMenuInBody is set)
|
||||
const int COLUMNS_COUNT = 3;
|
||||
if (ImGui::BeginTable("##table1", COLUMNS_COUNT, flags))
|
||||
if (ImGui::BeginTable("##table1", COLUMNS_COUNT, flags1))
|
||||
{
|
||||
ImGui::TableSetupColumn("One");
|
||||
ImGui::TableSetupColumn("Two");
|
||||
ImGui::TableSetupColumn("Three");
|
||||
|
||||
// Context Menu 1: right-click on header (including empty section after the third column!) should open Default Table Popup
|
||||
// [1.1]] Right-click on the TableHeadersRow() line to open the default table context menu.
|
||||
ImGui::TableHeadersRow();
|
||||
|
||||
// Submit dummy contents
|
||||
for (int row = 0; row < 4; row++)
|
||||
{
|
||||
ImGui::TableNextRow();
|
||||
for (int column = 0; column < COLUMNS_COUNT; column++)
|
||||
{
|
||||
ImGui::TableSetColumnIndex(column);
|
||||
ImGui::PushID(row * COLUMNS_COUNT + column);
|
||||
ImGui::Text("Cell %d,%d", 0, row);
|
||||
}
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
// Context Menus: second example
|
||||
// [2.1] Right-click on the TableHeadersRow() line to open the default table context menu.
|
||||
// [2.2] Right-click on the ".." to open a custom popup
|
||||
// [2.3] Right-click in columns to open another custom popup
|
||||
HelpMarker("Demonstrate mixing table context menu (over header), item context button (over button) and custom per-colum context menu (over column body).");
|
||||
ImGuiTableFlags flags2 = ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingPolicyFixedX | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders;
|
||||
if (ImGui::BeginTable("##table2", COLUMNS_COUNT, flags2))
|
||||
{
|
||||
ImGui::TableSetupColumn("One");
|
||||
ImGui::TableSetupColumn("Two");
|
||||
ImGui::TableSetupColumn("Three");
|
||||
|
||||
// [2.1] Right-click on the TableHeadersRow() line to open the default table context menu.
|
||||
ImGui::TableHeadersRow();
|
||||
for (int row = 0; row < 4; row++)
|
||||
{
|
||||
ImGui::TableNextRow();
|
||||
for (int column = 0; column < COLUMNS_COUNT; column++)
|
||||
{
|
||||
// Submit dummy contents
|
||||
ImGui::TableSetColumnIndex(column);
|
||||
ImGui::Text("Cell %d,%d", column, row);
|
||||
ImGui::SameLine();
|
||||
|
||||
// Context Menu 2: right-click on buttons open Custom Button Popup
|
||||
// [2.2] Right-click on the ".." to open a custom popup
|
||||
ImGui::PushID(row * COLUMNS_COUNT + column);
|
||||
ImGui::SmallButton("..");
|
||||
if (ImGui::BeginPopupContextItem())
|
||||
{
|
||||
ImGui::Text("This is the popup for Button() On Cell %d,%d", column, row);
|
||||
ImGui::Selectable("Close");
|
||||
ImGui::Text("This is the popup for Button(\"..\") in Cell %d,%d", column, row);
|
||||
if (ImGui::Button("Close"))
|
||||
ImGui::CloseCurrentPopup();
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
}
|
||||
|
||||
// Context Menu 3: Right-click anywhere in columns opens a custom popup
|
||||
// We use the ImGuiPopupFlags_NoOpenOverExistingPopup flag to avoid displaying over either the standard TableHeader context-menu or the Button context-menu.
|
||||
// [2.3] Right-click anywhere in columns to open another custom popup
|
||||
// (instead of testing for !IsAnyItemHovered() we could also call OpenPopup() with ImGuiPopupFlags_NoOpenOverExistingPopup
|
||||
// to manage popup priority as the popups triggers, here "are we hovering a column" are overlapping)
|
||||
const int hovered_column = ImGui::TableGetHoveredColumn();
|
||||
for (int column = 0; column < COLUMNS_COUNT + 1; column++)
|
||||
{
|
||||
ImGui::PushID(column);
|
||||
if (hovered_column == column && ImGui::IsMouseReleased(1))
|
||||
ImGui::OpenPopup("MyPopup", ImGuiPopupFlags_NoOpenOverExistingPopup);
|
||||
if (hovered_column == column && !ImGui::IsAnyItemHovered() && ImGui::IsMouseReleased(1))
|
||||
ImGui::OpenPopup("MyPopup");
|
||||
if (ImGui::BeginPopup("MyPopup"))
|
||||
{
|
||||
if (column == COLUMNS_COUNT)
|
||||
ImGui::Text("This is the popup for unused space after the last column.");
|
||||
ImGui::Text("This is a custom popup for unused space after the last column.");
|
||||
else
|
||||
ImGui::Text("This is the popup for Column '%s'", ImGui::TableGetColumnName(column));
|
||||
ImGui::Selectable("Close");
|
||||
ImGui::Text("This is a custom popup for Column %d", column);
|
||||
if (ImGui::Button("Close"))
|
||||
ImGui::CloseCurrentPopup();
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
ImGui::PopID();
|
||||
@ -4289,6 +4326,7 @@ static void ShowDemoWindowTables()
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_Sortable", (unsigned int*)&flags, ImGuiTableFlags_Sortable);
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_MultiSortable", (unsigned int*)&flags, ImGuiTableFlags_MultiSortable);
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_NoSavedSettings", (unsigned int*)&flags, ImGuiTableFlags_NoSavedSettings);
|
||||
ImGui::CheckboxFlags("ImGuiTableFlags_ContextMenuInBody", (unsigned int*)&flags, ImGuiTableFlags_ContextMenuInBody);
|
||||
ImGui::Unindent();
|
||||
|
||||
ImGui::BulletText("Decoration:");
|
||||
|
Reference in New Issue
Block a user