2025-01-20 08:55 AM
I want to create a scrollWheel that has 3 preset options. Option A, Option B, and Option A&B
The issue I have is that I can never get itemIndex = 1 in scrollWheelUpdateItem callback , only index 0 and 2. Also, after I first change wheel, it takes a while to be able to change it again.
I tried to provide all the relevant code and touchgfx setup.
Appreciate if you can tell me what is incorrect.
Here is my Container (MenuItem):
Here is how I set up my text:
scrollWheel:
Here is Container MenuItem.cpp:
#include <gui/containers/MenuItem.hpp>
#include <texts/TextKeysAndLanguages.hpp>
#include <BitmapDatabase.hpp>
MenuItem::MenuItem()
{
}
void MenuItem::initialize()
{
MenuItemBase::initialize();
}
void MenuItem::setWheelElements(int item)
{
switch (item)
{
case 0:
text.invalidate();
text.setTypedText(TypedText(T_S1));
break;
case 1:
text.invalidate();
text.setTypedText(TypedText(T_S2));
break;
case 2:
text.invalidate();
text.setTypedText(TypedText(T_S3));
break;
}
}
MenuItem.hpp:
#ifndef MENUITEM_HPP
#define MENUITEM_HPP
#include <gui_generated/containers/MenuItemBase.hpp>
class MenuItem : public MenuItemBase
{
public:
MenuItem();
virtual ~MenuItem() {}
virtual void initialize();
void setWheelElements(int item);
protected:
};
#endif // MENUITEM_HPP
Buttons1MenuView.cpp
#include <gui/buttons1menu_screen/Buttons1MenuView.hpp>
#include <gui_generated/common/FrontendApplicationBase.hpp>
#include "config_file.h"
#include "math.h"
Buttons1MenuView::Buttons1MenuView()
{
}
void Buttons1MenuView::setupScreen()
{
Buttons1MenuViewBase::setupScreen();
}
void Buttons1MenuView::tearDownScreen()
{
Buttons1MenuViewBase::tearDownScreen();
}
void Buttons1MenuView::scrollWheelUpdateItem(MenuItem& item, int16_t itemIndex)
{
scrollWheel.invalidate(); //NOT SURE IF NEEDED
item.setWheelElements(itemIndex);
}
Buttons1MenuView.hpp
#ifndef BUTTONS1MENUVIEW_HPP
#define BUTTONS1MENUVIEW_HPP
#include <gui_generated/buttons1menu_screen/Buttons1MenuViewBase.hpp>
#include <gui/buttons1menu_screen/Buttons1MenuPresenter.hpp>
class Buttons1MenuView : public Buttons1MenuViewBase
{
public:
Buttons1MenuView();
virtual ~Buttons1MenuView() {}
virtual void setupScreen();
virtual void tearDownScreen();
virtual void scrollWheelUpdateItem(MenuItem& item, int16_t itemIndex);
protected:
};
#endif // BUTTONS1MENUVIEW_HPP
2025-01-20 09:45 AM
I increased the size of the scrollWheel window (still making it only show one item) it responds much better and I do now get valid itemIndex, accept the index number does agree to what I thought it should be.
In other words, I assume Option A should have index 0, Option B index 1 and Option AB index 2,
but I get Option A index 1, Option B index 2 and Option AB index 0
Anyone know why the indexes as not as expected?