From c9fe7ebc7bd1badfaee7d901cbddc11f43030a32 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 4 Apr 2023 20:07:57 +0200 Subject: [PATCH] IO: Input queue trickling adjustment for touch screens. (#2702, #4921) + amend two comments in imgui.h --- docs/CHANGELOG.txt | 10 ++++++++++ imgui.cpp | 2 ++ imgui.h | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index a676048b..a96410b0 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -58,6 +58,16 @@ Other changes: Windows Close and Collapse Buttons. - Misc: Fixed ImVec2 operator[] violating aliasing rules causing issue with Intel C++ compiler. (#6272) [@BayesBug] +- IO: Input queue trickling adjustment for touch screens. (#2702, #4921) + This fixes single-tapping to move simulated mouse and immediately click on a widget + that is using the ImGuiButtonFlags_AllowItemOverlap policy. + - This only works if the backend can distinguish TouchScreen vs Mouse. + See 'Demo->Tools->Metrics->Inputs->Mouse Source' to verify. + - Fixed tapping on BeginTabItem() on a touch-screen. (#2702) + - Fixed tapping on CollapsingHeader() with a close button on a touch-screen. + - Fixed tapping on TreeNode() using ImGuiTreeNodeFlags_AllowItemOverlap on a touch-screen. + - Fixed tapping on Selectable() using ImGuiSelectableFlags_AllowItemOverlap on a touch-screen. + - Fixed tapping on TableHeader() on a touch-screen. - IO: Added io.AddMouseSourceEvent() and ImGuiMouseSource enum. This is to allow backend to specify actual event source between Mouse/TouchScreen/Pen. (#2702, #2334, #2372, #3453, #5693) - IO: Fixed support for calling io.AddXXXX functions fron inactive context (wrongly diff --git a/imgui.cpp b/imgui.cpp index 3275edef..4e3b6050 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -8733,6 +8733,8 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs) IM_ASSERT(button >= 0 && button < ImGuiMouseButton_COUNT); if (trickle_fast_inputs && ((mouse_button_changed & (1 << button)) || mouse_wheeled)) break; + if (trickle_fast_inputs && e->MouseButton.MouseSource == ImGuiMouseSource_TouchScreen && mouse_moved) // #2702: TouchScreen have no initial hover. + break; io.MouseDown[button] = e->MouseButton.Down; io.MouseSource = e->MouseButton.MouseSource; mouse_button_changed |= (1 << button); diff --git a/imgui.h b/imgui.h index c78bec72..c974d9c7 100644 --- a/imgui.h +++ b/imgui.h @@ -167,7 +167,7 @@ struct ImGuiViewport; // A Platform Window (always only one in 'ma // In Visual Studio IDE: CTRL+comma ("Edit.GoToAll") can follow symbols in comments, whereas CTRL+F12 ("Edit.GoToImplementation") cannot. // With Visual Assist installed: ALT+G ("VAssistX.GoToImplementation") can also follow symbols in comments. enum ImGuiKey : int; // -> enum ImGuiKey // Enum: A key identifier (ImGuiKey_XXX or ImGuiMod_XXX value) -enum ImGuiMouseSource : int; // -> enum ImGuiMouseSource // Enum; A mouse input source identifier (Mouse, TouchPad, TouchScreen, Pen) +enum ImGuiMouseSource : int; // -> enum ImGuiMouseSource // Enum; A mouse input source identifier (Mouse, TouchScreen, Pen) typedef int ImGuiCol; // -> enum ImGuiCol_ // Enum: A color identifier for styling typedef int ImGuiCond; // -> enum ImGuiCond_ // Enum: A condition for many Set*() functions typedef int ImGuiDataType; // -> enum ImGuiDataType_ // Enum: A primary data type @@ -2049,7 +2049,7 @@ struct ImGuiIO bool MouseDown[5]; // Mouse buttons: 0=left, 1=right, 2=middle + extras (ImGuiMouseButton_COUNT == 5). Dear ImGui mostly uses left and right buttons. Other buttons allow us to track if the mouse is being used by your application + available to user as a convenience via IsMouse** API. float MouseWheel; // Mouse wheel Vertical: 1 unit scrolls about 5 lines text. >0 scrolls Up, <0 scrolls Down. Hold SHIFT to turn vertical scroll into horizontal scroll. float MouseWheelH; // Mouse wheel Horizontal. >0 scrolls Left, <0 scrolls Right. Most users don't have a mouse with a horizontal wheel, may not be filled by all backends. - ImGuiMouseSource MouseSource; // Mouse actual input peripheral (Mouse/TouchPad/TouchScreen/Pen). + ImGuiMouseSource MouseSource; // Mouse actual input peripheral (Mouse/TouchScreen/Pen). bool KeyCtrl; // Keyboard modifier down: Control bool KeyShift; // Keyboard modifier down: Shift bool KeyAlt; // Keyboard modifier down: Alt