cancel
Showing results for 
Search instead for 
Did you mean: 

TouchGFX ScrollWheel widget index does not match UI

TLe.4
Associate II

I have noticed what might be a bug in the updateItemCallbackHandler() in my screen's ViewBase file where the itemIndex consistently moves ahead 1 index when I swipe up.

/* Scroll Wheel Item Update response to swiping is generated by TouchGFX */
void ModeScreenViewBase::updateItemCallbackHandler(touchgfx::DrawableListItemsInterface* items, int16_t containerIndex, int16_t itemIndex)
{
    if (items == &scrollWheelModeListItems)
    {
        touchgfx::Drawable* d = items->getDrawable(containerIndex);
        ValuesMenu* cc = (ValuesMenu*)d;
        scrollWheelModeUpdateItem(*cc, itemIndex);
    }
    else if (items == &scrollWheelModeSelectedListItems)
    {
        touchgfx::Drawable* d = items->getDrawable(containerIndex);
        ValuesMenu* cc = (ValuesMenu*)d;
        scrollWheelModeUpdateCenterItem(*cc, itemIndex);
    }
}

During debugging, I noticed my value for swiping down to decrement by 1 but swiping up increments by 1 twice initially. The function scrollWheelModeUpdateCenterItem(), which references itemIndex, is called twice when swiping up for after entering the screen or after swiping down.

0693W000008yw5aQAA.pngNote: values in the scroll wheel are wildcard placeholders. The expected behavior is the string highlighted is supposed to match the center item in the scroll wheel. The text of the center item and my string match when swiping down. However, the string using the ViewBase index will be the next item in the scroll wheel.

/* Prints highlighted string */
Unicode::strncpy(textAreaSelectedModeBuffer, modeScreenList[itemIndex], TEXTAREASELECTEDMODE_SIZE-1);
    ModeScreenViewBase::textAreaSelectedMode.setWildcard(textAreaSelectedModeBuffer);
    ModeScreenViewBase::textAreaSelectedMode.invalidate();

Additional Notes:

My Scroll Wheel animation and list appearance

0693W000008yw5fQAA.pngThe project is programmed onto a STM32429I-EVAL

1 ACCEPTED SOLUTION

Accepted Solutions

Sorry, I realized that my first advice is relevant only for Non-Circular Wheel.

But, I've tried another approach. I was wrong in the answer, actually there is scrollWheelAnimationEndCallback for handling animation end event.

class Wheel: public WheelBase
{
public:
 
  Wheel();
  virtual ~Wheel() {}
  virtual void initialize();
 
protected:
 
  Callback<Wheel> scrollWheelAnimationEndCallback;
  void scrollWheelAnimationEndHandler(void);
};
 
Wheel::Wheel() :
scrollWheelAnimationEndCallback(this, &Wheel::scrollWheelAnimationEndHandler)
{
  wheel.setAnimationEndedCallback(scrollWheelAnimationEndCallback);
}
 
void Wheel::scrollWheelAnimationEndHandler(void)
{
  int correct_index = wheel.getSelectedItem();
}

If you call .getSelectedItem() at this point, selected item index will be correct.

View solution in original post

6 REPLIES 6
Sergey Bogaev
Associate II

I also encountered this problem. In one of the examples from TouchGFX Designer (Scroll Wheel and List Example, file Screen1View.cpp) I noticed that the item index is obtained in the function which is called at the end of the wheel movement animation (in the above example it is "scrollWheelAnimateToHandler" from Screen1View.cpp).

// The callback updates the selectedVal on the itemSelected parameter
void Screen1View::scrollWheelAnimateToHandler(int16_t itemSelected)
{
    selectedVal.invalidate();
    Unicode::snprintf(selectedValBuffer, SELECTEDVAL_SIZE, "%d", itemSelected);
}

In this file there is an example of how to use the callback to register this function.

This way I was able to get the correct index for further processing. 🙂

TLe.4
Associate II

Thanks for the response, I gave the handler callback from the example a try. The index of the center item was printed. My list has 8 items. When I scroll up, I get:

A 0

B 1

C 2

D 3

E 4

F 5

G 6

H 7

A 8

B 1

C 2

D 3

E 4

F 5

G 6

H 7

A 8

.....

The only time that A was 0 was when I scrolled down and then scrolled back to A. But when I keep scrolling the index ranges from 1-8. Now when I scroll down:

.....

G 6

H -1

A 0

B 1

C 2

D 3

E 4

F 5

G 6

H -1

A 0

.....

Printing out the index does illustrate scroll up gives me index 1-8 and scroll down gives me 0-6 with the last item being -1. Nothing out of the ordinary was present in the widget configuration. Were there similar results for your situation?

Thanks for the response, I gave the handler callback from the example a try. The index of the center item was printed. My list has 8 items. When I scroll up, I get:

A 0

B 1

C 2

D 3

E 4

F 5

G 6

H 7

A 8

B 1

C 2

D 3

E 4

F 5

G 6

H 7

A 8

.....

The only time that A was 0 was when I scrolled down and then scrolled back to A. But when I keep scrolling the index ranges from 1-8. Now when I scroll down:

.....

G 6

H -1

A 0

B 1

C 2

D 3

E 4

F 5

G 6

H -1

A 0

.....

Printing out the index does illustrate scroll up gives me index 1-8 and scroll down gives me 0-6 with the last item being -1. Nothing out of the ordinary was present in the widget configuration. Were there similar results for your situation?

I want to contribute more details after some testing. The values I listed above were from dragging the scroll wheel, which I believe is supposed to move the center item by 1 in the list as opposed to swiping which is >1. Whenever I perform a hard swipe on the wheel, the index values I print are inconsistent and there is no pattern. Sometimes I will get the correct index for the item and other times I will get an out of bounds index.

Swiping down gets me negative itemSelected and swiping up gets me a positive itemSelected e.g. 10 when my list size is 8. This is with using scrollWheelAnimateToHandler with callback as opposed to printing the list item in scrollWheelModeUpdateCenterItem() before.

Sorry, I realized that my first advice is relevant only for Non-Circular Wheel.

But, I've tried another approach. I was wrong in the answer, actually there is scrollWheelAnimationEndCallback for handling animation end event.

class Wheel: public WheelBase
{
public:
 
  Wheel();
  virtual ~Wheel() {}
  virtual void initialize();
 
protected:
 
  Callback<Wheel> scrollWheelAnimationEndCallback;
  void scrollWheelAnimationEndHandler(void);
};
 
Wheel::Wheel() :
scrollWheelAnimationEndCallback(this, &Wheel::scrollWheelAnimationEndHandler)
{
  wheel.setAnimationEndedCallback(scrollWheelAnimationEndCallback);
}
 
void Wheel::scrollWheelAnimationEndHandler(void)
{
  int correct_index = wheel.getSelectedItem();
}

If you call .getSelectedItem() at this point, selected item index will be correct.

Want to say getSelectedItem() was what I was looking for! The scroll items and index match now.