Skip to main content
Tales Somensi
Associate II
March 28, 2020
Question

Scroll List Item Selected Callback

  • March 28, 2020
  • 3 replies
  • 2170 views

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

3 replies

Alexandre RENOUX
Visitor II
March 30, 2020

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
March 31, 2020

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.

Lead II
December 30, 2024

Thanks. This helped me out. I had to call setItemSelectedCallback too:

scrollList.setItemSelectedCallback(scrollListItemSelectedCallback);

 

To get the selected item:

	Drawable* d = scrollListListItems.getDrawable(itemIndex % scrollListListItems.getNumberOfDrawables());
	YourItemType* itemPtr = (YourItemType*)d;

 (don't forget to unselect others if you can only select one at the same time)

Also don't forget to overload scrollListUpdateItem so items keep their proper selection state:

virtual void scrollListUpdateItem(YourItemType& item, int16_t itemIndex);

 

"Kudo posts if you have the same problem and kudo replies if the solution works.Click ""Accept as Solution"" if a reply solved your problem. If no solution was posted please answer with your own."