ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
60.64k stars 10.24k forks source link

Drag & Drop into viewport. #5204

Open instinkt900 opened 2 years ago

instinkt900 commented 2 years ago

Version/Branch of Dear ImGui:

Version: 1.88 (WIP) Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_sdl.cpp + imgui_impl_sdl_renderer.cpp Compiler: MSVC 1929 Operating System: Win64

My Issue/Question:

I am currently using imgui docking windows over an sdl viewport where I am rendering some SDL graphics. I'm using ImGui::DockSpaceOverViewport(nullptr, ImGuiDockNodeFlags_PassthruCentralNode); to setup the dockspace and I have an ImGui window with a list inside and I would like to be able to drag items onto the viewport but I am unsure how to set this up.

I was made aware that BeginDragDropTarget works on items not windows and that BeginDragDropTargetCustom might be a better option but I don't know what ID should be in my situation. I have also tried making an invisible window with a dummy inside and that gets to a point where I can drop the item onto the viewport area, but only if the window flags allow mouse input but when that is set I cant interact with my viewport under the window.

Below is a screenshot of my application. You can see the docked imgui windows over the SDL viewport where the white grid is visible. The list on the right side is what I would like to drag from, onto the gridded area. What are my options? I just want to drop something onto the canvas.

Screenshots/Video

image

AlexvZyl commented 2 years ago

+1 for also wanting this.

rokups commented 2 years ago

I have also tried making an invisible window with a dummy inside and that gets to a point where I can drop the item onto the viewport area, but only if the window flags allow mouse input but when that is set I cant interact with my viewport under the window.

You are almost there. You could only render this dummy window when drag operation is in progress. You can check if a drag operation is active by checking if ImGui::GetDragDropPayload() returns a non-null pointer.

NPatch commented 2 years ago

I also had the same issue and the problem, AFAICT, with ImGui::BeginDragDropTarget() is that it uses the last item in the window, probably using a different rect than the one you want. Eventually used ImGui::BeginDragDropTargetCustom(window->ContentRegionRect, window->ID) as it uses what you give it straight up. Not sure if there's some edge case I'm ignoring that I'll later be faced with. I wonder what Omar thinks about this.