I do have a component which has a button as one of its children. The button has an event CLICKED that triggers a function callback which is correctly exported in ui_events.c. I have 8 instances of this component, layed out in a “grid” fashion, like an array counting instance variable trailing number 1-8 from left to right. In the event callback I’d like to have a reference on which instance id the event has occurred (best would be the trailing number of the instance variable, as this indicated the right order automatically in my layout casem or by using user_data payload).
I studied the ui_comp.c code which uses callback user data to hold a reference to the component - but this is the wrong way around for me. I also tried to set a user_data on my button, hoping I can retrieve that over the event e argument but it gets me a reference of something else (the component?). There must be a way to nicely retrieve the instance id either as a user_data payload or by the framework something like the id of the array holding all instance vars.
I need an example code which shows how to achieve this, in either way:
- using user_data which then would hold a primitive integer as an index.
- using a parent of parent traversal until I reached my component (which is a pane) which I can then compare because my main program has an array of the component instance var.
- any other trick that I missed to see. I really think the developers of the component feature has thought about this usecase, otherwise the callback on component definition level wouldn’t make sense, as the event always happens on an instance during runtime.
- SquareLine Studio version:
- Operating system:
- Target hardware: