2021-10-06 07:07 AM
Hi,
I want to set a common interaction for all buttons on screen. For this, I configured button interactions to call the same virtual function ButtonClicked(). How could I determine in this function, which button was clicked? Is there a way to tell TouchGFX to create a virtual function with a parameter of the clicked button?
Thank You
Solved! Go to Solution.
2021-10-06 07:37 AM
If you look in the generated code for your screen's View, you'll see exactly how to do this because TouchGFX actually does exactly what you want to accomplish behind the scenes when you create your interaction :)
I'll explain the code. First you need a Callback object, and a function that gets called when the Callback is triggered. In your screen View code you initialize the Callback object with the callback handler function as a parameter, then you register the buttons with the callback. A parameter of your callback function is a pointer to the button that was clicked. You can then compare that pointer against the addresses of various buttons on your screen. You'll see that in the generated code, each button leads to the same result - calling your virtual function.
You should use the TouchGFX tag when you ask questions in the future!
2021-10-06 07:37 AM
If you look in the generated code for your screen's View, you'll see exactly how to do this because TouchGFX actually does exactly what you want to accomplish behind the scenes when you create your interaction :)
I'll explain the code. First you need a Callback object, and a function that gets called when the Callback is triggered. In your screen View code you initialize the Callback object with the callback handler function as a parameter, then you register the buttons with the callback. A parameter of your callback function is a pointer to the button that was clicked. You can then compare that pointer against the addresses of various buttons on your screen. You'll see that in the generated code, each button leads to the same result - calling your virtual function.
You should use the TouchGFX tag when you ask questions in the future!
2021-10-07 06:35 AM
Thanks for detailed explanation.