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

Using more than one Begin/EndChild for the same window breaks IsItemHovered() #8350

Closed
gaborodriguez opened this issue Jan 27, 2025 · 4 comments
Labels

Comments

@gaborodriguez
Copy link

Version/Branch of Dear ImGui:

v1.91.3-docking

Back-ends:

custom

Compiler, OS:

Win10 + Clang & MSVC

Full config/build information:

Dear ImGui 1.91.3 (19130)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 4, sizeof(ImDrawVert): 20
define: __cplusplus=201703
define: IMGUI_DISABLE_OBSOLETE_FUNCTIONS
define: IMGUI_DISABLE_OBSOLETE_KEYIO
define: _WIN32
define: _WIN64
define: _MSC_VER=1939
define: _MSVC_LANG=201703
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: NULL
io.BackendRendererName: NULL
io.ConfigFlags: 0x00000480
 DockingEnable
 ViewportsEnable
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C01
 HasGamepad
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasViewports
--------------------------------
io.Fonts: 21 fonts, Flags: 0x00000000, TexSize: 1024,4096
io.DisplaySize: 1517.00,816.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,4.00
style.FrameRounding: 2.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 4.00,2.00
style.ItemInnerSpacing: 4.00,4.00

Details:

When using more than one Begin/EndChild pair for the same window a call to IsItemHovered() doesn't return true when that window is hovered. The hovering or last item state seems to be reflecting the item created before the last Begin/EndChild pair.

For example, this code results in the GIF below

ImGui::BeginChild("My Window", ImVec2(200, 100));
ImGui::EndChild();

ImGui::Button("Button");

ImGui::BeginChild("My Window", ImVec2(200, 100));
ImGui::EndChild();

if (ImGui::IsItemHovered()) {
    ImGui::SetTooltip("I Expected My Window");
}

Image

I would expect IsItemHovered() to refer to the window and not the button, is that not the case?

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

ImGui::BeginChild("My Window", ImVec2(200, 100));
ImGui::EndChild();

ImGui::Button("Button");

ImGui::BeginChild("My Window", ImVec2(200, 100));
ImGui::EndChild();

if (ImGui::IsItemHovered()) {
    ImGui::SetTooltip("I Expected My Window");
}
@ocornut ocornut added the bug label Jan 27, 2025
@GamingMinds-DanielC
Copy link
Contributor

Isn't that what IsWindowHovered() is for?

ocornut added a commit that referenced this issue Jan 27, 2025
…f EndChild(). (#8350)

Also made some of the fields accessible after BeginChild() to match Begin() logic.
@ocornut
Copy link
Owner

ocornut commented Jan 27, 2025

Isn't that what IsWindowHovered() is for?

It would indeed be an alternative.

But append version of EndChild() wasn't filled item data.
Thank you for your report. I have now pushed a fix 134fbe1 for this to be more consistent.

I'd like to keep this open as I would want to write more tests and explorer a few corner cases further.

@ocornut
Copy link
Owner

ocornut commented Jan 27, 2025

Adding link to #7506

ocornut added a commit to ocornut/imgui_test_engine that referenced this issue Jan 27, 2025
@ocornut
Copy link
Owner

ocornut commented Jan 27, 2025

I have amended the logic with a05d547 and added some basic tests ocornut/imgui_test_engine@7b68d89

This is not what you asked about but I also needed to clarify the return value of IsItemXXX right after BeginChild(). This is specced as returning title bar data for normal windows and not defined for child windows. I wanted to keep the possibility of adding title bars to child windows (I have a task for this actually) and thus intentionally made it that IsItemXXX after BeginChild() will still return false.

But IsItemXXX AFTER EndChild() non-ambiguously refer to the child window as a single item layed out in parent window, and those two commits fixes the issue reported.

@ocornut ocornut closed this as completed Jan 27, 2025
github-actions bot pushed a commit to Kreuterhack/imgui that referenced this issue Jan 28, 2025
…f EndChild(). (ocornut#8350)

Also made some of the fields accessible after BeginChild() to match Begin() logic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants