Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close popup without using ImGui::CloseCurrentPopup() #1137

Closed
colesnicov opened this issue May 7, 2017 · 4 comments
Closed

Close popup without using ImGui::CloseCurrentPopup() #1137

colesnicov opened this issue May 7, 2017 · 4 comments
Labels

Comments

@colesnicov
Copy link

Hello to everybody.

Is there a possibility to close the popup window on the way:

ImGui::OpenPopup("TEST");
ImGui::BeginPopupModal("TEST");
...
ImGui::EndPopup();


ImGui::Begin("___");
if(ImGui::Button("Close TEST popup", ImVec2(...)))
{
    // Here i want to close the popup with the name TEST
}
ImGui::End();
@colesnicov colesnicov changed the title Close popup without using ImGui::CloseCurrentPopup () Close popup without using ImGui::CloseCurrentPopup() May 7, 2017
@colesnicov
Copy link
Author

colesnicov commented May 8, 2017

Inspired from here: #249 and #528 but not #402 (comment)

I just added a boolean indice:

static bool test_open(true);

like this:

static bool test_open(true);

// Must be tested?
if(test_open){
    ImGui::OpenPopup("TEST");
}

ImGui::BeginPopupModal("TEST", &test_open);
...
ImGui::EndPopup();


ImGui::Begin("___");
if(ImGui::Button("Close TEST popup", ImVec2(...)))
{
    // Here i want to close the popup with the name TEST
    test_open = false;
}
ImGui::End();

@ocornut
Copy link
Owner

ocornut commented Aug 27, 2017

I would still like to add popup apis using ImGuiID (they'd have a behave very slightly differently because functions like ClosePopup() would need to scan the popup stack). Linking to #331 for reference.

@micb25
Copy link
Contributor

micb25 commented Nov 1, 2024

Hey, is there any news about a ClosePopup() function?

I want to implement a "Loading..." animation in my application via a modal popup. I have a global thread-safe counter (m_LoadingCounter) that gets increased when a thread starts to load a file and gets decreased when its done. Unfortunately, I need to track the status (opened/closed) of the popup manually. Short example:

// called every frame

if (m_LoadingCounter == 0 && !m_IsWindowOpen)
    return;

if (!m_IsWindowOpen) {
    ImGui::OpenPopup(WINDOW_TITLE_ID);
    m_IsWindowOpen = true;
}

// ...

if (ImGui::BeginPopupModal(WINDOW_TITLE_ID, nullptr, WINDOW_FLAGS)) {
    // ...
    if (m_LoadingCounter == 0) {
        ImGui::CloseCurrentPopup();
        m_IsWindowOpen = false;
    }
    ImGui::EndPopup();
}

This would be much easier with a ClosePopup() function, since it is not necessary to store the state of the popup in the application:

// called every frame

const bool windowOpen = ImGui::IsPopupOpen(WINDOW_TITLE_ID);

if (m_LoadingCounter == 0) {
    if (windowOpen)
        ImGui::ClosePopup(WINDOW_TITLE_ID);
    return;
}
    
if (!windowOpen)
    ImGui::OpenPopup(WINDOW_TITLE_ID);

// ...

if (ImGui::BeginPopupModal(WINDOW_TITLE_ID, nullptr, WINDOW_FLAGS)) {
    // ...
    ImGui::EndPopup();
}

@ocornut
Copy link
Owner

ocornut commented Nov 2, 2024

I will look into it but I think what’s missing here is a way to make a window modal without it being a popup. If you control both opening and closing it doesn’t have to be a popup. Modals are a bit ill designed currently. Linking to #402

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants