Coder Social home page Coder Social logo

Drag and Drop from Menubar about imgui HOT 5 CLOSED

BraunSilas avatar BraunSilas commented on May 30, 2024
Drag and Drop from Menubar

from imgui.

Comments (5)

GamingMinds-DanielC avatar GamingMinds-DanielC commented on May 30, 2024

You need to call BeginDragDropTarget() after submitting any widget that you want as a potential drop target. And definitely not inside of a BeginDragDropSource() conditional. Take a look at the drag&drop copy/swap example in the demo window for reference.

from imgui.

ocornut avatar ocornut commented on May 30, 2024

(Note that I added an assert to detect nested BeginDragDropTarget()/BeginDragDropSource(), but this specific error won't be caught as it is merely in the conditional block)

from imgui.

BraunSilas avatar BraunSilas commented on May 30, 2024

@GamingMinds-DanielC yes you are correct let me fix that. Reading through the documentation and applying your feedback I get get to this 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();
}
ImGui::EndMenu();
}
ImGui::EndMenuBar();

ImGui::BeginChild("drop here");
ImGui::EndChild();
if (ImGui::BeginDragDropTarget()) {
    if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload("DND_DEMO_CELL")) {
        SDL_Log("Droped :%d", taken);
    }
    ImGui::EndDragDropTarget();
}

`

It does run, but I am still not able to begin the DragDropSource.(as in I still don't see a tooltip or the SDL.Log).
Am I making any other mistakes?

from imgui.

GamingMinds-DanielC avatar GamingMinds-DanielC commented on May 30, 2024

One mistake I see is that you call ImGui::EndMenuBar() unconditionally. Everything after ImGui::BeginMenuBar() up to and including ImGui::EndMenuBar() must be called if and ONLY if ImGui::BeginMenuBar() returns true.

That's not why it doesn't work though. I have never tested drag&drop with menu items before, but a quick test suggests that ImGui::MenuItem() doesn't support it. Since you can put any type of widget inside of a menu, try replacing your menu item with ImGui::Selectable(), that should work.

from imgui.

BraunSilas avatar BraunSilas commented on May 30, 2024

Thank you @GamingMinds-DanielC
You're the boss!

@ocornut It would be nice for MenuItem() to support drag and drop.
Its not a must, since we can exchange it. but it would be convenient and intuitive.

from imgui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.