From 2dc81057ec4e5fbd97d06044967550b5c41b5387 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 3 May 2019 14:28:57 +0200 Subject: [PATCH] Selectable: With ImGuiSelectableFlags_AllowDoubleClick doesn't return true on the mouse button releas efollowing the double-click. Only first mouse release + second mouse down (double-click) returns true. Likewise for internal ButtonBehavior() with both _PressedOnClickRelease | _PressedOnDoubleClick. (#2503) --- docs/CHANGELOG.txt | 3 +++ imgui.cpp | 3 +++ imgui.h | 3 ++- imgui_widgets.cpp | 15 +++++++++++---- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index d808f4c2b..045df8753 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -74,6 +74,9 @@ Other Changes: clear the focus again. - Popups: Fixed right-click from closing all popups instead of aiming at the hovered popup level (regression in 1.67). +- Selectable: With ImGuiSelectableFlags_AllowDoubleClick doesn't return true on the mouse button release + following the double-click. Only first mouse release + second mouse down (double-click) returns true. + Likewise for internal ButtonBehavior() with both _PressedOnClickRelease | _PressedOnDoubleClick. (#2503) - GetMouseDragDelta(): also returns the delta on the mouse button released frame. (#2419) - GetMouseDragDelta(): verify that mouse positions are valid otherwise returns zero. - Inputs: Also add support for horizontal scroll with Shift+Mouse Wheel. (#2424, #1463) [@LucaRood] diff --git a/imgui.cpp b/imgui.cpp index 96f2caecd..43afd2358 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3282,6 +3282,7 @@ static void ImGui::UpdateMouseInputs() g.IO.MouseClickedTime[i] = g.Time; } g.IO.MouseClickedPos[i] = g.IO.MousePos; + g.IO.MouseDownWasDoubleClick[i] = g.IO.MouseDoubleClicked[i]; g.IO.MouseDragMaxDistanceAbs[i] = ImVec2(0.0f, 0.0f); g.IO.MouseDragMaxDistanceSqr[i] = 0.0f; } @@ -3293,6 +3294,8 @@ static void ImGui::UpdateMouseInputs() g.IO.MouseDragMaxDistanceAbs[i].x = ImMax(g.IO.MouseDragMaxDistanceAbs[i].x, delta_from_click_pos.x < 0.0f ? -delta_from_click_pos.x : delta_from_click_pos.x); g.IO.MouseDragMaxDistanceAbs[i].y = ImMax(g.IO.MouseDragMaxDistanceAbs[i].y, delta_from_click_pos.y < 0.0f ? -delta_from_click_pos.y : delta_from_click_pos.y); } + if (!g.IO.MouseDown[i] && !g.IO.MouseReleased[i]) + g.IO.MouseDownWasDoubleClick[i] = false; if (g.IO.MouseClicked[i]) // Clicking any mouse button reactivate mouse hovering which may have been deactivated by gamepad/keyboard navigation g.NavDisableMouseHover = false; } diff --git a/imgui.h b/imgui.h index f2c44e693..78e4c3d6d 100644 --- a/imgui.h +++ b/imgui.h @@ -1435,7 +1435,8 @@ struct ImGuiIO bool MouseClicked[5]; // Mouse button went from !Down to Down bool MouseDoubleClicked[5]; // Has mouse button been double-clicked? bool MouseReleased[5]; // Mouse button went from Down to !Down - bool MouseDownOwned[5]; // Track if button was clicked inside a window. We don't request mouse capture from the application if click started outside ImGui bounds. + bool MouseDownOwned[5]; // Track if button was clicked inside an imgui window. We don't request mouse capture from the application if click started outside ImGui bounds. + bool MouseDownWasDoubleClick[5]; // Track if button down was a double-click float MouseDownDuration[5]; // Duration the mouse button has been down (0.0f == just clicked) float MouseDownDurationPrev[5]; // Previous time the mouse button has been down ImVec2 MouseDragMaxDistanceAbs[5]; // Maximum distance, absolute, on each axis, of how much mouse has traveled from the clicking point diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 894da5439..f146920d8 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -429,6 +429,10 @@ void ImGui::BulletTextV(const char* fmt, va_list args) // Frame N+6 (mouse button is released) - true - - true - // Frame N+7 (mouse button is released) - true - - - - //------------------------------------------------------------------------------------------------------------------------------------------------ +// Note that some combinations are supported, +// - PressedOnDragDropHold can generally be associated with any flag. +// - PressedOnDoubleClick can be associated by PressedOnClickRelease/PressedOnRelease, in which case the second release event won't be reported. +//------------------------------------------------------------------------------------------------------------------------------------------------ // The behavior of the return-value changes when ImGuiButtonFlags_Repeat is set: // Repeat+ Repeat+ Repeat+ Repeat+ // PressedOnClickRelease PressedOnClick PressedOnRelease PressedOnDoubleClick @@ -569,10 +573,13 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool } else { - if (hovered && (flags & ImGuiButtonFlags_PressedOnClickRelease)) - if (!((flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[0] >= g.IO.KeyRepeatDelay)) // Repeat mode trumps - if (!g.DragDropActive) - pressed = true; + if (hovered && (flags & ImGuiButtonFlags_PressedOnClickRelease) && !g.DragDropActive) + { + bool is_double_click_release = (flags & ImGuiButtonFlags_PressedOnDoubleClick) && g.IO.MouseDownWasDoubleClick[0]; + bool is_repeating_already = (flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[0] >= g.IO.KeyRepeatDelay; // Repeat mode trumps + if (!is_double_click_release && !is_repeating_already) + pressed = true; + } ClearActiveID(); } if (!(flags & ImGuiButtonFlags_NoNavFocus))