Reputation: 11
How I can destroy imgui window by clicking X
void test::OnUIRender()
{
bool state;
ImGui::Begin("test_test", &state);
if (ImGui::Button("test"))
{
ImGui::DestroyContext();
}
ImGui::End();
}
Upvotes: 1
Views: 1441
Reputation: 519
You may try this logic. Same is used in imgui_demo.cpp
void test::OnUIRender(bool *p_open)
{
if (!ImGui::Begin("test_test", p_open))
{
ImGui::End();
return;
}
// ... window contents here
ImGui::Button("Button");
ImGui::End();
}
in your draw loop
bool show_Win = true;
while (render) {
// ...
ImGui::NewFrame();
// ...
if(showWin) OnUIRender(&showWin);
// ...
}
If window closed, ImGui will set showWin false, save it outside loop and use it to show/hide window in next frame. manually set it to true if you want to show window again
Upvotes: 0