‎2019-05-06 06:04 AM
Hello ,
I am working on a TouchGFX project with STM32f746-DISCO board
In one of my screens I have a scrollable list ( ScrollWheel object ) with 10 items.
The list is displayed correctly with the 10 items drawn on the screen.
However when I access listItems[7] ~ listItems[9] through code, the program crashes
I found this after trying to invalidate() for each item. I was able to reach until the 7th item only. And a crash occur whenever I try to reach anything beyond that.
The problem I think comes form ScreenViewBase.hpp file:
/*
* Member Declarations
*/
touchgfx::DrawableListItems<ChannelRow, 7> listItems;
TouchGFX keeps generating this line with size set to 7. no matter what is the value entered in the designer.
I tried changing the number of items from the designer to values less and higher than 7. With no success.
this file is write protected, and even when editing the value using external tools, TouchGFX keep regenerating this value.
I hope I am missing something and this is not a bug.
‎2019-05-07 12:05 AM
Hi @Abdullah İhsanoğlu​,
I understand your confusion. I think i know what you're confused about and perhaps rightfully so.
Imagine a list of 1000 items. If you were to allocate those all at the same time you would have a huge memory footprint. The 7 items you're seeing in your generated code are the amount of items that will currently fit into the visible area of your scroll list. The scroll lists offer callbacks to insert and remove items based on the position of the list. Try reducing or increasing the visual size of the list and keep an eye out for the generated code - I think you'll see that it changes the template argument based on how many items it thinks it can fit visually.
So, you're trying to reference elements that haven't been loaded yet. Does that make sense?
Best regards,
Martin
‎2019-05-07 12:09 AM
I hope you don't mind, but i edited the title of the post to better reflect the problem: "Cannot access certain elements in a ScrollList"
/Martin
‎2019-05-07 12:24 AM
I understand it , actually I figured it out to be this way as well since I wrote the post. =)
However, I still can't reference items properly ...
what I mean when I call listItems[0] , I want to be referencing the first item whatever is currently shown on the screen ..
OR
maybe if there is a way to know the real position of listItems[0] perspective to the total number of items .. just the position the real of the item
‎2019-05-09 12:28 AM
Any solution ?
‎2019-05-09 02:16 AM
You can't reference the first visible item as items[0]. This would require the list to constantly sort itself which would be ineffective use of resources. But you can get the currently active item and then do the lookup.