Skip to content

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

@gaborodriguez

Description

@gaborodriguez

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");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions