Skip to content

Commit 6aa408c

Browse files
committed
IO: Added io.ClearEventsQueue(). Obsoleted io.ClearInputCharacters(). (ocornut#4921)
cc ocornut#2425 ocornut#1153 ocornut#1600
1 parent 9a15730 commit 6aa408c

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

docs/CHANGELOG.txt

+11
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,19 @@ HOW TO UPDATE?
3636

3737
Breaking changes:
3838

39+
- IO: Obsoleted io.ClearInputCharacters() (added in 1.47) as it now ambiguous
40+
and often incorrect/misleading considering the existence of a higher-level
41+
input queue. (#4921)
42+
3943
Other changes:
4044

45+
- IO: Added io.ClearEventsQueue() to clear incoming inputs events. (#4921)
46+
May be useful in conjunction with io.ClearInputsKeys() if you need to clear
47+
both current inputs state and queued events (e.g. when using blocking native
48+
dialogs such as Windows's ::MessageBox() or ::GetOpenFileName()).
49+
- IO: Changed io.ClearInputsKeys() specs to also clear current frame character buffer
50+
(what now obsoleted io.ClearInputCharacters() did), as this is effectively the
51+
desirable behavior.
4152
- Demo: Better showcase use of SetNextItemAllowOverlap(). (#6574, #6512, #3909, #517)
4253

4354

imgui.cpp

+16-4
Original file line numberDiff line numberDiff line change
@@ -1341,13 +1341,15 @@ void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars)
13411341
}
13421342
}
13431343

1344-
// FIXME: Perhaps we could clear queued events as well?
1345-
void ImGuiIO::ClearInputCharacters()
1344+
// Clear all incoming events.
1345+
void ImGuiIO::ClearEventsQueue()
13461346
{
1347-
InputQueueCharacters.resize(0);
1347+
IM_ASSERT(Ctx != NULL);
1348+
ImGuiContext& g = *Ctx;
1349+
g.InputEventsQueue.clear();
13481350
}
13491351

1350-
// FIXME: Perhaps we could clear queued events as well?
1352+
// Clear current keyboard/mouse/gamepad state + current frame text input buffer. Equivalent to releasing all keys/buttons.
13511353
void ImGuiIO::ClearInputKeys()
13521354
{
13531355
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
@@ -1368,8 +1370,18 @@ void ImGuiIO::ClearInputKeys()
13681370
MouseDownDuration[n] = MouseDownDurationPrev[n] = -1.0f;
13691371
}
13701372
MouseWheel = MouseWheelH = 0.0f;
1373+
InputQueueCharacters.resize(0); // Behavior of old ClearInputCharacters().
13711374
}
13721375

1376+
// Removed this as it is ambiguous/misleading and generally incorrect to use with the existence of a higher-level input queue.
1377+
// Current frame character buffer is now also cleared by ClearInputKeys().
1378+
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
1379+
void ImGuiIO::ClearInputCharacters()
1380+
{
1381+
InputQueueCharacters.resize(0);
1382+
}
1383+
#endif
1384+
13731385
static ImGuiInputEvent* FindLatestInputEvent(ImGuiContext* ctx, ImGuiInputEventType type, int arg = -1)
13741386
{
13751387
ImGuiContext& g = *ctx;

imgui.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// Library Version
2626
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
2727
#define IMGUI_VERSION "1.89.8 WIP"
28-
#define IMGUI_VERSION_NUM 18971
28+
#define IMGUI_VERSION_NUM 18972
2929
#define IMGUI_HAS_TABLE
3030

3131
/*
@@ -2058,8 +2058,11 @@ struct ImGuiIO
20582058

20592059
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.
20602060
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.
2061-
IMGUI_API void ClearInputCharacters(); // [Internal] Clear the text input buffer manually
2062-
IMGUI_API void ClearInputKeys(); // [Internal] Release all keys
2061+
IMGUI_API void ClearEventsQueue(); // Clear all incoming events.
2062+
IMGUI_API void ClearInputKeys(); // Clear current keyboard/mouse/gamepad state + current frame text input buffer. Equivalent to releasing all keys/buttons.
2063+
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
2064+
IMGUI_API void ClearInputCharacters(); // [Obsolete] Clear the current frame text input buffer. Now included within ClearInputKeys().
2065+
#endif
20632066

20642067
//------------------------------------------------------------------
20652068
// Output - Updated by NewFrame() or EndFrame()/Render()

0 commit comments

Comments
 (0)