I want to implement drag’n’drop functionality in TreeView that allows fully re-arranging the TreeViewItems.
I’ve gotten the re-parenting working with the existing drag’n’drop functionality: You drag a TreeViewItem on top of an other, and the dragged item becomes the drop targets child in the tree.
The reordering of TreeViewItems I haven’t managed to figure out however! I expect there should be some functionality for highlighting the area between two TreeViewItems when one hovers over it during a drag’n’drop operation, during which moment dropping would mean inserting the dragged item between the items above and below the highlight, instead of making it the child of either.
I’ve been perusing the TreeView source to find some functionality that allows such functionality, but I’m none the wiser…
I’ve found this thing in the source called ‘dragInsertPointHighlight’, but I’m not sure if it is what I’m looking for, and it is not documented anywhere.
Any ideas? Perhaps an example of some JUCE code doing this or similar?
That’s already done automatically, I’m not sure why you’re not seeing it… Have a look at the treeviews in the introjucer, which let you drag things around to rearrange them.
I will do that!
In my attempt to keep the message concise I didn’t specify some details that I see now are necessary to the description:
What I do is make my own TreeViewItems, sub-classing from the TreeViewItem base class provided, and have them create their own components to be returned from createItemComponent().
So I have some of my own code in there to initiate the drag’n’drop in the mousedrag function, as when you have your own TreeViewItem classes and components it is no longer fully automatic in the TreeView.
I realize this circumvents much of the built in functionality that you describe, but I needed my TreeViewItems to contain various custom components (the tree is very central to my program), so just using the paintItem() function for my own custom drawing did not seem enough at the time I first started working with the tree.
Anyway, I will look at what the Introjucer does with the tree drag’n’drop, and see what code I need to write to replicate that while still using my own custom components in the tree.