首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ImGui按钮自由切换

ImGui按钮自由切换
EN

Stack Overflow用户
提问于 2020-06-29 14:32:53
回答 1查看 1K关注 0票数 0

我在我的UI应用程序中使用了ImGui。我的问题是,当我按下按钮时,'if condition‘里面的代码就会执行。但一旦我按下按钮,我就不能按下其他按钮,包括按下的按钮。有谁能告诉我出了什么问题吗?

示例代码:

代码语言:javascript
复制
while(window)

{
    // Poll and handle events (inputs, window resize, etc.)
    // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
    // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
    // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
    // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
    glfwPollEvents();

    // Start the Dear ImGui frame
    ImGui_ImplOpenGL3_NewFrame();
    ImGui_ImplGlfw_NewFrame();
    ImGui::NewFrame();

    // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
    if (show_demo_window)
        ImGui::ShowDemoWindow(&show_demo_window);

    // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
    {
        static float f = 0.0f;
        static int counter = 0;

        ImGui::Begin("Hello, world!");                          // Create a window called "Hello, world!" and append into it.

        ImGui::Text("This is some useful text.");               // Display some text (you can use a format strings too)
        ImGui::Checkbox("Demo Window", &show_demo_window);      // Edit bools storing our window open/close state
        ImGui::Checkbox("Another Window", &show_another_window);

        ImGui::SliderFloat("float", &f, 0.0f, 1.0f);            // Edit 1 float using a slider from 0.0f to 1.0f
        ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color

        if (ImGui::Button("Button"))                            // Buttons return true when clicked (most widgets return true when edited/activated)

        {

            for (int i = 0; i < 1000000; i++)

            {
                cout << i;
            }
           
        }
EN

回答 1

Stack Overflow用户

发布于 2020-10-20 20:57:39

即时模式GUI并不意味着所有的工作都可以在GUI线程中完成。

您可以在按下按钮时触发要完成的操作。我建议只更新UI和gui渲染循环中的简单逻辑,所有的处理都应该移动到runner类型的线程。假设渲染循环周期的执行时间保持为1/renderFPS的四分之一

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

https://stackoverflow.com/questions/62632440

复制
相关文章

相似问题

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