【发布时间】:2020-06-29 06:32:53
【问题描述】:
我在我的 UI 应用程序中使用 ImGui。我的问题是当我按下按钮时,'if condition' 中的代码将执行。但是一旦我按下按钮,我就无法按下其他按钮,包括按下的按钮。谁能告诉我是什么问题?
示例代码:
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;
}
}
【问题讨论】:
-
你的百万次打印需要很长时间才能执行,gui 大概会冻结,直到它们完成
-
我知道如何克服这个冻结,我尝试使用线程但仍然有同样的问题,
-
删除百万张照片?
-
在 GUI 线程上工作会在我知道的每个 GUI 框架中冻结 GUI,直到工作完成
-
请显示minimal reproducible example(stackoverflow.com/help/mcve)。您说的是两个按钮,但代码只包含一个。
标签: c++ user-interface opengl glfw imgui