I’ve been struggling for a while trying to get some DragAndDrop functionality working. I’ve tried it two different ways: using DragAndDropContainer and ComponentDragger.
I got CompontDragger working but didn’t do what I wanted. It lets me move a container around the screen. The DragAndDropContainer seemed closer to the behavior I want. The original container is still visible, and a translucent copy appears and drags when you start dragging.
However, the translucent dragged container is only visible within the original objects bounds. In the image below, the red/blue box is a DragAndDropContainer. The dark green box in the bottom right is a DragAndDropTarget.
There is something about the limitations of DragAndDrop or I’m fundamentally not understanding how to use it to accomplish: dragging the red/blue container over and drop it in the green container.
Any help or ideas would be appreciated. I can post the code but I feel it’s my understanding of DragAndDrop that’s wrong, not bugs in the simple example.
You might check out the DemoRunner that is provided with JUCE. If you look at the Widgets Demo, there is a “Drag & Drop” tab that demonstrates what you’re looking for. All of the relevant code is in the DragAndDropDemo class.
I removed the DragAndDropContainer inheritance on TargetSource and did have to move it to MainComponent at the top which I think would be obvious to the more experienced but I crashed the program on my first try to implement the proposed changes. I added a nullptr check to the assignment of “dragC” in order to catch the crash and figure out MainComponent needed to inherit Drag&DropContainer.
@Connorreviere Actually I’ve spent several days going through every dragging example in DemoRunner including the Widgets Demo trying to figure this out. That demo shows effectively how a DragAndDropTarget works, but the fact a ListBox was the only Target source meant it was missing the critical details for why my example didn’t work for a simple custom container. I needed a working example about exactly how to set this up for the mouseDrag() method on the source container. Because the demo uses a ListBox, there is no mouseDrag() in that file.
Thank you both for your prompt help. I’ll post the fixed code below in case someone finds this thread in a search.