Drag and Drop from Menubar #7504

Closed
opened 2024-04-17 12:58:58 +00:00 by BraunSilas · 0 comments
BraunSilas commented 2024-04-17 12:58:58 +00:00 (Migrated from github.com)

Version/Branch of Dear ImGui:

v1.90.4 / Main

Back-ends:

imgui_impl_sdl2.cpp + sdl2renderer.cpp

Compiler, OS:

Windows 10 + CLion + Bundled MinGW

Full config/build information:

No response

Details:

I want to create a drag and drop functionality, where I can go in Menubar and enter a submenu and then drag an object into a child in the window.

While I was able to drag and drop all kind of Objects in a window I wasn't able to make it work within the Menubar.

Thank you for your help

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:


    ImGui::BeginMenuBar();
    if(ImGui::BeginMenu("Menu")){
        ImGui::MenuItem("Item");
        if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) {
            ImGui::SetDragDropPayload("DND_DEMO_CELL", &taken, sizeof(int));
            SDL_Log("test works");
            ImGui::Text("Swap %s", taken);
            ImGui::EndDragDropSource();
            if (ImGui::BeginDragDropTarget()) {
                if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload("DND_DEMO_CELL")) {
                    IM_ASSERT(payload->DataSize == sizeof(int));
                        SDL_Log("Droped :%d", taken);
                    }
                }
                ImGui::EndDragDropTarget();
            }
        ImGui::EndMenu();
    }
    ImGui::EndMenuBar();
### Version/Branch of Dear ImGui: v1.90.4 / Main ### Back-ends: imgui_impl_sdl2.cpp + sdl2renderer.cpp ### Compiler, OS: Windows 10 + CLion + Bundled MinGW ### Full config/build information: _No response_ ### Details: I want to create a drag and drop functionality, where I can go in Menubar and enter a submenu and then drag an object into a child in the window. While I was able to drag and drop all kind of Objects in a window I wasn't able to make it work within the Menubar. Thank you for your help ### Screenshots/Video: _No response_ ### Minimal, Complete and Verifiable Example code: ```ImGui::Begin("Custom Routines", 0, ImGuiWindowFlags_MenuBar);// ImGui::BeginMenuBar(); if(ImGui::BeginMenu("Menu")){ ImGui::MenuItem("Item"); if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) { ImGui::SetDragDropPayload("DND_DEMO_CELL", &taken, sizeof(int)); SDL_Log("test works"); ImGui::Text("Swap %s", taken); ImGui::EndDragDropSource(); if (ImGui::BeginDragDropTarget()) { if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload("DND_DEMO_CELL")) { IM_ASSERT(payload->DataSize == sizeof(int)); SDL_Log("Droped :%d", taken); } } ImGui::EndDragDropTarget(); } ImGui::EndMenu(); } ImGui::EndMenuBar(); ```
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#7504
No description provided.