cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to access items in a scroll wheel that are not visible on the screen

nico23
Senior III

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

nico23_0-1764583732068.png

 

8 REPLIES 8
nico23
Senior III

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

tdecker2
Associate III

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.

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

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.

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()

nico23
Senior III

 

So, to summarize for everyone who'll come:

  • When creating a scroll list, the array that will be created is not the number of elements you have set in the TouchGFX Designer, but, instead, the size of elements that will be visible during runtime + 1
  • You need to create a separate structure to save your logic regarding the elements you want to have in your scroll list. To do so, your only method is to override scrollListUpdateItem and implement your own logic.
  • If you need to update items outside of the ones actually visible, you can't use the array provided by TouchGFX, as it is automatically refreshed every time a new item is visible and the order is dictated by TouchGFX during runtime. The way you would do it is to update your own data structure, and then check when visible and refresh it
JohanAstrup
ST Employee

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