imgui icon indicating copy to clipboard operation
imgui copied to clipboard

Docking: how to figure out if a docked tab becomes active/visible?

Open parbo opened this issue 3 years ago • 12 comments

Version/Branch of Dear ImGui:

Dear ImGui 1.84 WIP (18302)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201703
define: _WIN32
define: _WIN64
define: _MSC_VER=1928
define: _MSVC_LANG=201703
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000440
 DockingEnable
 ViewportsEnable
io.ConfigViewportsNoAutoMerge
io.ConfigViewportsNoDecoration
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60,0
io.BackendFlags: 0x00001C06
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasViewports
--------------------------------
io.Fonts: 7 fonts, Flags: 0x00000000, TexSize: 4096,4096
io.DisplaySize: 2560,00,1377,00
io.DisplayFramebufferScale: 1,00,1,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

My Issue/Question:

In the docking branch, is there a way to figure out if a docked window (i.e. a tab) became active/visible? ImGui::IsWindowAppearing() does not seem to work for that.

parbo avatar May 28 '21 13:05 parbo

Hello, Please define "active/visible" and why IsWindowAppearing() doesn't work for you.

ocornut avatar May 28 '21 14:05 ocornut

When opening a window in a dockspace by calling ImGui::SetNextWindowDockId before ImGui::Begin, then ImGui::IsWindowAppearing doesn't return true. Also, I had expected that switching between tabs in a dockspace would ImGui::IsWindowAppearing to become true as the tab becomes active, but it doesn't afaict. And if that is intended, then I think there should be some other API to know that a docked window in a tab became visible.

parbo avatar May 31 '21 08:05 parbo

The reason I asked the question is that there are situations we may want a different appearing condition that the one you mention here, and specifically #2283 wants a different one and couldn't obtain it. And I assumed it was still the case.

But what I'm seeing right now after testing is that we "accidentally" solved #2283 but what you mention - which is the most desirable behavior ihmo - is now broken. So there's a bug (maybe recent?) indeed, will investigate.

ocornut avatar May 31 '21 11:05 ocornut

Amusingly this case got broken by: Fix IsWindowAppearing() from returning true twice in most cases. (#3982, #1497, #1061) 84e6fe4fc741983824955aaba6fb8203be6c778e

ocornut avatar May 31 '21 11:05 ocornut

Pushed a fix here: 91704b773e7e636dd83afdd2871a4fa17fa78863 Thank you!

ocornut avatar May 31 '21 15:05 ocornut

This is a more complex than expected, because they are cases were IsWindowAppearing() would return true while Begin() returned false, meaning users may not submit contents. We are working on it.

ocornut avatar Jun 03 '21 13:06 ocornut

Pushed two extra commits which should fix the issues we encountered.

Also added a sanity assert to ensure that Begin() never returns false when the Appearing flag is set.

appearing_tests

ocornut avatar Jun 03 '21 14:06 ocornut

I've been asking myself if I should do ask here my question or not, as far as I'm not a great expert on ImGui docking windows and in ImGui in general, but I decided to do so, so forgive me if this is already answered or solved or if my question does not makes sense...

I would like to know if there is way of detecting if a docked window on tabs is "visible". So if I've 3 windows tabbed as here :

Screenshot 2023-01-01 at 16 59 19

There is some mouse interaction within those windows, which actually are all of the same "type". What it happens is that the mouse interaction is being triggered on all 3 windows even just one of them is visible. I was trying to understand if there is a way to avoid this.

I got to understand that even windows are docked/tabbed and maybe they are not "visible", they are being "drawn" and receiving the mouse interaction and so the interaction is being triggered on all 3 windows. I thought I could find a way of knowing if the window/tab is actually visible and so avoid the interaction to happen on hidden tabs.

Is there any other solution then detecting if the GetMousePress happened on a "focused" window ? Or how should I think about this issue properly to solve this unwanted behaviour ?

eloimaduell avatar Jan 01 '23 15:01 eloimaduell

I would like to know if there is way of detecting if a docked window on tabs is "visible".

The Begin() calls of the inactive windows returns false.

cfillion avatar Jan 01 '23 16:01 cfillion

Thanks @cfillion

So I might have something wrong on my end as I do already have an if(Begin()...) before calling the draw function and doing the mouse interaction... I've checked that I'm doing in any case the ImGui::End(); (as seen in the documentation) ... so not sure if maybe there is a flag needed to have this "false return" if inactive window/tab?

I'm printing the window to the console inside the window code and even if they are all docked/tabbed, the 3 names are printed all the time.... ?¿

Any idea why my Begin() call is not returning false for my "ASTRES Rectangular2" and "ASTRES Rectangular3" ?

Screenshot 2023-01-01 at 16 59 19

eloimaduell avatar Jan 01 '23 16:01 eloimaduell

Just to specify it ... I'm running on :// dear imgui, v1.87 WIP

eloimaduell avatar Jan 01 '23 16:01 eloimaduell

I have the same issues. Begin() returns true on the non-visible tabs too, though only on the first frame. @eloimaduell or someone, did you find a solution?

VelocityRa avatar Jul 03 '24 19:07 VelocityRa