Browse Source

Added flag showing whether the GUI wants text input

Conflicts:
	imgui.cpp
Borislav Stanimirov 10 years ago
parent
commit
73917115a8
4 changed files with 16 additions and 4 deletions
  1. 11 3
      imgui.cpp
  2. 2 0
      imgui.h
  3. 1 0
      imgui_demo.cpp
  4. 2 1
      imgui_internal.h

+ 11 - 3
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();

+ 2 - 0
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()

+ 1 - 0
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())

+ 2 - 1
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;
     }
 };