How does the scrollwheel item update method work? The itemIndex is different from the currently selected item.
I use the scrollWheel widget for a menu structure. To set it's content I have used the method discribed in the STM32 Graphics: Getting Started with Scroll List Widget tutorial. The scrollWhel consists of 13 items and I use a dedicated template for the selected item. The automatically generated updateItemCallbackHandler hands itemIndex to scrollWheel1UpdateCenterItem function which I use to set the text for the currrently selected item.
void measureMenuView::scrollWheelMoveDwn(void)
{
int16_t scrollWheelSelectedItem = scrollWheel1.getSelectedItem();
scrollWheelSelectedItem++;
if (scrollWheelSelectedItem > scrollWheel1.getNumberOfItems())
scrollWheelSelectedItem = scrollWheel1.getNumberOfItems();
scrollWheel1.animateToItem(scrollWheelSelectedItem);
scrollWheel1.invalidate();
}
void measureMenuView::scrollWheel1UpdateCenterItem(secondaryMenuSelected& item, int16_t itemIndex)
{
item.setTextSelected(itemIndex, scrollWheel1.getNumberOfItems(), 0);
}
void secondaryMenuSelected::setTextSelected(int itemNo, int numberOfItems,
int screenNo)
{
switch (itemNo)// % numberOfItems)
{
case 0:
textSelected1.setTypedText(TypedText(T_OPTION1));
break;
case 1:
textSelected1.setTypedText(TypedText(T_OPTION2));
break;
case 2:
textSelected1.setTypedText(TypedText(T_OPTION3));
break;
case 3:
textSelected1.setTypedText(TypedText(T_OPTION4));
break;
case 4:
textSelected1.setTypedText(TypedText(T_OPTION5));
break;
case 5:
textSelected1.setTypedText(TypedText(T_OPTION6));
break;
case 6:
textSelected1.setTypedText(
TypedText(T_OPTION7));
break;
case 7:
textSelected1.setTypedText(TypedText(T_OPTION8));
break;
case 8:
textSelected1.setTypedText(TypedText(T_OPTION9));
break;
case 9:
textSelected1.setTypedText(TypedText(T_OPTION10));
break;
case 10:
textSelected1.setTypedText(TypedText(T_OPTION11));
break;
case 11:
textSelected1.setTypedText(TypedText(T_OPTION12));
break;
case 12:
textSelected1.setTypedText(TypedText(T_OPTION13));
break;
}
}It works as intended if I am just aiming to show the correct text but I would like to use the text width of the currently selected item to decide whether I have to scroll the text if it's wide or not. And this does not work because the text width is never (except for 0) the correct width currently selected item. This issue reflects in the textID of textSelected1 which is always one ahead of the currently selected item text.
textWidth = textSelected1.getTextWidth();Why is that and why does scrollWheel1UpdateCenterItem function gets called multiple times with just one button press.