2025-12-01 2:07 AM - edited 2025-12-01 2:09 AM
I have the need to access items of a scroll wheel that are not visible on the screen (but that are already initialized)
For instance, I have a scroll wheel with each items a toggle button.
With the ScrollUpdateItem I'm able to set the correct index to the item with
ScrollUpdateItem(alarmsItem& item, int16_t itemIndex)
{ item.setIndex(itemIndex)where setIndex is a function that set the index in the item
Now, this works but, I've got the issue when it comes to the callback of each toggle.
For instance, once a callback is called, I need to process items different from the one selected so, I need to access the SelectorScrollListItems
For some reason, despite setting SelectorScroll.setNumberOfItems(6); I'm seeing TouchGFX generating touchgfx::DrawableListItems<alarmsItem, 5> SelectorScrollListItems; so, when I try to access SelectorScrollListItems[5] I'm seeing the call to the assert
TYPE& operator[](int index)
{
assert(index >= 0 && index < SIZE);
return element[index];
}why is that?
How do I fix it?
PS. TouchGFX Designer has the correct number of items set as well
2025-12-01 2:18 AM - edited 2025-12-01 3:10 AM
I think, ultimately, the code generated by TouchGFX Designer is bugged and/or wrong. If I set a numberOfItems in the designer, the corrispondent
touchgfx::DrawableListItems<myItem, numberOfItems>should reflect it. Instead, it is generate with a fixed value
touchgfx::DrawableListItems<myItem, 5>and in the SetupScreen it got initialized wrongly
for (int i = 0; i < mySelectorScrollListItems.getNumberOfDrawables(); i++)
{
mySelectorScrollListItems[i].initialize();
}@JohanAstrup @Osman SOYKURT @LouisB
Your example shows different sizes in the Base hpp that can't be reporduced with the current version of TouchGFX Designer 4.26 https://support.touchgfx.com/docs/development/ui-development/ui-components/containers/scroll-wheel
touchgfx::DrawableListItems<CustomContainer1, 6> scrollWheel1ListItems;
touchgfx::DrawableListItems<CustomContainer2, 2> scrollWheel1SelectedListItems;This seems to be a 2 years old issue https://community.st.com/t5/stm32-mcus-touchgfx-and-gui/touchgfx-support-needed-adding-more-than-6-elements-to-a-scroll/td-p/52563
I've also noticed that the array containing the items (ListItems) is a circular one. So when a new item is shown on the screen and the 5 items of the array are full, it overwrite the one at index 0
2025-12-01 4:24 AM
It's been a while since I worked with TouchGFX, but I think I can help with this explanation:
The scroll wheel and similar lists only generate as many graphic objects (items) as actually fit in the scroll wheel area (or one more). When scrolling, the “pushed out” items are then recycled and pushed back into the image on the other side with new content using ScrollUpdateItem(alarmsItem& item, int16_t itemIndex). So you have to store information elsewhere (in your own data array) and transfer it to the objects in the ScrollUpdateItem() callback.
2025-12-01 4:32 AM
Thanks for the explanation!
This is not documented anywhere, but it matches the behavior I'm seeing.
I would suggest updating the documentation underlying the fact that the array generated by TouchGFX doesn't match the actual dimensions of all the elements in the view, but just a smaller part
2025-12-01 7:07 AM - edited 2025-12-01 7:09 AM
2025-12-01 7:48 AM
Thanks for pointing out the discussions.
Those are good conversations, but again, I can't see this behavior described in the official docs. It would be very helpful.
2025-12-01 8:31 AM - edited 2025-12-02 1:10 PM
It is not, and I think the reason is that “it is obvious.” It’s obvious to me now, but I was confused just like you were.
“DrawableItems” are the items visible on the display, number of these is autogenerated based on view dimentions. That is why there is only
getNumberOfDrawables()
and not
setNumberOfDrawables()
because the number of drawables can’t be changed - "obviously".
In contrast, the functions that use the plain word “Items” refer to the items in your data list. That’s why you have both
setNumberOfItems()
getNumberOfItems()
2025-12-01 11:34 PM
So, to summarize for everyone who'll come:
2025-12-02 1:08 AM
Hello @nico23.
I completely agree that it is not very visible in the documentation and that it should ideally be in the Scroll Wheel page. However, just for future reference, you can find this in the documentation:
"The ScrollWheel uses the DrawableList to make it possible to handle a huge number of items using only a limited number of drawables by reusing drawables that are no longer in view."
https://support.touchgfx.com/docs/api/classes/classtouchgfx_1_1_scroll_wheel
"A container able to display many items using only a few drawables. This is done by only having drawables for visible items, and populating these drawables with new content when each of these become visible."
https://support.touchgfx.com/docs/api/classes/classtouchgfx_1_1_drawable_list
Best regards,
Johan