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?
2025-01-06 4:22 AM
I've created an example project (simulator only) that implements a scrollist with buttons.
This project has 2 bugs:
2025-02-20 7:38 AM
Hello @unsigned_char_array ,
Are you still blocked on this?
I looked at your project and I have added a few toggle buttons to be able to test more.
It seems you are not able to scroll when one of your buttons is not on because then you won't have enough elements so that it makes sense to scroll.
This is because even if you can manually scroll, you should remove the "+1" to your scroll down function. When adding multiple element, I realized that when I was scrolling down, it would always scroll 2 element at a time.
Please find attached the ST scrollList example modified using your functions to enable scroll up and scroll down. Note that the code is directly inside the interactions.
Regards,
2025-02-20 9:16 AM
The project is on hold temporarily, but I hope to soon return to this project. This is indeed a blocking issue. But I feel like making a scroll list from scratch (one without flashy animations) would be easier then modifying the existing one.
The example you gave doesn't involve a dynamic list that can change at run time. That's what I was looking for. A list of active errors. A new error might show up when in the error screen.
2025-02-21 1:24 AM
Hello @unsigned_char_array ,
Sure, on the example I shared, I just changed your code so it would go down one item at a time instead of 2 items at a time.
Please find attached your previous project with the small change to go down a single item instead of 2.
I have also added a few potential error messages so you can do a longer list to test.
however, I did not found how to remove the error messages when unchecking :) but that doesn't bother the testing.
Maybe it would be possible to do what you want to do by rewritting the scrollList widget.
You could copy the code of the scrollList to create a custom container yourself.
I think what is blocking the use of the scrollList is that we are missing a function such as "getCurrentSelectedItem" (but you seem to have found a way to get the current selected item number) and that the function animateToItem just scroll until the desired item is inside the visible part of the scrollList so it the item is "below", it will scroll up until the item is a bottom of the visible scrollList but if it is above, it will scroll down until it is a the position of the selected element.
If you manage to add the first function and to modify the second function, yo should have everything you need.
Please tell me if that explanation is not clear / if you want to hear more.
Regards,