Comments (5)
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.
(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.
@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.
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.
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)
- Docking without a central node? HOT 1
- Widget Rotations HOT 1
- Created Docked layout only using `imgui.h` HOT 2
- compile error with docking branch and SDL3 HOT 1
- Text followed by SameLine and then SmallButton inside table cell disables SmallButton HOT 5
- Ctrl+Backspace behavior in TextInput HOT 4
- Restoring layout from memory rearranges windows and sometimes crashes. HOT 2
- Splitters weird padding HOT 10
- Hantverk'n Video Game Graphics and Testing Settings GUI HOT 3
- DX12 backend can't render into a multisampled frame buffer HOT 2
- Question: fine-tuning the window scrollbar HOT 5
- Trying to get a 3 part rendering pipeline working but events aren't processed. HOT 3
- Are there ImGui APIs that can throw? HOT 4
- Unable to checkout v1.89.8 from Jetbrains IDE using tag HOT 2
- Question: GetCurrentWindow internal function HOT 3
- LabelText can't auto set item size
- Mouse action functions (IsItemHovered, IsMouseClicked,IsMouseDown,IsMouseReleased, etc.) always return false for overlapped item. HOT 10
- Hang when destroying viewports in example_sdl2_opengl3 (only when vsync is deactivated) HOT 6
- Imgui for arm64
- Question: Auto tile panels HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imgui.