2025-04-16 3:11 AM - edited 2025-04-16 4:47 AM
I have a scroll wheel languageSelectorWheel with several items. Every item is a container languageSelectorItem
On the container I have a toggle button. When I click any toggle button, I want to send a trigger on the view of the scroll wheel to execute a function.
On the toggle button I have added an interaction onClick via TouchGFX that emits the trigger languageChanged. The trigger is set on the languageSelectorItem container
On the view where the languageSelectorWheel is added, I have set the callback
Solved! Go to Solution.
2025-04-16 11:37 PM - edited 2025-04-17 3:56 AM
Ok so I figure it out. I set a trigger on the container that returns its index
On the interactions I have added a button click that both call a function and executes the trigger
Here you must register the trigger
void setLanguageSelectedCallback(touchgfx::GenericCallback<const int16_t>& callback)
{
languageSelectedCallback = &callback;
}
protected:
int16_t itemNumber;
touchgfx::GenericCallback<const int16_t>* languageSelectedCallback;
here you execute the callback
void languageItem::buttonClicked()
{
// Call the callback when the button is clicked, passing the item number
if (languageSelectedCallback && languageSelectedCallback->isValid())
{
languageSelectedCallback->execute(itemNumber);
}
}
Here you register the callback from the container
protected:
/*
* Callback Declarations
*/
touchgfx::Callback<languageSettingsView, const int16_t> languageItemLanguageSelectedCallback;
/*
* Callback Handler Declarations
*/
void languageItemLanguageSelectedCallbackHandler(const int16_t itemIndex);
Finally in the view you can initialize all the callback, one for each element of the wheel
languageSettingsView::languageSettingsView():
languageItemLanguageSelectedCallback(this, &languageSettingsView::languageItemLanguageSelectedCallbackHandler)
{
for (int i = 0; i < languageSelectorScrollListItems.getNumberOfDrawables(); i++)
{ languageSelectorScrollListItems[i].setLanguageSelectedCallback(languageItemLanguageSelectedCallback);
}
}
And then you can use the callback on the View to react according to the index
void languageSettingsView::languageItemLanguageSelectedCallbackHandler(const int16_t itemIndex)
{
}
Clearly on the View you need a function that set the itemNumber, something like
void languageSettingsView::languageSelectorScrollUpdateItem(languageItem& item, int16_t itemIndex)
{
item.setItemNumber(itemIndex);
}
Where the setItemNumber function must be added to the container
2025-04-16 11:37 PM - edited 2025-04-17 3:56 AM
Ok so I figure it out. I set a trigger on the container that returns its index
On the interactions I have added a button click that both call a function and executes the trigger
Here you must register the trigger
void setLanguageSelectedCallback(touchgfx::GenericCallback<const int16_t>& callback)
{
languageSelectedCallback = &callback;
}
protected:
int16_t itemNumber;
touchgfx::GenericCallback<const int16_t>* languageSelectedCallback;
here you execute the callback
void languageItem::buttonClicked()
{
// Call the callback when the button is clicked, passing the item number
if (languageSelectedCallback && languageSelectedCallback->isValid())
{
languageSelectedCallback->execute(itemNumber);
}
}
Here you register the callback from the container
protected:
/*
* Callback Declarations
*/
touchgfx::Callback<languageSettingsView, const int16_t> languageItemLanguageSelectedCallback;
/*
* Callback Handler Declarations
*/
void languageItemLanguageSelectedCallbackHandler(const int16_t itemIndex);
Finally in the view you can initialize all the callback, one for each element of the wheel
languageSettingsView::languageSettingsView():
languageItemLanguageSelectedCallback(this, &languageSettingsView::languageItemLanguageSelectedCallbackHandler)
{
for (int i = 0; i < languageSelectorScrollListItems.getNumberOfDrawables(); i++)
{ languageSelectorScrollListItems[i].setLanguageSelectedCallback(languageItemLanguageSelectedCallback);
}
}
And then you can use the callback on the View to react according to the index
void languageSettingsView::languageItemLanguageSelectedCallbackHandler(const int16_t itemIndex)
{
}
Clearly on the View you need a function that set the itemNumber, something like
void languageSettingsView::languageSelectorScrollUpdateItem(languageItem& item, int16_t itemIndex)
{
item.setItemNumber(itemIndex);
}
Where the setItemNumber function must be added to the container