Skip to content

Commit 7355c84

Browse files
committed
Tweak EndGroup() to facilitate fixing #2550 later (currently should have no side-effect0. Demo: Add extra widget to status query test.
1 parent aca6ee1 commit 7355c84

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

imgui.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -6825,10 +6825,13 @@ void ImGui::EndGroup()
68256825

68266826
// If the current ActiveId was declared within the boundary of our group, we copy it to LastItemId so IsItemActive(), IsItemDeactivated() etc. will be functional on the entire group.
68276827
// It would be be neater if we replaced window.DC.LastItemId by e.g. 'bool LastItemIsActive', but would put a little more burden on individual widgets.
6828-
// (and if you grep for LastItemId you'll notice it is only used in that context.
6829-
if ((group_data.BackupActiveIdIsAlive != g.ActiveId) && (g.ActiveIdIsAlive == g.ActiveId) && g.ActiveId) // && g.ActiveIdWindow->RootWindow == window->RootWindow)
6828+
// Also if you grep for LastItemId you'll notice it is only used in that context.
6829+
// (The tests not symmetrical because ActiveIdIsAlive is an ID itself, in order to be able to handle ActiveId being overwritten during the frame.)
6830+
const bool group_contains_curr_active_id = (group_data.BackupActiveIdIsAlive != g.ActiveId) && (g.ActiveIdIsAlive == g.ActiveId) && g.ActiveId;
6831+
const bool group_contains_prev_active_id = !group_data.BackupActiveIdPreviousFrameIsAlive && g.ActiveIdPreviousFrameIsAlive;
6832+
if (group_contains_curr_active_id)
68306833
window->DC.LastItemId = g.ActiveId;
6831-
else if (!group_data.BackupActiveIdPreviousFrameIsAlive && g.ActiveIdPreviousFrameIsAlive) // && g.ActiveIdPreviousFrameWindow->RootWindow == window->RootWindow)
6834+
else if (group_contains_prev_active_id)
68326835
window->DC.LastItemId = g.ActiveIdPreviousFrame;
68336836
window->DC.LastItemRect = group_bb;
68346837

imgui_demo.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -1533,21 +1533,23 @@ static void ShowDemoWindowWidgets()
15331533
ImGui::RadioButton("Checkbox", &item_type, 2);
15341534
ImGui::RadioButton("SliderFloat", &item_type, 3);
15351535
ImGui::RadioButton("InputText", &item_type, 4);
1536-
ImGui::RadioButton("ColorEdit4", &item_type, 5);
1537-
ImGui::RadioButton("MenuItem", &item_type, 6);
1538-
ImGui::RadioButton("TreeNode (w/ double-click)", &item_type, 7);
1539-
ImGui::RadioButton("ListBox", &item_type, 8);
1536+
ImGui::RadioButton("InputFloat3", &item_type, 5);
1537+
ImGui::RadioButton("ColorEdit4", &item_type, 6);
1538+
ImGui::RadioButton("MenuItem", &item_type, 7);
1539+
ImGui::RadioButton("TreeNode (w/ double-click)", &item_type, 8);
1540+
ImGui::RadioButton("ListBox", &item_type, 9);
15401541
ImGui::Separator();
15411542
bool ret = false;
15421543
if (item_type == 0) { ImGui::Text("ITEM: Text"); } // Testing text items with no identifier/interaction
15431544
if (item_type == 1) { ret = ImGui::Button("ITEM: Button"); } // Testing button
15441545
if (item_type == 2) { ret = ImGui::Checkbox("ITEM: Checkbox", &b); } // Testing checkbox
15451546
if (item_type == 3) { ret = ImGui::SliderFloat("ITEM: SliderFloat", &col4f[0], 0.0f, 1.0f); } // Testing basic item
15461547
if (item_type == 4) { ret = ImGui::InputText("ITEM: InputText", &str[0], IM_ARRAYSIZE(str)); } // Testing input text (which handles tabbing)
1547-
if (item_type == 5) { ret = ImGui::ColorEdit4("ITEM: ColorEdit4", col4f); } // Testing multi-component items (IsItemXXX flags are reported merged)
1548-
if (item_type == 6) { ret = ImGui::MenuItem("ITEM: MenuItem"); } // Testing menu item (they use ImGuiButtonFlags_PressedOnRelease button policy)
1549-
if (item_type == 7) { ret = ImGui::TreeNodeEx("ITEM: TreeNode w/ ImGuiTreeNodeFlags_OpenOnDoubleClick", ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_NoTreePushOnOpen); } // Testing tree node with ImGuiButtonFlags_PressedOnDoubleClick button policy.
1550-
if (item_type == 8) { const char* items[] = { "Apple", "Banana", "Cherry", "Kiwi" }; static int current = 1; ret = ImGui::ListBox("ITEM: ListBox", &current, items, IM_ARRAYSIZE(items), IM_ARRAYSIZE(items)); }
1548+
if (item_type == 5) { ret = ImGui::InputFloat3("ITEM: InputFloat3", col4f); } // Testing multi-component items (IsItemXXX flags are reported merged)
1549+
if (item_type == 6) { ret = ImGui::ColorEdit4("ITEM: ColorEdit4", col4f); } // Testing multi-component items (IsItemXXX flags are reported merged)
1550+
if (item_type == 7) { ret = ImGui::MenuItem("ITEM: MenuItem"); } // Testing menu item (they use ImGuiButtonFlags_PressedOnRelease button policy)
1551+
if (item_type == 8) { ret = ImGui::TreeNodeEx("ITEM: TreeNode w/ ImGuiTreeNodeFlags_OpenOnDoubleClick", ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_NoTreePushOnOpen); } // Testing tree node with ImGuiButtonFlags_PressedOnDoubleClick button policy.
1552+
if (item_type == 9) { const char* items[] = { "Apple", "Banana", "Cherry", "Kiwi" }; static int current = 1; ret = ImGui::ListBox("ITEM: ListBox", &current, items, IM_ARRAYSIZE(items), IM_ARRAYSIZE(items)); }
15511553
ImGui::BulletText(
15521554
"Return value = %d\n"
15531555
"IsItemFocused() = %d\n"
@@ -1628,6 +1630,9 @@ static void ShowDemoWindowWidgets()
16281630
if (embed_all_inside_a_child_window)
16291631
ImGui::EndChild();
16301632

1633+
static char dummy_str[] = "This is a dummy field to be able to tab-out of the widgets above.";
1634+
ImGui::InputText("dummy", dummy_str, IM_ARRAYSIZE(dummy_str), ImGuiInputTextFlags_ReadOnly);
1635+
16311636
// Calling IsItemHovered() after begin returns the hovered status of the title bar.
16321637
// This is useful in particular if you want to create a context menu (with BeginPopupContextItem) associated to the title bar of a window.
16331638
static bool test_window = false;

0 commit comments

Comments
 (0)