From 73917115a8e217b848a0b9f4680a671c90eb7b14 Mon Sep 17 00:00:00 2001 From: Borislav Stanimirov Date: Sun, 23 Aug 2015 22:52:47 +0300 Subject: [PATCH] Added flag showing whether the GUI wants text input Conflicts: imgui.cpp --- imgui.cpp | 14 +++++++++++--- imgui.h | 2 ++ imgui_demo.cpp | 1 + imgui_internal.h | 3 ++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 59c96e8c..fe89d187 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -128,8 +128,10 @@ // swap video buffer, etc. } - - after calling ImGui::NewFrame() you can read back 'io.WantCaptureMouse' and 'io.WantCaptureKeyboard' to tell if ImGui - wants to use your inputs. if it does you can discard/hide the inputs from the rest of your application. + - after calling ImGui::NewFrame() you can read back flags from the IO structure to tell how ImGui intends to use your inputs. + When 'io.WantCaptureMouse' or 'io.WantCaptureKeyboard' flags are set you may want to discard/hide the inputs from the rest of your application. + When 'io.WantInputsCharacters' is set to may want to notify your OS to popup an onscreen keyboard, if available. + API BREAKING CHANGES ==================== @@ -1901,8 +1903,9 @@ void ImGui::NewFrame() bool mouse_owned_by_application = mouse_earliest_button_down != -1 && !g.IO.MouseDownOwned[mouse_earliest_button_down]; g.IO.WantCaptureMouse = (!mouse_owned_by_application && g.HoveredWindow != NULL) || (!mouse_owned_by_application && mouse_any_down) || (g.ActiveId != 0) || (!g.OpenedPopupStack.empty()) || (g.CaptureMouseNextFrame); g.IO.WantCaptureKeyboard = (g.ActiveId != 0) || (g.CaptureKeyboardNextFrame); + g.IO.WantInputCharacters = ((g.InputTextState.Id != 0) && (g.InputTextState.Id == g.ActiveId)) || g.WantInputCharactersNextFrame; g.MouseCursor = ImGuiMouseCursor_Arrow; - g.CaptureMouseNextFrame = g.CaptureKeyboardNextFrame = false; + g.CaptureMouseNextFrame = g.CaptureKeyboardNextFrame = g.WantInputCharactersNextFrame = false; // If mouse was first clicked outside of ImGui bounds we also cancel out hovering. if (mouse_owned_by_application) @@ -2874,6 +2877,11 @@ void ImGui::CaptureMouseFromApp() GImGui->CaptureMouseNextFrame = true; } +void ImGui::CaptureInputCharactersFromApp() +{ + GImGui->WantInputCharactersNextFrame = true; +} + bool ImGui::IsItemHovered() { ImGuiWindow* window = GetCurrentWindow(); diff --git a/imgui.h b/imgui.h index 2dab96b3..3468231a 100644 --- a/imgui.h +++ b/imgui.h @@ -405,6 +405,7 @@ namespace ImGui IMGUI_API void SetMouseCursor(ImGuiMouseCursor type); // set desired cursor type IMGUI_API void CaptureKeyboardFromApp(); // manually enforce imgui setting the io.WantCaptureKeyboard flag next frame (your application needs to handle it). e.g. capture keyboard when your widget is being hovered. IMGUI_API void CaptureMouseFromApp(); // manually enforce imgui setting the io.WantCaptureMouse flag next frame (your application needs to handle it). + IMGUI_API void CaptureInputCharactersFromApp(); // manually enforce imgui setting the io.WantInputCharacters flag next frame (your application needs to handle it). // Helpers functions to access the MemAllocFn/MemFreeFn pointers in ImGui::GetIO() IMGUI_API void* MemAlloc(size_t sz); @@ -724,6 +725,7 @@ struct ImGuiIO bool WantCaptureMouse; // Mouse is hovering a window or widget is active (= ImGui will use your mouse input) bool WantCaptureKeyboard; // Widget is active (= ImGui will use your keyboard input) + bool WantInputCharacters; // Some text input widget is active, which will read input characters from the InputCharacters array. float Framerate; // Framerate estimation, in frame per second. Rolling average estimation based on IO.DeltaTime over 120 frames int MetricsAllocs; // Number of active memory allocations int MetricsRenderVertices; // Vertices output during last call to Render() diff --git a/imgui_demo.cpp b/imgui_demo.cpp index dfd85f3c..4e9d0ad8 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1343,6 +1343,7 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::Text("WantCaptureMouse: %s", io.WantCaptureMouse ? "true" : "false"); ImGui::Text("WantCaptureKeyboard: %s", io.WantCaptureKeyboard ? "true" : "false"); + ImGui::Text("WantInputCharacters: %s", io.WantInputCharacters ? "true" : "false"); ImGui::Button("Hover me\nto enforce\ninputs capture"); if (ImGui::IsItemHovered()) diff --git a/imgui_internal.h b/imgui_internal.h index 8c9b8ab2..3e13b7f8 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -394,6 +394,7 @@ struct ImGuiState float FramerateSecPerFrameAccum; bool CaptureMouseNextFrame; // explicit capture via CaptureInputs() sets those flags bool CaptureKeyboardNextFrame; + bool WantInputCharactersNextFrame; char TempBuffer[1024*3+1]; // temporary text buffer ImGuiState() @@ -456,7 +457,7 @@ struct ImGuiState memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame)); FramerateSecPerFrameIdx = 0; FramerateSecPerFrameAccum = 0.0f; - CaptureMouseNextFrame = CaptureKeyboardNextFrame = false; + CaptureMouseNextFrame = CaptureKeyboardNextFrame = WantInputCharactersNextFrame = false; } };