If you’re doing the whole thing for the very 1st time, I’d suggest following a tutorial (even though it may not be 100% what you need - just to get an idea of the logic behind it) as what I’ve posted may not contain every detail needed.
How about the part where the objects can be dragged and dropped?
As a kickstarter, consider the following:
- this would go into the widget that we’ll be dragging around - called wRubbish here
- the override dropdown is full of useful functionality
- here we’re detecting whether a specific mouse button is attempting to drag the widget about
- below, still in the same wRubbish widget, we override what happens when the dragging actually starts
- the above would create a Drag & Drop Operation that will handle most of the dragging process
We would then need to implement what happens when the abovementioned drag & drop operation terminates over a widget. You’d implement onDrop in the boxes mentioned in the previous posts.
The payload is the reference to dragged widget, here you’ll decide what happens to it and what other logic triggers.
Should I just follow this?
Whenever you see content by Mathew Wadstein, it’s pretty much guaranteed to be short, sweet, void of bull$ & straight to the point. Highly recommended if all you want is to learn core functionality behind a feature rather than follow a 36 episode tutorial series replicating creation of a MMO inventory.
Regarding this:
I hoped it could all work in just a single widget, if possible.
It could be done in a single widget but we don’t know how far this needs to be taken. If you’re planning on having more than the most basic functionality, it’s much more convenient to have widgets that can encapsulate the desired behaviour their parent does not need to know about.
It’s a pretty standard approach that allows you to stay a bit more flexible further down the road.