diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 4d4c89481..3b1087001 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -77,7 +77,8 @@ Other Changes: - Platform IME: [Windows] Fixed a call to ImmAssociateContextEx() leading to freeze on some setups. (#2589, #5535, #5264, #4972) - Misc: io.Framerate moving average now converge in 60 frames instead of 120. (#5236, #4138) -- Tools: Item Picker: Mouse button can be changed by holding Ctrl+Shift, making it easier +- Debug Tools: Debug Log: Added IO events logging. +- Debug Tools: Item Picker: Mouse button can be changed by holding Ctrl+Shift, making it easier to use the Item Picker in e.g. menus. (#2673) - Backends: Metal: Use __bridge for ARC based systems. (#5403) [@stack] - Backends: Metal: Add dispatch synchronization. (#5447) [@luigifcruz] @@ -176,10 +177,10 @@ Other Changes: - DrawList: Fixed texture-based anti-aliasing path with RGBA textures (#5132, #3245) [@cfillion] - DrawList: Fixed divide-by-zero or glitches with Radius/Rounding values close to zero. (#5249, #5293, #3491) - DrawList: Circle with a radius smaller than 0.5f won't appear, to be consistent with other primitives. [@thedmd] -- Debug: Added ShowDebugLogWindow() showing an opt-in synthetic log of principal events (focus, popup, - active id changes) helping to diagnose issues. -- Debug: Added DebugTextEncoding() function to facilitate diagnosing issues when not sure about whether - you have a UTF-8 text encoding issue or a font loading issue. [@LaMarche05, @ocornut] +- Debug Tools: Debug Log: Added ShowDebugLogWindow() showing an opt-in synthetic log of principal events + (focus, popup, active id changes) helping to diagnose issues. +- Debug Tools: Added DebugTextEncoding() function to facilitate diagnosing issues when not sure about + whether you have a UTF-8 text encoding issue or a font loading issue. [@LaMarche05, @ocornut] - Demo: Add better demo of how to use SetNextFrameWantCaptureMouse()/SetNextFrameWantCaptureKeyboard(). - Metrics: Added a "UTF-8 Encoding Viewer" section using the aforementioned DebugTextEncoding() function. - Metrics: Added "InputText" section to visualize internal state (#4947, #4949). @@ -1740,8 +1741,8 @@ Other Changes: returning true. This also effectively make ColorEdit4() not incorrect trigger IsItemDeactivatedAfterEdit() when clicking the color button to open the picker popup. (#1875) - Misc: Added IMGUI_DISABLE_METRICS_WINDOW imconfig.h setting to explicitly compile out ShowMetricsWindow(). -- Debug, Metrics: Added "Tools->Item Picker" tool which allow clicking on a widget to break in the debugger - within the item code. The tool calls IM_DEBUG_BREAK() which can be redefined in imconfig.h if needed. +- Debug Tools: Added "Metrics->Tools->Item Picker" tool which allow clicking on a widget to break in the + debugger within the item code. The tool calls IM_DEBUG_BREAK() which can be redefined in imconfig.h. - ImDrawList: Fixed CloneOutput() helper crashing. (#1860) [@gviot] - ImDrawList::ChannelsSplit(), ImDrawListSplitter: Fixed an issue with merging draw commands between channel 0 and 1. (#2624) diff --git a/imgui.cpp b/imgui.cpp index 09bfb3edd..5cd814210 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7973,17 +7973,17 @@ static const char* GetInputSourceName(ImGuiInputSource source) IM_ASSERT(IM_ARRAYSIZE(input_source_names) == ImGuiInputSource_COUNT && source >= 0 && source < ImGuiInputSource_COUNT); return input_source_names[source]; } -#endif - -/*static void DebugPrintInputEvent(const char* prefix, const ImGuiInputEvent* e) +static void DebugPrintInputEvent(const char* prefix, const ImGuiInputEvent* e) { - if (e->Type == ImGuiInputEventType_MousePos) { IMGUI_DEBUG_LOG_IO("%s: MousePos (%.1f %.1f)\n", prefix, e->MousePos.PosX, e->MousePos.PosY); return; } + ImGuiContext& g = *GImGui; + if (e->Type == ImGuiInputEventType_MousePos) { IMGUI_DEBUG_LOG_IO("%s: MousePos (%.1f, %.1f)\n", prefix, e->MousePos.PosX, e->MousePos.PosY); return; } if (e->Type == ImGuiInputEventType_MouseButton) { IMGUI_DEBUG_LOG_IO("%s: MouseButton %d %s\n", prefix, e->MouseButton.Button, e->MouseButton.Down ? "Down" : "Up"); return; } - if (e->Type == ImGuiInputEventType_MouseWheel) { IMGUI_DEBUG_LOG_IO("%s: MouseWheel (%.1f %.1f)\n", prefix, e->MouseWheel.WheelX, e->MouseWheel.WheelY); return; } + if (e->Type == ImGuiInputEventType_MouseWheel) { IMGUI_DEBUG_LOG_IO("%s: MouseWheel (%.1f, %.1f)\n", prefix, e->MouseWheel.WheelX, e->MouseWheel.WheelY); return; } if (e->Type == ImGuiInputEventType_Key) { IMGUI_DEBUG_LOG_IO("%s: Key \"%s\" %s\n", prefix, ImGui::GetKeyName(e->Key.Key), e->Key.Down ? "Down" : "Up"); return; } if (e->Type == ImGuiInputEventType_Text) { IMGUI_DEBUG_LOG_IO("%s: Text: %c (U+%08X)\n", prefix, e->Text.Char, e->Text.Char); return; } if (e->Type == ImGuiInputEventType_Focus) { IMGUI_DEBUG_LOG_IO("%s: AppFocused %d\n", prefix, e->AppFocused.Focused); return; } -}*/ +} +#endif // Process input queue // We always call this with the value of 'bool g.IO.ConfigInputTrickleEventQueue'. @@ -8006,13 +8006,14 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs) int event_n = 0; for (; event_n < g.InputEventsQueue.Size; event_n++) { - const ImGuiInputEvent* e = &g.InputEventsQueue[event_n]; + ImGuiInputEvent* e = &g.InputEventsQueue[event_n]; if (e->Type == ImGuiInputEventType_MousePos) { ImVec2 event_pos(e->MousePos.PosX, e->MousePos.PosY); if (IsMousePosValid(&event_pos)) event_pos = ImVec2(ImFloorSigned(event_pos.x), ImFloorSigned(event_pos.y)); // Apply same flooring as UpdateMouseInputs() - if (io.MousePos.x != event_pos.x || io.MousePos.y != event_pos.y) + e->IgnoredAsSame = (io.MousePos.x == event_pos.x && io.MousePos.y == event_pos.y); + if (!e->IgnoredAsSame) { // Trickling Rule: Stop processing queued events if we already handled a mouse button change if (trickle_fast_inputs && (mouse_button_changed != 0 || mouse_wheeled || key_changed || text_inputted)) @@ -8025,7 +8026,8 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs) { const ImGuiMouseButton button = e->MouseButton.Button; IM_ASSERT(button >= 0 && button < ImGuiMouseButton_COUNT); - if (io.MouseDown[button] != e->MouseButton.Down) + e->IgnoredAsSame = (io.MouseDown[button] == e->MouseButton.Down); + if (!e->IgnoredAsSame) { // Trickling Rule: Stop processing queued events if we got multiple action on the same button if (trickle_fast_inputs && ((mouse_button_changed & (1 << button)) || mouse_wheeled)) @@ -8036,7 +8038,8 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs) } else if (e->Type == ImGuiInputEventType_MouseWheel) { - if (e->MouseWheel.WheelX != 0.0f || e->MouseWheel.WheelY != 0.0f) + e->IgnoredAsSame = (e->MouseWheel.WheelX == 0.0f && e->MouseWheel.WheelY == 0.0f); + if (!e->IgnoredAsSame) { // Trickling Rule: Stop processing queued events if we got multiple action on the event if (trickle_fast_inputs && (mouse_moved || mouse_button_changed != 0)) @@ -8052,7 +8055,8 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs) IM_ASSERT(key != ImGuiKey_None); const int keydata_index = (key - ImGuiKey_KeysData_OFFSET); ImGuiKeyData* keydata = &io.KeysData[keydata_index]; - if (keydata->Down != e->Key.Down || keydata->AnalogValue != e->Key.AnalogValue) + e->IgnoredAsSame = (keydata->Down == e->Key.Down && keydata->AnalogValue == e->Key.AnalogValue); + if (!e->IgnoredAsSame) { // Trickling Rule: Stop processing queued events if we got multiple action on the same button if (trickle_fast_inputs && keydata->Down != e->Key.Down && (key_changed_mask.TestBit(keydata_index) || text_inputted || mouse_button_changed != 0)) @@ -8093,7 +8097,10 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs) { // We intentionally overwrite this and process lower, in order to give a chance // to multi-viewports backends to queue AddFocusEvent(false) + AddFocusEvent(true) in same frame. - io.AppFocusLost = !e->AppFocused.Focused; + const bool focus_lost = !e->AppFocused.Focused; + e->IgnoredAsSame = (io.AppFocusLost == focus_lost); + if (!e->IgnoredAsSame) + io.AppFocusLost = focus_lost; } else { @@ -8107,9 +8114,11 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs) g.InputEventsTrail.push_back(g.InputEventsQueue[n]); // [DEBUG] - /*if (event_n != 0) +#ifndef IMGUI_DISABLE_DEBUG_TOOLS + if (event_n != 0 && (g.DebugLogFlags & ImGuiDebugLogFlags_EventIO)) for (int n = 0; n < g.InputEventsQueue.Size; n++) - DebugPrintInputEvent(n < event_n ? "Processed" : "Remaining", &g.InputEventsQueue[n]);*/ + DebugPrintInputEvent(n < event_n ? (g.InputEventsQueue[n].IgnoredAsSame ? "Processed (Same)" : "Processed") : "Remaining", &g.InputEventsQueue[n]); +#endif // Remaining events will be processed on the next frame if (event_n == g.InputEventsQueue.Size) @@ -13265,6 +13274,7 @@ void ImGui::ShowDebugLogWindow(bool* p_open) SameLine(); CheckboxFlags("Focus", &g.DebugLogFlags, ImGuiDebugLogFlags_EventFocus); SameLine(); CheckboxFlags("Popup", &g.DebugLogFlags, ImGuiDebugLogFlags_EventPopup); SameLine(); CheckboxFlags("Nav", &g.DebugLogFlags, ImGuiDebugLogFlags_EventNav); + SameLine(); CheckboxFlags("IO", &g.DebugLogFlags, ImGuiDebugLogFlags_EventIO); if (SmallButton("Clear")) g.DebugLogBuf.clear(); diff --git a/imgui_internal.h b/imgui_internal.h index 193545e20..ab76fb002 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1238,6 +1238,7 @@ struct ImGuiInputEvent ImGuiInputEventText Text; // if Type == ImGuiInputEventType_Text ImGuiInputEventAppFocused AppFocused; // if Type == ImGuiInputEventType_Focus }; + bool IgnoredAsSame; bool AddedByTestEngine; ImGuiInputEvent() { memset(this, 0, sizeof(*this)); }