2025-02-12 06:55 AM - edited 2025-02-12 07:02 AM
Hi,
I have a scroll list that works perfekt in the simulator, but when running it on target (STM32H735) I need to set a periodic update of scollList.invalidate(), to get it to work. The problem is that only the first and last element show as selected, when scrolled to, but the function on each element is OK, i.e to switch language.
What can be the cause of this? Here is the code:
#include <gui/installation_lang_screen/Installation_LANGView.hpp>
#include <images/BitmapDatabase.hpp>
#include <texts/TextKeysAndLanguages.hpp>
Installation_LANGView::Installation_LANGView()
: currentIndex(0)
, languages {{
{ BITMAP_UNITED_STATES_ID, T_TEXT_ENGLISHUS, std::nullopt, std::nullopt },
{ BITMAP_FRANCE_ID, T_TEXT_FRANCE, std::nullopt, std::nullopt },
{ BITMAP_GERMANY_ID, T_TEXT_DEUTSCHE, std::nullopt, std::nullopt },
{ BITMAP_HUNGARY_ID, T_TEXT_MAGYAR, std::nullopt, std::nullopt },
{ BITMAP_ITALY_ID, T_TEXT_ITALIANO, std::nullopt, std::nullopt },
{ BITMAP_NETHERLANDS_ID, T_TEXT_NEDERLANDS, std::nullopt, std::nullopt }
}}
{
scrollList.setNumberOfItems(languages.size());
for (int i = 0; i < scrollList.getNumberOfItems(); i++) {
scrollListListItems[i].setup(languages[i]);
scrollListListItems[i].setIndex(i);
scrollListListItems[i].setUnselected();
}
scrollList.animateToItem(0);
scrollListListItems[0].setSelected();
scrollList.invalidate();
}
void Installation_LANGView::setupScreen()
{
Installation_LANGViewBase::setupScreen();
footer.showNavigationElement(POS_RIGHT, NAV_SET);
footer.showNavigationElement(POS_CENTER, NAV_MOVE_UPDOWN);
footer.showNavigationElement(POS_LEFT, NAV_BACK);
}
void Installation_LANGView::tearDownScreen()
{
Installation_LANGViewBase::tearDownScreen();
}
void Installation_LANGView::scrollListUpdateItem(ListElement& item,
int16_t itemIndex)
{
if ((size_t)itemIndex < languages.size() && currentIndex < languages.size()) {
if(item.getIndex() == currentIndex)
{
item.setSelected();
} else {
item.setUnselected();
}
}
scrollList.invalidate();
}
void Installation_LANGView::scrollList_ItemSelectedHandler(int16_t itemSelected)
{
scrollList.animateToItem(itemSelected);
currentIndex = itemSelected;
for (int i = 0; i < scrollList.getNumberOfItems(); i++) {
scrollList.itemChanged(i);
}
}
void Installation_LANGView::goUp()
{
if (currentIndex > 0) {
scrollList_ItemSelectedHandler(currentIndex - 1);
}
}
void Installation_LANGView::goDown()
{
int16_t numItems = languages.size();
if (currentIndex < numItems - 1) {
scrollList_ItemSelectedHandler(currentIndex + 1);
}
}
void Installation_LANGView::enter()
{
if (scrollListListItems[0].isSelected()) {
Texts::setLanguage(US);
} else if (scrollListListItems[1].isSelected()) {
Texts::setLanguage(FR);
} else if (scrollListListItems[2].isSelected()) {
Texts::setLanguage(DE);
} else if (scrollListListItems[3].isSelected()) {
Texts::setLanguage(HU);
} else if (scrollListListItems[4].isSelected()) {
Texts::setLanguage(IT);
} else if (scrollListListItems[5].isSelected()) {
Texts::setLanguage(NL);
}
application().gotoMain_MenuScreenNoTransition();
}
void Installation_LANGView::updateScrollList()
{
// scrollList.invalidate();
}
2025-02-13 12:44 AM
Hello @MNils.2,
Could you add screenshots of the issue with the 1st and last element ?
BR,
2025-02-13 01:47 AM
2025-02-13 02:30 AM
And this only happens on the target but not the simulator right ?
2025-02-13 02:31 AM
Yes, it works fine in simulator.
2025-02-13 05:32 AM
Something with the current index might cause issues, try to debug it on the board and follow the value of "currentIndex". You also said "I need to set a periodic update of scollList.invalidate()", what happens if you dont ?
2025-02-13 05:46 AM
void Installation_LANGView::updateScrollList() { // scrollList.invalidate(); }
If I uncomment the srcollList.invalidate() which is Triggered on every tick, it works fine on target as well.
If I don't do it I get the 1:st and last issue:
The thing is that the function on every item works , but it does not shown as selected. So if I go down 1 step and press enter we switch languages to French. But the field is not shown selected.
It is only if I click 5 times and come to Nederland that the field shows that it is selected.
2025-02-13 06:05 AM
Then maybe the invalidation causes problem, in scrollList_ItemSelectedHandler, try to put an invalidate at the begining and the end of this function.
2025-02-13 11:05 PM
I tried that but unfortunately it behaves the same
2025-02-13 11:50 PM - edited 2025-02-14 12:04 AM
I inserted log print like this:
void Installation_LANGView::scrollListUpdateItem(ListElement& item,
int16_t itemIndex)
{
if(item.getIndex() == currentIndex)
{
item.setSelected();
#ifndef SIMULATOR
LOG_INF("UpdateItem, itemIndex %d Selected", itemIndex);
#endif
} else {
item.setUnselected();
#ifndef SIMULATOR
LOG_INF("UpdateItem, itemIndex %d Unselected", itemIndex);
#endif
}
}
void Installation_LANGView::scrollList_ItemSelectedHandler(int16_t itemSelected)
{
#ifndef SIMULATOR
LOG_INF("itemSelectedHandler, itemSelected %d", itemSelected);
#endif
currentIndex = itemSelected;
scrollList.animateToItem(itemSelected);
for (int i = 0; i < scrollList.getNumberOfItems(); i++) {
scrollList.itemChanged(i);
}
scrollList.invalidate();
}
And pressing down button 5 times gives the following log (but only item 0 and 5 shows selected),
it looks the same for every button press: