ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
58.86k stars 10.05k forks source link

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

Open parbo opened 3 years ago

parbo commented 3 years ago

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.

ocornut commented 3 years ago

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

parbo commented 3 years ago

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.

ocornut commented 3 years ago

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 commented 3 years ago

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

ocornut commented 3 years ago

Pushed a fix here: 91704b773e7e636dd83afdd2871a4fa17fa78863 Thank you!

ocornut commented 3 years ago

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 commented 3 years ago

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

eloimaduell commented 1 year ago

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 ?

cfillion commented 1 year ago

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.

eloimaduell commented 1 year ago

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 commented 1 year ago

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

VelocityRa commented 1 month ago

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?