You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MultiSelect + DragDrop + TreeNode: Hovering over an open TreeNode with DragDrop active causes MultiSelect selection to be cleared and replaced by only the hovered TreeNode
#7850
Closed
bratpilz opened this issue
Aug 1, 2024
· 3 comments
Hello again! I know MultiSelect in combination with trees is still experimental, but I tried it anyway and ran into the issue described in the title.
Using the various MultiSelect features like Ctrl/Shift clicking works fine on TreeNodes. But now I wanted to be able to drag all selected nodes at once. For this, I call Begin(/End)DragDropSource after each TreeNode, which also works well. But when I have this DragDrop active and hover over a TreeNode that's currently open, the selection gets overwritten by just that single node I'm hovering. I'm guessing this has something to do with the fact that TreeNodes get automatically opened on hover while DragDrop is active. Relatedly, passing ImGuiDragDropFlags_SourceNoHoldToOpenOthers to BeginDragDropSource prevents this issue from occurring.
Screenshots/Video:
multi-select-treenode-open-issue.mp4
Minimal, Complete and Verifiable Example code:
// Here's some code anyone can copy and paste to reproduce your issue
{
usingnamespaceImGui;SetNextWindowSize (ImVec2 (400.0f, 300.0f), ImGuiCond_Appearing);
Begin ("Test");
static ImGuiSelectionBasicStorage selection;
staticunsignedconst N = 3;
auto ms = BeginMultiSelect (ImGuiMultiSelectFlags_BoxSelect1d, selection.Size, N * (N+1));
selection.ApplyRequests (ms);
auto dnd_source = [&]() {
if (!BeginDragDropSource()) // Workaround: Pass ImGuiDragDropFlags_SourceNoHoldToOpenOthers here to prevent the issue from occurring.return;
SetDragDropPayload ("test", 0, 0);
Text ("Dragging %u selected node%s:", selection.Size, selection.Size == 1 ? "" : "s");
void *it = 0;
ImGuiID id;
while (selection.GetNextSelectedItem (&it, &id))
{
unsigned id_i = id / (N+1);
unsigned rest = id - id_i * (N+1);
if (rest == 0)
Text ("- Top level %u", id_i);
elseText ("- Top level %u / Leaf %u", id_i, rest-1);
}
EndDragDropSource(); };
for (unsigned i = 0; i < N; ++i)
{
char label[32];
snprintf (label, sizeof label, "Top level %u", i);
int base_flags = ImGuiTreeNodeFlags_SpanFullWidth;
int flags = base_flags;
unsigned base_id = i * (N+1);
if (selection.Contains (base_id))
flags |= ImGuiTreeNodeFlags_Selected;
SetNextItemSelectionUserData (base_id);
bool top_level_open = TreeNodeEx (label, flags);
dnd_source();
if (!top_level_open)
continue;
for (unsigned j = 0; j < N; ++j)
{
int flags = base_flags | ImGuiTreeNodeFlags_Leaf;
unsigned leaf_id = base_id + 1 + j;
if (selection.Contains (leaf_id))
flags |= ImGuiTreeNodeFlags_Selected;
snprintf (label, sizeof label, "Leaf %u", j);
SetNextItemSelectionUserData (leaf_id);
bool leaf_open = TreeNodeEx (label, flags);
dnd_source();
if (leaf_open)
TreePop();
}
TreePop();
}
ms = EndMultiSelect();
selection.ApplyRequests (ms);
End();
}
The text was updated successfully, but these errors were encountered:
While looking at your test case I was initially frustrated that double-clicking wouldn't open tree nodes.
Normal tree node open on simple click (could potentially be reevaluated) but when using multi-select we are forced to enable ImGuiTreeNodeFlags_OpenOnArrow. However I think we could come up with the change that if none of the _OpenOnXXX behavior is explicit, then the default for multi-selectable tree node would be ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick, aka a more sensible default. Going to make that change now.
Thanks for another very fast fix! This new default open behavior sounds good too. During my testing I had also noticed that I had to press on the arrow to open the nodes now, which wasn't super convenient, so this makes it easier.
Version/Branch of Dear ImGui:
Version 1.91.1 WIP, Branch: master
Back-ends:
imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Compiler, OS:
Linux + GCC
Full config/build information:
Details:
My Issue/Question:
Hello again! I know MultiSelect in combination with trees is still experimental, but I tried it anyway and ran into the issue described in the title.
Using the various MultiSelect features like Ctrl/Shift clicking works fine on TreeNodes. But now I wanted to be able to drag all selected nodes at once. For this, I call Begin(/End)DragDropSource after each TreeNode, which also works well. But when I have this DragDrop active and hover over a TreeNode that's currently open, the selection gets overwritten by just that single node I'm hovering. I'm guessing this has something to do with the fact that TreeNodes get automatically opened on hover while DragDrop is active. Relatedly, passing ImGuiDragDropFlags_SourceNoHoldToOpenOthers to BeginDragDropSource prevents this issue from occurring.
Screenshots/Video:
multi-select-treenode-open-issue.mp4
Minimal, Complete and Verifiable Example code:
The text was updated successfully, but these errors were encountered: