TreeNode: Fixed bug where dragging a payload over a TreeNode() with either _OpenOnDoubleClick or _OpenOnArrow would open the node. (#143)

This commit is contained in:
omar 2020-04-15 13:06:05 +02:00
parent 54b38d88f7
commit 1fd9e131e4
4 changed files with 15 additions and 4 deletions

View File

@ -41,6 +41,8 @@ Other Changes:
- TreeNode: Fixed bug where BeginDragDropSource() failed when the _OpenOnDoubleClick flag is - TreeNode: Fixed bug where BeginDragDropSource() failed when the _OpenOnDoubleClick flag is
enabled (bug introduced in 1.76, but pre-1.76 it would also fail unless the _OpenOnArrow enabled (bug introduced in 1.76, but pre-1.76 it would also fail unless the _OpenOnArrow
flag was also set, and _OpenOnArrow is frequently set along with _OpenOnDoubleClick). flag was also set, and _OpenOnArrow is frequently set along with _OpenOnDoubleClick).
- TreeNode: Fixed bug where dragging a payload over a TreeNode() with either _OpenOnDoubleClick
or _OpenOnArrow would open the node. (#143)
----------------------------------------------------------------------- -----------------------------------------------------------------------

View File

@ -3795,6 +3795,7 @@ void ImGui::NewFrame()
g.DragDropAcceptIdCurrRectSurface = FLT_MAX; g.DragDropAcceptIdCurrRectSurface = FLT_MAX;
g.DragDropWithinSource = false; g.DragDropWithinSource = false;
g.DragDropWithinTarget = false; g.DragDropWithinTarget = false;
g.DragDropHoldJustPressedId = 0;
// 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

View File

@ -1165,6 +1165,7 @@ struct ImGuiContext
ImGuiID DragDropAcceptIdCurr; // Target item id (set at the time of accepting the payload) ImGuiID DragDropAcceptIdCurr; // Target item id (set at the time of accepting the payload)
ImGuiID DragDropAcceptIdPrev; // Target item id from previous frame (we need to store this to allow for overlapping drag and drop targets) ImGuiID DragDropAcceptIdPrev; // Target item id from previous frame (we need to store this to allow for overlapping drag and drop targets)
int DragDropAcceptFrameCount; // Last time a target expressed a desire to accept the source int DragDropAcceptFrameCount; // Last time a target expressed a desire to accept the source
ImGuiID DragDropHoldJustPressedId; // Set when holding a payload just made ButtonBehavior() return a press.
ImVector<unsigned char> DragDropPayloadBufHeap; // We don't expose the ImVector<> directly, ImGuiPayload only holds pointer+size ImVector<unsigned char> DragDropPayloadBufHeap; // We don't expose the ImVector<> directly, ImGuiPayload only holds pointer+size
unsigned char DragDropPayloadBufLocal[16]; // Local buffer for small payloads unsigned char DragDropPayloadBufLocal[16]; // Local buffer for small payloads
@ -1320,6 +1321,7 @@ struct ImGuiContext
DragDropAcceptIdCurrRectSurface = 0.0f; DragDropAcceptIdCurrRectSurface = 0.0f;
DragDropAcceptIdPrev = DragDropAcceptIdCurr = 0; DragDropAcceptIdPrev = DragDropAcceptIdCurr = 0;
DragDropAcceptFrameCount = -1; DragDropAcceptFrameCount = -1;
DragDropHoldJustPressedId = 0;
memset(DragDropPayloadBufLocal, 0, sizeof(DragDropPayloadBufLocal)); memset(DragDropPayloadBufLocal, 0, sizeof(DragDropPayloadBufLocal));
CurrentTabBar = NULL; CurrentTabBar = NULL;

View File

@ -500,11 +500,13 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
if (g.DragDropActive && (flags & ImGuiButtonFlags_PressedOnDragDropHold) && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoHoldToOpenOthers)) if (g.DragDropActive && (flags & ImGuiButtonFlags_PressedOnDragDropHold) && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoHoldToOpenOthers))
if (IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) if (IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem))
{ {
const float DRAG_DROP_HOLD_TIMER = 0.70f;
hovered = true; hovered = true;
SetHoveredID(id); SetHoveredID(id);
if (CalcTypematicRepeatAmount(g.HoveredIdTimer + 0.0001f - g.IO.DeltaTime, g.HoveredIdTimer + 0.0001f, 0.70f, 0.00f)) if (CalcTypematicRepeatAmount(g.HoveredIdTimer + 0.0001f - g.IO.DeltaTime, g.HoveredIdTimer + 0.0001f, DRAG_DROP_HOLD_TIMER, 0.00f))
{ {
pressed = true; pressed = true;
g.DragDropHoldJustPressedId = id;
FocusWindow(window); FocusWindow(window);
} }
} }
@ -5376,7 +5378,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
bool toggled = false; bool toggled = false;
if (!is_leaf) if (!is_leaf)
{ {
if (pressed) if (pressed && g.DragDropHoldJustPressedId != id)
{ {
if ((flags & (ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) == 0 || (g.NavActivateId == id)) if ((flags & (ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick)) == 0 || (g.NavActivateId == id))
toggled = true; toggled = true;
@ -5384,8 +5386,12 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
toggled |= is_mouse_x_over_arrow && !g.NavDisableMouseHover; // Lightweight equivalent of IsMouseHoveringRect() since ButtonBehavior() already did the job toggled |= is_mouse_x_over_arrow && !g.NavDisableMouseHover; // Lightweight equivalent of IsMouseHoveringRect() since ButtonBehavior() already did the job
if ((flags & ImGuiTreeNodeFlags_OpenOnDoubleClick) && g.IO.MouseDoubleClicked[0]) if ((flags & ImGuiTreeNodeFlags_OpenOnDoubleClick) && g.IO.MouseDoubleClicked[0])
toggled = true; toggled = true;
if (g.DragDropActive && is_open) // When using Drag and Drop "hold to open" we keep the node highlighted after opening, but never close it again. }
toggled = false; else if (pressed && g.DragDropHoldJustPressedId == id)
{
IM_ASSERT(button_flags & ImGuiButtonFlags_PressedOnDragDropHold);
if (!is_open) // When using Drag and Drop "hold to open" we keep the node highlighted after opening, but never close it again.
toggled = true;
} }
if (g.NavId == id && g.NavMoveRequest && g.NavMoveDir == ImGuiDir_Left && is_open) if (g.NavId == id && g.NavMoveRequest && g.NavMoveDir == ImGuiDir_Left && is_open)