353 views
in GUI Development by
Hello.

I've run into the error related to VerticalList. When I'm moving inside the list from bottom to the top and OnLoadItem signal is sent by the list, within this slot GetViewForItem call returns invalid item. I'm 100% sure that my item is inside the internal cache of the list, GetViewForItem returns non-null value BUT it returns another item in the list!

For example my list contains 29 items total. Valid tail of the list is 28, valid head is 22. When I'm requesting GetViewForItem(23) - next item to the currently drawn one it returns item number 24!
It looks like during scrolling up the list the pointer view.next is not updated for the currently drawn item.

Interestingly that the same code returns valid item when the list is scrolled from top to bottom.  

Are there any workarounds of this issue? (except from holding separate array of data - I can't afford this).

Best regards,
Maxim.
by
I've added a workaround like this when scrolling upside:

// Filling the list from bottom to top.
    var Menus::MenuItem_TripCombinedItem below_item = (Menus::MenuItem_TripCombinedItem)VerticalList.GetViewForItem(list_item_index+1);

    if (below_item == null)
      throw "This is impossible!";

    // Workaraond of the Vertical list issue
    below_item = (Menus::MenuItem_TripCombinedItem)below_item.prev;
    
    if (below_item == null)
      throw "Workaround failed";

And it looks to be working.

1 Answer

0 votes
by

Hello Maxim,

well, the problem is related to the invocation of GetViewForItem() in context of the OnLoadItem method. Conceptionally OnLoadItem is intended to take care of the pure loading process of the actual item only. Accessing other items during this update phase it not guaranteed to work correctly. 

The list component is optimized to reuse existing items while the user is scrolling the list. You can imagine, after the user has scrolled the list, the update algorithm iterates through the actually existing item views and removes all the views which have become invisible arranging them at the opposite end of the list. Then the rearranged view is loaded with its new content (via OnLoadItem slot method).

Until this loop is done, the order of item views will change permanently. Moreover as long as the OnLoadItem has not been signaled for an item, the corresponding view may contain old contents. Therefore, depending on whether you are trying to access the view for an already updated item or an item still waiting for its update, the methhod GetViewForItem() may return the corect wrong value.

In other words, since it is not possible to load all items at once atomically, some of the items are already up to date while other are still waiting for the update. Accessing these not updated items with GetViewForItem() will inevitable lead to a wrong returned value.

I have updated our online documentation pointing out, that GetViewForItem() is not intended to be used in context of OnLoadItem.

Additionally I have put this issue on our to-do list. We will discuss how to proceed with this problem. Probably, we will add some error handling, so GetViewForItem() can detect which items are already up-to-date and valid and which items are still unsure. Accessing such 'unsure' item will return null.

Well, I have no workaround for you. You should avoid using GetViewForItem() in context of OnLoadItem. Please see also Access list items and views,

Best reagrds

Paul Banach

Embedded Wizard Website | Privacy Policy | Imprint

...