Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeginPopupContextItem() fail to gain focus when it is called within a BeginChild() #4676

Closed
xhsu opened this issue Oct 26, 2021 · 3 comments
Closed

Comments

@xhsu
Copy link

xhsu commented Oct 26, 2021

Version/Branch of Dear ImGui:
Version: 1.86 WIP (18502)
Branch: master

Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Compiler: Visual Studio 2019 (MSVC 1929) with C++20
Operating System: Windows 10

My Issue/Question:
When I place a BeginPopupContextItem() inside a Child window, the menu appears but my mouse cannot click on it. It wouldn't disappear or select a random item when I click, it just won't get focus, hover, or receive any click message.
The program is not frozen, if you click anywhere else, the pop-up menu will disappear like normal.
Item can still be 'selected' if I use my arrow key on the keyboard, but hitting Enter key gets no result.
I googled and searched many closed issues in this repo, but nothing similar pops out.
Searched in FAQ, nothing pops out.

Screenshots/Video
(Have no screen-recording software...)
(My mouse cursor is located exactly at the 'D' part of the "Delete" word in the following screenshot. Sorry that Windows snap cannot include the cursor.)
2021-10-26

Standalone, minimal, complete and verifiable example:
Opened source repo.
Despite the name, it is a game modding tool, not a 'trainer' or something similar.

The code looks like this:
(If you were inspecting my repo, it's in CZeroEditor.cpp line 3000 (#pragma region CharacterTemplateModal))

ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 5.0f);
ImGui::BeginChild("ChildR", ImVec2(iModalContentWidth, 350), true, ImGuiWindowFlags_None);

[...]

bTreeNodeExpanded = ImGui::TreeNode(itszTemplate->c_str());
if (!bTreeNodeExpanded && ImGui::IsItemHovered())
	ImGui::SetTooltip("Right-click to delete.\nDrag and draw to reorder.");

if (!bTreeNodeExpanded && ImGui::BeginPopupContextItem(itszTemplate->c_str()))
{
	if (ImGui::MenuItem("Delete"))
	{
		[...] // Deletion thingy.
		ImGui::EndPopup();
	}
	ImGui::EndPopup();
}

[...]	// Drag and draw thingy.
if (bTreeNodeExpanded)
{
	fnDisplayTemplateWithOverrideInfo(Template);
	ImGui::TreePop();
}

ImGui::EndChild();
ImGui::PopStyleVar();

[Edit Oct 27: Add a screenshot]

@ocornut ocornut added the popups label Oct 26, 2021
@ocornut
Copy link
Owner

ocornut commented Oct 27, 2021

Hello,

If I use your code it works. There is something you are omitting which may be interfering (which is why the issue guidelines ask for a verifiable minimum repro).

PS: The EndPopup() call in the if (MenuItem()) {} block is incorrect but that's not your issue since your menu item is not accessible in the first place.

ImGui::BeginChild("ChildR", ImVec2(500, 350), true, ImGuiWindowFlags_None);
bool bTreeNodeExpanded = ImGui::TreeNode("hello");
if (!bTreeNodeExpanded && ImGui::IsItemHovered())
    ImGui::SetTooltip("Right-click to delete.\nDrag and draw to reorder.");
if (!bTreeNodeExpanded && ImGui::BeginPopupContextItem("Hello"))
{
    if (ImGui::MenuItem("Delete"))
    {
        //ImGui::EndPopup();
    }
    ImGui::EndPopup();
}

if (bTreeNodeExpanded)
{
    ImGui::Text("Hello");
    ImGui::TreePop();
}
ImGui::EndChild();

@ocornut
Copy link
Owner

ocornut commented Oct 27, 2021

Given the shading in your screenshot I noticed you may have an outer modal carrying the child window.
I could repro the issue by embedding your code in a modal and can confirm there is a bug.

@ocornut ocornut added the bug label Oct 27, 2021
ocornut added a commit that referenced this issue Oct 27, 2021
…xed IsWindowFocused()/IsWindowHovered() issues with childs inside popups. (#4676)(#4676, #4527)

Amend/fix 6b1e094f, fc4988f (Sep 24)
@ocornut
Copy link
Owner

ocornut commented Oct 27, 2021

Pushed a fix c363b6d
Thank you for reporting !

@ocornut ocornut closed this as completed Oct 27, 2021
actondev pushed a commit to actondev/imgui that referenced this issue Nov 26, 2021
…xed IsWindowFocused()/IsWindowHovered() issues with childs inside popups. (ocornut#4676)(ocornut#4676, ocornut#4527)

Amend/fix 6b1e094f, fc4988f (Sep 24)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants