ocornut / imgui

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

Secondary window within modal #7202

Open PapaNaxos opened 6 months ago

PapaNaxos commented 6 months ago

Version/Branch of Dear ImGui:

Version 1.90, Branch:docking

Back-ends:

imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp

Compiler, OS:

rhel8 + GCC 8.5.0

Full config/build information:

Dear ImGui 1.90 WIP (18993)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201103
define: __linux__
define: __GNUC__=8
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000C41
 NavEnableKeyboard
 DockingEnable
 ViewportsEnable
io.ConfigViewportsNoDecoration
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000140E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,128
io.DisplaySize: 1920.00,1011.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,5.00
style.FrameRounding: 2.00
style.FrameBorderSize: 1.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Details:

My Issue/Question:

What I'm trying to achieve is having a second window/popup open while using a modal popup. The purpose of this secondary window/popup is to provide help information for the user while they use the UI provided by the modal window.

Ideally, the help window would have the following properties:

So approximately the structure of the UI would be something like:

I managed to achieve a subset of this functionality with the following code:

if (ImGui::BeginPopupModal(...))
{
    // Stuff in modal
    if (ImGui::Button("Help")) ImGui::OpenPopup("Help Window");

    ImGuiID id = ImGui::GetCurrentWindow()->GetID("Help Window");
    int flags = ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoCollapse;
    if (ImGui::BeginPopupEx(id, flags))
    {
        // help contents
        ImGui::EndPopup();
    }
    ImGui::EndPopup();
}

This achieves:

But fails to achieve:

The features marked with *()** are desirable, but not essential. However, I'd very much like for the help window to stay open when interacting with the primary modal UI.

Is there any way to achieve this with the normal API, or perhaps some small modifications/additions to the IMGUI source I can make?

Screenshots/Video:

Screenshot from 2024-01-05 19-42-44

Minimal, Complete and Verifiable Example code:

No response

PapaNaxos commented 6 months ago

I have made a bit more progress. I can now stop the the popup from closing when using the primary modal.

I had to add to the window flags enum in imgui.h

ImGuiWindowFlags_ModalSecondary = 1 << 30

And add the following lines to ImGui::ClosePopupsOverWindow

if (popup.Window->Flags & ImGuiWindowFlags_ModalSecondary)
        continue;

which is directly after:

if (popup.Window->Flags & ImGuiWindowFlags_ChildWindow)
    continue;

And call my help window including the new ImGuiWindowFlags_ModalSecondary flag

This works, but has a few issues:

I don't like having to modify ImGui code, but did not see an alternative (especially having to use one of the ImGuiWindowFlags_ which is nearly full, so future updates may use up these flag spots).

Definitely open to suggestions on how to improve / fix the remaining issues. Thanks!

PapaNaxos commented 6 months ago

Another issue is that comboboxes will also cause the secondary help window to close.