Skip to content

Commit f9f3dd3

Browse files
okmatijacopybara-github
authored andcommitted
Fix ImGui input processing
PiperOrigin-RevId: 808555760 Change-Id: Ie443143d9c058058b99786e44f27715b05c9f8ed
1 parent d7500e0 commit f9f3dd3

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/experimental/toolbox/window.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ std::string Window::GetDropFile() {
130130
return tmp;
131131
}
132132

133-
Window::Status Window::ProcessEvents() {
133+
Window::Status Window::NewFrame() {
134134
SDL_Event event;
135135
while (SDL_PollEvent(&event)) {
136136
ImGui_ImplSDL2_ProcessEvent(&event);
@@ -158,6 +158,15 @@ Window::Status Window::ProcessEvents() {
158158
return should_exit_ ? kQuitting : kRunning;
159159
}
160160

161+
void Window::EndFrame() {
162+
// We use ImGui for input management in addition to GUI rendering so its
163+
// important to call ImGui::EndFrame even if we don't call ImGui::Render.
164+
// Note ImGui::Render internally calls ImGui::EndFrame, but so long as
165+
// ImGui::NewFrame has been called, ImGui::EndFrame may be called multiple
166+
// times; it will be a no-op.
167+
ImGui::EndFrame();
168+
}
169+
161170
void Window::Present() {
162171
// Filament (with the exception of WebGL) handles the swapchain internally.
163172
if (config_ != kFilamentVulkan && config_ != kFilamentOpenGL) {

src/experimental/toolbox/window.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ class Window {
5050
kQuitting,
5151
};
5252

53-
// Processes all pendings window events, returning the status of the window.
54-
Status ProcessEvents();
53+
// Processes all pendings window events and prepares ImGui for input handling
54+
// and GUI rendering. Returns the status of the window.
55+
Status NewFrame();
56+
57+
// Finalizes ImGui input handling. Must call NewFrame first.
58+
void EndFrame();
5559

5660
// Swaps and presents the window buffer.
5761
void Present();

0 commit comments

Comments
 (0)