Fix ImGui input processing

PiperOrigin-RevId: 808555760
Change-Id: Ie443143d9c058058b99786e44f27715b05c9f8ed
This commit is contained in:
Matija Kecman
2025-09-18 06:41:21 -07:00
committed by Copybara-Service
parent d7500e0dec
commit f9f3dd3c1d
2 changed files with 16 additions and 3 deletions
+10 -1
View File
@@ -130,7 +130,7 @@ std::string Window::GetDropFile() {
return tmp;
}
Window::Status Window::ProcessEvents() {
Window::Status Window::NewFrame() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
ImGui_ImplSDL2_ProcessEvent(&event);
@@ -158,6 +158,15 @@ Window::Status Window::ProcessEvents() {
return should_exit_ ? kQuitting : kRunning;
}
void Window::EndFrame() {
// We use ImGui for input management in addition to GUI rendering so its
// important to call ImGui::EndFrame even if we don't call ImGui::Render.
// Note ImGui::Render internally calls ImGui::EndFrame, but so long as
// ImGui::NewFrame has been called, ImGui::EndFrame may be called multiple
// times; it will be a no-op.
ImGui::EndFrame();
}
void Window::Present() {
// Filament (with the exception of WebGL) handles the swapchain internally.
if (config_ != kFilamentVulkan && config_ != kFilamentOpenGL) {
+6 -2
View File
@@ -50,8 +50,12 @@ class Window {
kQuitting,
};
// Processes all pendings window events, returning the status of the window.
Status ProcessEvents();
// Processes all pendings window events and prepares ImGui for input handling
// and GUI rendering. Returns the status of the window.
Status NewFrame();
// Finalizes ImGui input handling. Must call NewFrame first.
void EndFrame();
// Swaps and presents the window buffer.
void Present();