Skip to content

Clicking on disabled item doesn't set focus to containing window #8064

Closed
@geertbleyen

Description

Version/Branch of Dear ImGui:

Version 1.90.9, Branch: docking

Back-ends:

imgui_impl_osx.mm + imgui_impl_win32.cpp

Compiler, OS:

Windows11, VS2022; MacOS 15.0, Xcode16

Full config/build information:

Dear ImGui 1.90.8 (19080)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201402
define: __APPLE__
define: __GNUC__=4
define: __clang_version__=16.0.0 (clang-1600.0.26.3)
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_osx
io.BackendRendererName: imgui_impl_metal
io.ConfigFlags: 0x00000443
 NavEnableKeyboard
 NavEnableGamepad
 DockingEnable
 ViewportsEnable
io.ConfigViewportsNoDecoration
io.ConfigMacOSXBehaviors
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000140A
 HasMouseCursors
 PlatformHasViewports
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1200.00,720.00
io.DisplayFramebufferScale: 2.00,2.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Details:

We are creating a node editor, and these nodes have an editable title. However, by default, this is a disabled TextInput and the node can be dragged by click+drag on the title as well. However, doing so does not set window focus on the nodeeditor window. I understand and agree that clicking disabled items shouldn't be navigated to, or be activatable, but I'd still expect the containing window gaining focus when clicking on an item inside of it.
Is it intentional that this doesn't happen?

As a quick experiment I hacked following code into ImGui::ButtonBehavior

...
if (flatten_hovered_children)
    g.HoveredWindow = backup_hovered_window;

// new:  here we handle clicking on disabled items to set focus to containing window
if (g.HoveredIdDisabled && g.HoveredId == id)
    {
    int mouse_button_clicked = -1;
    int mouse_button_released = -1;
    const ImGuiID test_owner_id = (flags & ImGuiButtonFlags_NoTestKeyOwner) ? ImGuiKeyOwner_Any : id;
    for (int button = 0; button < 3; button++)
      {
        if (flags & (ImGuiButtonFlags_MouseButtonLeft << button)) // Handle ImGuiButtonFlags_MouseButtonRight and ImGuiButtonFlags_MouseButtonMiddle here.
          {
            if (IsMouseClicked(button, ImGuiInputFlags_None, test_owner_id) && mouse_button_clicked == -1) { mouse_button_clicked = button; }
            if (IsMouseReleased(button, test_owner_id) && mouse_button_released == -1) { mouse_button_released = button; }
          }
      }
    if (mouse_button_released == 0)
        FocusWindow(window);
    }

// Mouse handling
const ImGuiID test_owner_id = (flags & ImGuiButtonFlags_NoTestKeyOwner) ? ImGuiKeyOwner_Any : id;
if (hovered)
{
...

And this makes it 'work' for button-like item (checkbox etc...). I'm assume similar changes would be required to other widget categories (textinput, ...?)

However, it may be intentional that it doesn't work like that at the moment, and a different approach may be better?

Any advice is appreciated on this.

Screenshots/Video:

Screen.Recording.2024-10-15.at.15.48.37.mov

Minimal, Complete and Verifiable Example code:

No response

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions