Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeginDragDropTarget makes tree node disappears #8140

Open
IniKiwi opened this issue Nov 8, 2024 · 1 comment
Open

BeginDragDropTarget makes tree node disappears #8140

IniKiwi opened this issue Nov 8, 2024 · 1 comment
Labels
drag drop drag and drop

Comments

@IniKiwi
Copy link

IniKiwi commented Nov 8, 2024

Version/Branch of Dear ImGui:

Version dev, Branch: docking

Back-ends:

imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp

Compiler, OS:

Linux Debian 12

Full config/build information:

Dear ImGui 1.91.5 WIP (19141)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201703
define: __linux__
define: __GNUC__=13
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000081
 NavEnableKeyboard
 DockingEnable
io.ConfigViewportsNoDecoration
io.ConfigNavCaptureKeyboard
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigWindowsMoveFromTitleBarOnly
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C0E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,128
io.DisplaySize: 1280.00,720.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Details:

I'm following this example https://github.com/ocornut/imgui/blob/368123ab06b2b573d585e52f84cd782c5c006697/imgui_demo.cpp#L2662C48-L2662C71. But when I'm adding a drag and drop target, treenodes disappears.

Screenshots/Video:

Capture.video.du.2024-11-08.14-09-41.mp4

Minimal, Complete and Verifiable Example code:

int flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanTextWidth;
    if(m_SelectedObject == e) flags |= ImGuiTreeNodeFlags_Selected;
    std::set<Instance*> childs = e->GetChildrens();
    if(!(childs.size() > 0)) flags |= ImGuiTreeNodeFlags_Leaf;

    std::string label = fmt::format("{}{}", InstanceClassNameToIcon(e), e->GetName());

    bool skip;
    if(show){
        skip = ImGui::TreeNodeEx((void*)e, flags, label.c_str());
        if (ImGui::IsItemClicked() && !ImGui::IsItemToggledOpen()) m_SelectedObject = e;
        if(ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)){
            ImGui::SetDragDropPayload("_INSTANCE", e, sizeof(void*));
            ImGui::Text(label.c_str());
            ImGui::EndDragDropSource();
        }

        /*if(ImGui::BeginDragDropTarget()){
            if(const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("_INSTANCE")){
                IM_ASSERT(payload->DataSize == sizeof(void*));
                Instance* object = (Instance*)payload->Data;
                object->SetParent(e);
            }
            ImGui::EndDragDropTarget();
        }*/

        if (ImGui::BeginPopupContextItem()){
            m_SelectedObject = e;
            ImGui::MenuItem(ICON_CUT_RED" Cut", "Ctrl+X", &m_instanceContextMenuActions.Cut);
            ImGui::MenuItem(ICON_PAGE_COPY" Copy", "Ctrl+C", &m_instanceContextMenuActions.Copy);
            ImGui::MenuItem(ICON_BLANK" Paste Into", "Ctrl+Shift+V", &m_instanceContextMenuActions.PasteInto);
            ImGui::MenuItem(ICON_PAGE_COPY" Duplicate", "Ctrl+D", &m_instanceContextMenuActions.Duplicate);
            ImGui::MenuItem(ICON_DELETE" Delete", "Del", &m_instanceContextMenuActions.Delete);
            ImGui::MenuItem(ICON_PENCIL" Rename", "", &m_instanceContextMenuActions.Rename);
            ImGui::Separator();
            ImGui::MenuItem(ICON_SHAPE_GROUP" Group", "Ctrl+G", &m_instanceContextMenuActions.Group);
            ImGui::MenuItem(ICON_SHAPE_UNGROUP" Ungroup", "Ctrl+U", &m_instanceContextMenuActions.Ungroup);
            ImGui::Separator();
            ImGui::MenuItem(ICON_BRICK_ADD" Insert Part", "", &m_instanceContextMenuActions.InsertPart);
            ImGui::MenuItem(ICON_BRICK_ADD" Insert Object", "", &m_instanceContextMenuActions.InsertPart);
            ImGui::EndPopup();
        }
    }

    if(skip){
        for(Instance* child: childs){
            RenderExplorerElement(child);
        }
        if(show)ImGui::TreePop();
    }
@ocornut ocornut added the drag drop drag and drop label Nov 8, 2024
@ocornut
Copy link
Owner

ocornut commented Nov 8, 2024

Hello,
Your code is missing details, but it would be good if you can narrow this into a more minimal repro can I can paste anywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
drag drop drag and drop
Projects
None yet
Development

No branches or pull requests

2 participants