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

No way i can render popup modal #3051

Closed
fuhranku opened this issue Mar 9, 2020 · 3 comments
Closed

No way i can render popup modal #3051

fuhranku opened this issue Mar 9, 2020 · 3 comments
Labels
label/id and id stack implicit identifiers, pushid(), id stack popups

Comments

@fuhranku
Copy link

fuhranku commented Mar 9, 2020

Greetings. I'm working with OpenGl 3.30 w/ C++

Version/Branch of Dear ImGui:

Version: 1.74
Branch: master

My Issue/Question:

Modal is not showing under any circumstances. I've read issue #331 and working examples here exposed are not working for me either. A simple case like this won't show anything at all

I initialize ImGui like this:`

bool UI::init(GLFWwindow* window) {
	IMGUI_CHECKVERSION();
	ImGui::CreateContext();
	if (!ImGui_ImplGlfw_InitForOpenGL(window, true) || !ImGui_ImplOpenGL3_Init("#version 330 core"))
		return false;
	ImGui::StyleColorsDark();
}

My draw function:

void UI::draw() {
	// Start new frame
	ImGui_ImplOpenGL3_NewFrame();
	ImGui_ImplGlfw_NewFrame();
	ImGui::NewFrame();

       // This basic example shows nothing for me
        if (ImGui::BeginMainMenuBar())
        {
            if (ImGui::BeginMenu("menu"))
            {
                if (ImGui::MenuItem("menu item"))
                   ImGui::OpenPopup("popup");
                ImGui::EndMenu();
            }
            ImGui::EndMainMenuBar();
        }

        if (ImGui::BeginPopupModal("popup"))
        {
            ImGui::Text("Lorem ipsum");
            ImGui::EndPopup();
        }

	ImGui::Render();
	ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}


I've been reading all related issues but apparently it should render my modal with this case, and is not working. Everything else works just fine.

@ocornut
Copy link
Owner

ocornut commented Mar 9, 2020

Hello,

It seems like you missed the key explanation and solution outlined in #331, e.g.
#331 (comment)

You have to remember that OpenPopup() and BeginPopup() are relying on the ID stack:

https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-why-are-multiple-widgets-reacting-when-i-interact-with-a-single-one-q-how-can-i-have-multiple-widgets-with-the-same-label-or-with-an-empty-label

So in your example you are doing the Open while the top of ID stack is "mainmenubar" "menu" and you are trying to Begin into it while the top of the ID stack is empty, so the ID don't match.

@ocornut ocornut added the popups label Mar 9, 2020
@fuhranku
Copy link
Author

fuhranku commented Mar 9, 2020

Hello! Thank you for this quick answer! Now i'm trying with boolean flag workaround and it's working now (it seems i did miss key explanation), to be honest ID stack still not 100% clear for me, i'll be diggin more into it.

Thank you, hopping a smooth and fancy workaround for modals :-)

@ocornut
Copy link
Owner

ocornut commented Mar 9, 2020

I'll let you read the linked FAQ, if you still have issue or questions feel free to post here!

@ocornut ocornut closed this as completed Mar 9, 2020
@ocornut ocornut added the label/id and id stack implicit identifiers, pushid(), id stack label Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
label/id and id stack implicit identifiers, pushid(), id stack popups
Projects
None yet
Development

No branches or pull requests

2 participants