1

How do I prevent clicking background when I click the IMGUI button (e.g. I click the translate button and also click the background)

enter image description here

薛潇宇
  • 31
  • 3

1 Answers1

2

Check whether ImGui wants to capture the mouse click using ImGui::GetIO().WantCaptureMouse. If it does then don't let the event propagate further.

void Application::handleInput(InputEvent event) {

        // don't pass mouse and keyboard presses further if an ImGui widget is active
        auto& io = ImGui::GetIO();
        if (io.WantCaptureMouse || io.WantCaptureKeyboard) {
            return;
        }

        // ... event processing
    }
}

ImGui FAQ: Q: How can I tell whether to dispatch mouse/keyboard to Dear ImGui or my application?

Jan Šimek
  • 656
  • 8
  • 21