Here’s a scenario that I haven’t been able to figure out any satisfactory solution to. I have a list of widgets that I loop over, each one having an event I want to bind to, that causes an action. That action relying on data that correlates to the widget itself. An example being, having an inventory system that is comprised of a grid of buttons, each button containing data from an Item Object.
Here’s an example image:
In the example, I want to get the widgets themselves, but in practice I also want the Item data. The Widget’s are dumb - they merely present the data. One approach that worked, was to have the widgets store an integer, which correlates to the index of the for-loop, and then having that integer be passed along to the event. I don’t like this solution, it seemed flaky to me. I’d also like to keep the widgets as dumb as possible, without having them store anything, ideally.
Am I using a wrong approach? What would be a “best practice” when binding lists of widgets?