2025-01-03 11:03 AM
I want to programmatically scroll up and down a scrollList. I want a button push or something in the application to trigger scrolling up or down one item or 1 page.
The goal is a list of error codes. Right now they are just strings with numbers between 1 and 6.
I tried it with animateToItem, but I get strange behavior.
My list has 3.5 items visible, so 4 drawable items. The array scrollListListItems generated by TouchGFX is 5 drawable items.
It has up to 6 items in the list. But the number is variable (I used checkmarks to add or remove items from the list).
If I shorten my list to 5 items no scrolling happens programmatically.
The indexes of the items are not in order in the drawables. For instance 5,1,2,3,4.
void ErrorScreenView::scrollUpFunction(void)
{
int16_t minIndex = INT16_MAX;
int16_t maxIndex = -1;
for (int i = 0; i < scrollListListItems.getNumberOfDrawables(); i++)
{
int16_t itemIndex = scrollList.getItem(i);
if (itemIndex >= 0)
{
minIndex = std::min(minIndex, itemIndex);
maxIndex = std::max(maxIndex, itemIndex);
}
}
if (minIndex > 0)
{
scrollList.animateToItem(minIndex - 1);
}
}
void ErrorScreenView::scrollDownFunction(void)
{
int16_t minIndex = INT16_MAX;
int16_t maxIndex = -1;
for (int i = 0; i < scrollListListItems.getNumberOfDrawables(); i++)
{
int16_t itemIndex = scrollList.getItem(i);
if (itemIndex >= 0)
{
minIndex = std::min(minIndex, itemIndex);
maxIndex = std::max(maxIndex, itemIndex);
}
}
if (maxIndex < (scrollList.getNumberOfItems() - 1))
{
scrollList.animateToItem(maxIndex + 1);
}
}
Other functionality of the list I got working:
When scrolling programmatically these two functions don't work properly either. Clicking an item selects the wrong one and old items can linger unless I scroll manually.
Is there a way to programmatically trigger what works fine with touch?