Skip to content

Commit

Permalink
IO: Added io.ClearEventsQueue(). Obsoleted io.ClearInputCharacters(). (
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornut committed Jul 6, 2023
1 parent 9a15730 commit 6aa408c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
11 changes: 11 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
20 changes: 16 additions & 4 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 6aa408c

Please sign in to comment.