-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
PopupModal not appearing #8272
Comments
Chances are you're opening the popup in a different ID context from where The way I've solved this sort of issue in the past is to add a |
Hello, I've tried this but now it is not logging anything in the ImGui Debug Log either. Should I call Here are the changes: class myclass {
struct Popup {
const char* title;
const char* text;
const char* btn1;
const char* btn2;
bool shouldOpen;
};
static Popup* activePopup = nullptr;
static void drawAlerts()
{
if(activePopup == nullptr) return;
if(activePopup->shouldOpen)
{
ImGui::OpenPopup(activePopup->title);
activePopup->shouldOpen = false;
}
ImGui::SetNextWindowSize(ImVec2(0, ImGui::CalcTextSize(activePopup->text).x));
ImGui::SetNextWindowPos({
ImGui::GetIO().DisplaySize.x / 2,
ImGui::GetIO().DisplaySize.y / 2
}, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
if(ImGui::BeginPopupModal(activePopup->title, NULL, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize))
{
AlignForWidth(ImGui::GetCurrentWindow()->SizeFull.x);
ImGui::Text(activePopup->text);
ImGui::Separator();
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
ImGui::SetNextItemWidth(activePopup->btn2 != nullptr ? ImGui::GetCurrentWindow()->SizeFull.x / 2 : ImGui::GetCurrentWindow()->SizeFull.x);
if(ImGui::Button(activePopup->btn1)) { ImGui::CloseCurrentPopup(); activePopup->text = activePopup->title = activePopup->btn1 = activePopup->btn2 = nullptr; }
if(activePopup->btn2 != nullptr)
{
ImGui::SameLine();
ImGui::SetNextItemWidth(activePopup->btn2 != nullptr ? ImGui::GetCurrentWindow()->SizeFull.x / 2 : ImGui::GetCurrentWindow()->SizeFull.x);
if(ImGui::Button(activePopup->btn2)) { ImGui::CloseCurrentPopup(); activePopup->text = activePopup->title = activePopup->btn1 = activePopup->btn2 = nullptr; }
}
ImGui::PopStyleColor();
ImGui::EndPopup();
}
}
static void alert(const char* title, const char* text, const char* btn1, const char* btn2 = nullptr, const std::function<void()>& callback = [](){})
{
activePopup = new Popup(title, text, btn1, btn2, true);
}
}; |
Version/Branch of Dear ImGui:
Version 1.91.5, Branch: master
Back-ends:
n/a
Compiler, OS:
Windows 11 + CMake
Full config/build information:
No response
Details:
Hello!
I am trying to make a custom popup modal. In order to keep things organized, I made a class function for making and drawing it.
alert()
initializes a class variable (Popup* activePopup
) that holds the popup infodrawAlerts()
draws the popup that has been createdI do call drawAlerts in my draw function but it seems it is not appearing, did I do something wrong? How can I improve the system?
Screenshots/Video:
Popup functions:
Popup variable:
Minimal, Complete and Verifiable Example code:
The text was updated successfully, but these errors were encountered: