Reputation: 582
when creating a pop up modal in ImGui, I noticed that there is a grey overlay that appears over the rest of the application (to put the focus on the pop up I think).
However, I am wondering if there is a way for me to remove that gray overlay screen so that I can still interact with the rest of the application even when that modal is popped up. So the modal pops up but its not interferring with the rest of the application - just an information pop up to reflect the current speed until the user clicks OK to make the pop up go away.
This is the code I have for the modal window creation:
if (ImGui::BeginPopupModal("Speed Adjustment")) {
std::string speed_text = "You're adjusting the speed";
speed_text += "\n";
ImGui::Text(speed_text.c_str());
//list the current speed
std::string currSpeed= "This is the current speed: " + std::to_string(databse->camSpeed);
ImGui::Text(currSpeed.c_str());
ImGui::Spacing();
ImGui::NextColumn();
ImGui::Columns(1);
ImGui::Separator();
ImGui::NewLine();
ImGui::SameLine(GetWindowWidth() - 270);
//click ok when finished adjusting
if (ImGui::Button("OK finished adjusting", ImVec2(200, 0))) {
speedpopup= false;
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
Do I need to add certain flags for the beginPopupModal portion? If so, what flags should I use?
Thank you, any help is appreciated!
Upvotes: 1
Views: 8168
Reputation: 519
As per the documentation in imgui.h:659
Popups, Modals :
If you want to interact with the rest of the application even when popped up is shown better go with a regularImGui::Begin()
call. Even you can use with appropriate flags to center the window as needed.
static bool speedpopup = true;
if (speedpopup) {
if (ImGui::Begin("mypicker"))
{
std::string speed_text = "You're adjusting the speed";
speed_text += "\n";
ImGui::Text(speed_text.c_str());
//list the current speed
std::string currSpeed = "This is the current speed: ";
ImGui::Text(currSpeed.c_str());
ImGui::Spacing();
ImGui::NextColumn();
ImGui::Columns(1);
ImGui::Separator();
ImGui::NewLine();
ImGui::SameLine(270);
//click ok when finished adjusting
if (ImGui::Button("OK finished adjusting", ImVec2(200, 0))) {
speedpopup = false;
}
ImGui::End();
}
}
Helper function like this can define a custom Begin()
bool BeginCentered(const char* name)
{
ImGuiIO& io = ImGui::GetIO();
ImVec2 pos(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f);
ImGui::SetNextWindowPos(pos, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
ImGuiWindowFlags flags = ImGuiWindowFlags_NoMove
| ImGuiWindowFlags_NoDecoration
| ImGuiWindowFlags_AlwaysAutoResize
| ImGuiWindowFlags_NoSavedSettings;
return ImGui::Begin(name, nullptr, flags);
}
The imgui documentation are clear in the headers.
Upvotes: 3