#How can I allow a player to rearrange nodes in a vbox by dragging and dropping them?

1 messages · Page 1 of 1 (latest)

supple sapphire
#

I'm currently making a to-do list to try to learn the UI system. I haven't yet figured out the best way to make the different items on the list draggable and droppable to rearrange using their handles.

I was thinking I could reparent the node outside of the vbox and have it follow the mouse, and then reparent it back to the vbox at a spot aligning with where it is released, but then I'm not yet sure how to detect where that spot is, and that seems like an overcomplicated solution.

I would love to hear how you would approach this problem, is there some easier method I haven't thought of?

The current alternative in mind I have would just be to add up/down arrows to move them up and down one index using move child, which would be straightforward but I think dragging would be a lot more satisfying.

azure sun
#

yeah the reparenting approach seems good. I don't know of any nodes with the ability to do this out of the box. There's a signal on all Control nodes called gui_input that you can connect to to know when that particular item got an input like a click. And as for finding the right place to drop in in the vbox list: you'd probably just have to loop all items in the vbox until you find the spot by comparing their y values to the dropped item when you release .