2020-03-28 10:53 AM
Hi. I've been working on a project with STM32 and touchGFX. I'm struggling with a simple issue that could be easily solved if I had more experience with the framework and with C++.
I'm working with a 7 inch touchscreen display. In one screen, i inserted a scrollList. I'm getting to change it's items and manipulate the list. However, the list items must be clickable. I discovered I have to create a GenericCallback and use scrollList.setItemSelectedCallback to set a function as a handler for item selected. What I'm facing is, I do not quite understand how to create the generic callback on ScreenView.hpp and ScreenView.cpp. Unfortunately, there is not an specific tutorial on touchGFX website to help with this. I've looked at every material available online, from documents to forums and tutorials. May you help me?
Thanks
2020-03-30 01:05 AM
Hi,
In TouchGFX Designer, you will find a perfect example called "Scroll Wheel and List Example" in UI Template. There's a callback created that is triggered every time you click on a item, and an image is updated accordingly.
/Alexandre
2020-03-31 03:25 PM
Thanks Alexandre, the template example has answered my question.
For whoever is struggling with the same issue, here's what I did:
In the ScreenView.hpp file:
class ScreenView : public ScreenViewBase
{
public:
// all your public stuff
protected:
// all your protected stuff
// this is the code that matters to the question
Callback<ScreenConfigView, int16_t> scrollListItemSelectedCallback;
void scrollListItemSelectedHandler(int16_t itemSelected);
};
In the ScreenView.cpp file:
// class constructor
ScreenView::ScreenView() : scrollListItemSelectedCallback(this, &ScreenConfigView::scrollListItemSelectedHandler)
{
// code
}
// function to be called every time an item is selected
void ScreenConfigView::scrollListItemSelectedHandler(int16_t itemSelected){
switch(itemSelected){
case 0:
// code for item 0
break;
case 1:
// code for item 1
break;
}
}
With this, every time an item inside your scrollList is selected, function scrollListItemSelectedHandler will be called with item index.
Best regards.