cancel
Showing results for 
Search instead for 
Did you mean: 

Update item in scroll wheel without scrolling

Pirol
Associate III

I have a scroll wheel with selected item. Is it possible to update the selected item, e.g. its font color, when the modelListener notifys the screen that a certain event has happened?

Example: Let's assume the model contains a counter and notifys the screen if the current value is even or odd. For even values, the text of the selected item in the scroll wheel should be blue and for odd values green.

How can I achieve this?

I managed to kind of do it by calling a function that does the follwing:

void ScrollWheelScreenView::updateSelectedItem
{ 
    touchgfx::Drawable* d = scrollWheel1SelectedListItems.getDrawable(0);
    ContainerSelectedScrollItem* cc = (ContainerSelectedScrollItem*)d;
    cc->setOddOrEven();
    cc->setTextAndIcon(indexCenterItem - 1)
}

This function is called in the presenter-implementation of the notify-function. The text color is updated, but the text itself is not always correct: If the odd/even-update happens while scrolling, the text of the next or previous item is displayed.

1 ACCEPTED SOLUTION

Accepted Solutions
Pirol
Associate III

Today, I got it working. I will document it here in case someone has the same question. It is not the best solution but at least it works for me.

For me, one problem when working with the scroll wheel is to get the indeces right. In a scroll wheel with selected item, there are four different indices: the container index of not-selected items, the item index of not selected items, the container index of selected items and the item index of selected items.

As I wanted to change the appearance of the selected item, only the two latter ones were relevant for me.

The list with the selected items contains two (= numberOfListItems) items: the one that is shown and the next one (the one below or above). It would not hurt if both of the items were updated so I just looped through the container index.

To get the index of the selected item, you could use getSelectedItem. But I needed the item index of both items. So I added a member variable and a getter to my custom container CCSelectedScrollItem. The getter is called in the code below.

void ScreenView::updateItemsInSelectedList()
{
    int16_t numberOfListItems = scrollWheel1SelectedListItems.getNumberOfDrawables();
    touchgfx::DrawableListItemsInterface* items = &scrollWheel1SelectedListItems;
    for (int16_t containerIndex = 0; containerIndex < numberOfListItems; containerIndex++)
    {
        touchgfx::Drawable* d= items->getDrawable(containerIndex);
        CCSelectedScrollItem* c = (CCSelectedScrollItem*)d;
        int16_t itemNumber = cc->getItemNumber();
        updateItemCallbackHandler(items, containerIndex, itemNumber);
    }
}

The function updateItemsInSelectedList() is called in the presenter of the view in the function that implements the notify-function of the value that should be updated.

View solution in original post

5 REPLIES 5
MM..1
Chief III

You require invoke scrollWheel1UpdateCenterItem where you need place setodd ....

with force

itemChanged(int itemIndex)

read API ScrollWheel | TouchGFX Documentation

Yoann KLEIN
ST Employee

Hello @Pirol​,

You can also take a look at this project, that enables the user to scroll to the bottom or the top of a scrollable container after pressing a button. It could help you change the current item in your list or wheel.

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX
Pirol
Associate III

Thank you for your suggestions.

Priorities have shifted so that I did not have the time to fully work through everything yet, but I will work on it later and will then let you know if I achieved what I needed. Or come back with more questions...

Pirol
Associate III

Today, I got it working. I will document it here in case someone has the same question. It is not the best solution but at least it works for me.

For me, one problem when working with the scroll wheel is to get the indeces right. In a scroll wheel with selected item, there are four different indices: the container index of not-selected items, the item index of not selected items, the container index of selected items and the item index of selected items.

As I wanted to change the appearance of the selected item, only the two latter ones were relevant for me.

The list with the selected items contains two (= numberOfListItems) items: the one that is shown and the next one (the one below or above). It would not hurt if both of the items were updated so I just looped through the container index.

To get the index of the selected item, you could use getSelectedItem. But I needed the item index of both items. So I added a member variable and a getter to my custom container CCSelectedScrollItem. The getter is called in the code below.

void ScreenView::updateItemsInSelectedList()
{
    int16_t numberOfListItems = scrollWheel1SelectedListItems.getNumberOfDrawables();
    touchgfx::DrawableListItemsInterface* items = &scrollWheel1SelectedListItems;
    for (int16_t containerIndex = 0; containerIndex < numberOfListItems; containerIndex++)
    {
        touchgfx::Drawable* d= items->getDrawable(containerIndex);
        CCSelectedScrollItem* c = (CCSelectedScrollItem*)d;
        int16_t itemNumber = cc->getItemNumber();
        updateItemCallbackHandler(items, containerIndex, itemNumber);
    }
}

The function updateItemsInSelectedList() is called in the presenter of the view in the function that implements the notify-function of the value that should be updated.

Hi pirol, your post is intresting but not so comprensible...

cc->getItemNumber();

exist? I can't find this methode, can you explane how system work? thanks...