diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 6dfcccd38..b2242e12d 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -36,8 +36,19 @@ HOW TO UPDATE? Breaking changes: +- IO: Obsoleted io.ClearInputCharacters() (added in 1.47) as it now ambiguous + and often incorrect/misleading considering the existence of a higher-level + input queue. (#4921) + Other changes: +- IO: Added io.ClearEventsQueue() to clear incoming inputs events. (#4921) + May be useful in conjunction with io.ClearInputsKeys() if you need to clear + both current inputs state and queued events (e.g. when using blocking native + dialogs such as Windows's ::MessageBox() or ::GetOpenFileName()). +- IO: Changed io.ClearInputsKeys() specs to also clear current frame character buffer + (what now obsoleted io.ClearInputCharacters() did), as this is effectively the + desirable behavior. - Demo: Better showcase use of SetNextItemAllowOverlap(). (#6574, #6512, #3909, #517) diff --git a/imgui.cpp b/imgui.cpp index f6b98168f..5847d7b9f 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1341,13 +1341,15 @@ void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars) } } -// FIXME: Perhaps we could clear queued events as well? -void ImGuiIO::ClearInputCharacters() +// Clear all incoming events. +void ImGuiIO::ClearEventsQueue() { - InputQueueCharacters.resize(0); + IM_ASSERT(Ctx != NULL); + ImGuiContext& g = *Ctx; + g.InputEventsQueue.clear(); } -// FIXME: Perhaps we could clear queued events as well? +// Clear current keyboard/mouse/gamepad state + current frame text input buffer. Equivalent to releasing all keys/buttons. void ImGuiIO::ClearInputKeys() { #ifndef IMGUI_DISABLE_OBSOLETE_KEYIO @@ -1368,8 +1370,18 @@ void ImGuiIO::ClearInputKeys() MouseDownDuration[n] = MouseDownDurationPrev[n] = -1.0f; } MouseWheel = MouseWheelH = 0.0f; + InputQueueCharacters.resize(0); // Behavior of old ClearInputCharacters(). } +// Removed this as it is ambiguous/misleading and generally incorrect to use with the existence of a higher-level input queue. +// Current frame character buffer is now also cleared by ClearInputKeys(). +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS +void ImGuiIO::ClearInputCharacters() +{ + InputQueueCharacters.resize(0); +} +#endif + static ImGuiInputEvent* FindLatestInputEvent(ImGuiContext* ctx, ImGuiInputEventType type, int arg = -1) { ImGuiContext& g = *ctx; diff --git a/imgui.h b/imgui.h index f6aa69f82..36572cc51 100644 --- a/imgui.h +++ b/imgui.h @@ -25,7 +25,7 @@ // Library Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345') #define IMGUI_VERSION "1.89.8 WIP" -#define IMGUI_VERSION_NUM 18971 +#define IMGUI_VERSION_NUM 18972 #define IMGUI_HAS_TABLE /* @@ -2058,8 +2058,11 @@ struct ImGuiIO IMGUI_API void SetKeyEventNativeData(ImGuiKey key, int native_keycode, int native_scancode, int native_legacy_index = -1); // [Optional] Specify index for legacy <1.87 IsKeyXXX() functions with native indices + specify native keycode, scancode. IMGUI_API void SetAppAcceptingEvents(bool accepting_events); // Set master flag for accepting key/mouse/text events (default to true). Useful if you have native dialog boxes that are interrupting your application loop/refresh, and you want to disable events being queued while your app is frozen. - IMGUI_API void ClearInputCharacters(); // [Internal] Clear the text input buffer manually - IMGUI_API void ClearInputKeys(); // [Internal] Release all keys + IMGUI_API void ClearEventsQueue(); // Clear all incoming events. + IMGUI_API void ClearInputKeys(); // Clear current keyboard/mouse/gamepad state + current frame text input buffer. Equivalent to releasing all keys/buttons. +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + IMGUI_API void ClearInputCharacters(); // [Obsolete] Clear the current frame text input buffer. Now included within ClearInputKeys(). +#endif //------------------------------------------------------------------ // Output - Updated by NewFrame() or EndFrame()/Render()