我正在使用ImGui制作一个程序,如果一个窗口上的输入在单击"OK“按钮后出现错误,我希望显示一个PopUp。它输入IF语句并执行代码,但是弹出窗口没有出现。
ImGui::OpenPopup("Error Creating Image");
// Always center this window when appearing
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
if (ImGui::BeginPopupModal("Error Creating Image", NULL, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::SetItemDefaultFocus();
ImGui::Text("The size of the Image must be greater than 0. Also it need to have a name!\n\n");
ImGui::Separator();
if (ImGui::Button("OK")) {
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}发布于 2022-09-19 09:31:21
当发生错误时,所显示的整个代码是否只运行一次?
ImGui::BeginPopupModal和相关的if块必须运行每个帧,否则弹出窗口将不会被绘制。就像这样:
void foo() { // 'foo' runs every frame.
if (ImGui::Button("Show popup"))
ImGui::OpenPopup("ThePopup");
// Maybe some other stuff here.
if (ImGui::BeginPopupModal("ThePopup")) {
// Draw popup contents.
ImGui::EndPopup();
}
}绘制弹出窗口的代码可以移动到任何地方,只要它位于ID堆栈的同一级别。
https://stackoverflow.com/questions/73722798
复制相似问题