imgui icon indicating copy to clipboard operation
imgui copied to clipboard

Popup windows do not disappear

Open Aarkham opened this issue 2 years ago • 1 comments

(you may also go to Demo>About Window, and click "Config/Build Information" to obtain a bunch of detailed information that you can paste here)

Version/Branch of Dear ImGui:

Version: 1.89.1 Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_opengl3.cpp, also in custom engine. Operating System: Windows

My Issue/Question:

I have a periodic table implementation with imgui and when I click in an element appears a pop up showing more information about that element.

Everything works fine, but I have seen that in the Windows List of the Metrics Debugger, the windows that are created for the popup do not disappear. Is this behavior the expected one?

Screenshots/Video

image

image

Standalone, minimal, complete and verifiable example: (see https://github.com/ocornut/imgui/issues/2261)

This is the code I'm using to show the pop up, You can find the complete code in https://github.com/Aarkham/ImPeriodicTable


void ShowPeriodicTable()
{
  ImGui::SetNextWindowPos(ImVec2(0.0f,0.0f),ImGuiCond_Appearing);
  ImGui::SetNextWindowSize(ImVec2(kWindowInitWidth,kWindowInitHeight),ImGuiCond_Appearing);
  if(ImGui::Begin("Test",nullptr/*,ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove/*|ImGuiWindowFlags_NoBackground*/))
    {
      ImGuiWindow* window = ImGui::GetCurrentWindow();

      float window_width=ImGui::GetWindowWidth();
      float window_height=ImGui::GetWindowHeight();

      ImGui::SetWindowFontScale(1.4f*window_width/kWindowInitWidth);

      float kElementWidth=(window_width-2.0f*kElementsColumns*kElementBorder-(kElementsColumns-1.0f)*kElementSeparation)/kElementsColumns;
      float kElementHeight=kElementWidth;

      if(!window->SkipItems)
        {
          for(const Element& element:kPeridicTable)
            {
              if(Button(element,kElementWidth,kElementHeight,window))
                {
                  ImGui::OpenPopup(element.m_Name);
                }
              if (ImGui::BeginPopupModal(element.m_Name,nullptr,ImGuiWindowFlags_AlwaysAutoResize))
                {
                  const float popup_width=window_width*0.7f;
                  const float popup_height=window_height*0.7f;
                  constexpr float button_width=190.f;
                  constexpr float button_height=60.f;

                  ImGui::BeginChild("popup",ImVec2(popup_width,popup_height));
                    ElementPopup(element);
                  ImGui::EndChild();

                  if (ImGui::Button("Ok", ImVec2(button_width,button_height)))
                    {
                      ImGui::CloseCurrentPopup();
                    }

                  ImGui::EndPopup();
                }
            }
        }

      ImGui::End();
    }
}

Aarkham avatar Dec 13 '22 17:12 Aarkham

Thank you for filling out the whole issue template! 💜

Everything works fine, but I have seen that in the Windows List of the Metrics Debugger, the windows that are created for the popup do not disappear. Is this behavior the expected one?

Yes, this is expected behavior. Dear ImGui remembers windows even when they're inactive.

It does this to ensure that they will appear in the same state if you start submitting them again. (EG: If the user hides and then shows a window, they ideally want it to reappear in the same location scrolled to the place where they last left off.)

Some ancillary data will be freed if the window is inactive for some time (1 minute by default), but as far as I'm aware windows are never completely forgotten until ImGui::Shutdown is called.

PathogenDavid avatar Dec 13 '22 18:12 PathogenDavid

Thanks David for your detailed, spot-on answer. Closing this!

ocornut avatar Jan 24 '23 17:01 ocornut