Browse Source

IO: modify io.AddFocusEvent() to tolerate in/out for multi-viewports. Amend 2f40be6. (merged from docking) (#3532)

pull/4615/head
ocornut 3 years ago
parent
commit
bbb95a5e06
  1. 22
      imgui.cpp
  2. 4
      imgui.h

22
imgui.cpp

@ -1185,13 +1185,8 @@ void ImGuiIO::ClearInputCharacters()
InputQueueCharacters.resize(0); InputQueueCharacters.resize(0);
} }
void ImGuiIO::AddFocusEvent(bool focused) void ImGuiIO::ClearInputKeys()
{ {
if (focused)
return;
// Clear buttons state when focus is lost
// (this is useful so e.g. releasing Alt after focus loss on Alt-Tab doesn't trigger the Alt menu toggle)
memset(KeysDown, 0, sizeof(KeysDown)); memset(KeysDown, 0, sizeof(KeysDown));
for (int n = 0; n < IM_ARRAYSIZE(KeysDownDuration); n++) for (int n = 0; n < IM_ARRAYSIZE(KeysDownDuration); n++)
KeysDownDuration[n] = KeysDownDurationPrev[n] = -1.0f; KeysDownDuration[n] = KeysDownDurationPrev[n] = -1.0f;
@ -1201,6 +1196,13 @@ void ImGuiIO::AddFocusEvent(bool focused)
NavInputsDownDuration[n] = NavInputsDownDurationPrev[n] = -1.0f; NavInputsDownDuration[n] = NavInputsDownDurationPrev[n] = -1.0f;
} }
void ImGuiIO::AddFocusEvent(bool focused)
{
// We intentionally overwrite this and process in NewFrame(), in order to give a chance
// to multi-viewports backends to queue AddFocusEvent(false),AddFocusEvent(true) in same frame.
AppFocusLost = !focused;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// [SECTION] MISC HELPERS/UTILITIES (Geometry functions) // [SECTION] MISC HELPERS/UTILITIES (Geometry functions)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -4070,6 +4072,14 @@ void ImGui::NewFrame()
g.DragDropWithinTarget = false; g.DragDropWithinTarget = false;
g.DragDropHoldJustPressedId = 0; g.DragDropHoldJustPressedId = 0;
// Clear buttons state when focus is lost
// (this is useful so e.g. releasing Alt after focus loss on Alt-Tab doesn't trigger the Alt menu toggle)
if (g.IO.AppFocusLost)
{
g.IO.ClearInputKeys();
g.IO.AppFocusLost = false;
}
// Update keyboard input state // Update keyboard input state
// Synchronize io.KeyMods with individual modifiers io.KeyXXX bools // Synchronize io.KeyMods with individual modifiers io.KeyXXX bools
g.IO.KeyMods = GetMergedKeyModFlags(); g.IO.KeyMods = GetMergedKeyModFlags();

4
imgui.h

@ -1892,8 +1892,9 @@ struct ImGuiIO
IMGUI_API void AddInputCharacter(unsigned int c); // Queue new character input IMGUI_API void AddInputCharacter(unsigned int c); // Queue new character input
IMGUI_API void AddInputCharacterUTF16(ImWchar16 c); // Queue new character input from an UTF-16 character, it can be a surrogate IMGUI_API void AddInputCharacterUTF16(ImWchar16 c); // Queue new character input from an UTF-16 character, it can be a surrogate
IMGUI_API void AddInputCharactersUTF8(const char* str); // Queue new characters input from an UTF-8 string IMGUI_API void AddInputCharactersUTF8(const char* str); // Queue new characters input from an UTF-8 string
IMGUI_API void ClearInputCharacters(); // Clear the text input buffer manually
IMGUI_API void AddFocusEvent(bool focused); // Notifies Dear ImGui when hosting platform windows lose or gain input focus IMGUI_API void AddFocusEvent(bool focused); // Notifies Dear ImGui when hosting platform windows lose or gain input focus
IMGUI_API void ClearInputCharacters(); // [Internal] Clear the text input buffer manually
IMGUI_API void ClearInputKeys(); // [Internal] Release all keys
//------------------------------------------------------------------ //------------------------------------------------------------------
// Output - Updated by NewFrame() or EndFrame()/Render() // Output - Updated by NewFrame() or EndFrame()/Render()
@ -1941,6 +1942,7 @@ struct ImGuiIO
float NavInputsDownDuration[ImGuiNavInput_COUNT]; float NavInputsDownDuration[ImGuiNavInput_COUNT];
float NavInputsDownDurationPrev[ImGuiNavInput_COUNT]; float NavInputsDownDurationPrev[ImGuiNavInput_COUNT];
float PenPressure; // Touch/Pen pressure (0.0f to 1.0f, should be >0.0f only when MouseDown[0] == true). Helper storage currently unused by Dear ImGui. float PenPressure; // Touch/Pen pressure (0.0f to 1.0f, should be >0.0f only when MouseDown[0] == true). Helper storage currently unused by Dear ImGui.
bool AppFocusLost;
ImWchar16 InputQueueSurrogate; // For AddInputCharacterUTF16 ImWchar16 InputQueueSurrogate; // For AddInputCharacterUTF16
ImVector<ImWchar> InputQueueCharacters; // Queue of _characters_ input (obtained by platform backend). Fill using AddInputCharacter() helper. ImVector<ImWchar> InputQueueCharacters; // Queue of _characters_ input (obtained by platform backend). Fill using AddInputCharacter() helper.

Loading…
Cancel
Save