cancel
Showing results for 
Search instead for 
Did you mean: 

Scroll List Item Selected Callback

Tales Somensi
Associate II

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

2 REPLIES 2
Alexandre RENOUX
Principal

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

Tales Somensi
Associate II

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.