首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ImGUI弹出,但不显示,而是执行代码

ImGUI弹出,但不显示,而是执行代码
EN

Stack Overflow用户
提问于 2022-09-14 20:23:52
回答 1查看 339关注 0票数 0

我正在使用ImGui制作一个程序,如果一个窗口上的输入在单击"OK“按钮后出现错误,我希望显示一个PopUp。它输入IF语句并执行代码,但是弹出窗口没有出现。

代码语言:javascript
复制
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();
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-19 09:31:21

当发生错误时,所显示的整个代码是否只运行一次?

ImGui::BeginPopupModal和相关的if块必须运行每个帧,否则弹出窗口将不会被绘制。就像这样:

代码语言:javascript
复制
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堆栈的同一级别。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73722798

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档