Skip to content

Commit

Permalink
Demo: amend Selectable() + BeginPopupContextItem() demo to maintain a…
Browse files Browse the repository at this point in the history
…nd update selection state when popup is open. (#6032)
  • Loading branch information
ocornut committed Jan 2, 2023
1 parent e5d5186 commit 156e0a8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion imgui_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3438,11 +3438,14 @@ static void ShowDemoWindowPopups()
// and BeginPopupContextItem() will use the last item ID as the popup ID.
{
const char* names[5] = { "Label1", "Label2", "Label3", "Label4", "Label5" };
static int selected = -1;
for (int n = 0; n < 5; n++)
{
ImGui::Selectable(names[n]);
if (ImGui::Selectable(names[n], selected == n))
selected = n;
if (ImGui::BeginPopupContextItem()) // <-- use last item id as popup id
{
selected = n;
ImGui::Text("This a popup for \"%s\"!", names[n]);
if (ImGui::Button("Close"))
ImGui::CloseCurrentPopup();
Expand Down

0 comments on commit 156e0a8

Please sign in to comment.