- 1 year ago
Imgui create pop up box removing the grayed out focus screen
To create a pop-up box in ImGui (Dear ImGui) without the grayed-out focus screen, you can make use of ImGui's modal windows. Modal windows allow you to display a pop-up dialog box while preventing interaction with the rest of the user interface until the dialog is closed.
Here's an example of how you can create a pop-up box in ImGui without the grayed-out focus screen:
cppbool showPopup = true;
// Inside your ImGui rendering loop
ImGui::SetNextWindowSize(ImVec2(200, 100));
ImGui::SetNextWindowPosCenter(ImGuiCond_Appearing);
// Use ImGui::BeginPopupModal to create a modal pop-up window
if (showPopup) {
ImGui::OpenPopup("MyPopup");
}
if (ImGui::BeginPopupModal("MyPopup", &showPopup, ImGuiWindowFlags_NoCollapse)) {
// Display the content of the pop-up window
ImGui::Text("This is a pop-up window!");
if (ImGui::Button("Close")) {
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
In this example, we use the ImGui::BeginPopupModal
function to create the modal pop-up window. We pass the showPopup
variable as the second parameter to track the visibility of the pop-up.
The ImGui::SetNextWindowSize
and ImGui::SetNextWindowPosCenter
functions are used to set the size and position of the pop-up window. You can adjust these values according to your requirements.
Inside the ImGui::BeginPopupModal
block, you can place the content you want to display in the pop-up window. In this example, we have a simple text and a close button. When the close button is clicked, we close the current pop-up using ImGui::CloseCurrentPopup()
.
With this approach, the pop-up window will appear without graying out the rest of the UI, allowing the user to interact with it while the pop-up is open.
Remember to integrate this code within your ImGui rendering loop and handle the pop-up's visibility (showPopup
) appropriately based on your application's logic.