cancel
Showing results for 
Search instead for 
Did you mean: 

List Layout Callback not firing

BKazi.1
Associate II

I am trying to create a language selection menu. I have managed to inflate the list. However, the callback for element selection is not firing. Please advise. Following is my code.

#ifndef CONTAINER_MENU_HPP
#define CONTAINER_MENU_HPP
 
#include <gui_generated/containers/Container_MenuBase.hpp>
#include <texts/TextKeysAndLanguages.hpp>
 
class Container_Menu : public Container_MenuBase
{
public:
    Container_Menu();
    virtual ~Container_Menu() {}
 
    virtual void setupListElement(TEXTS iconTextID, int index);
    virtual void setAction(GenericCallback< Container_Menu& >& callback);
    virtual void setSelection(int selected);
    virtual int getIndex();
    virtual void selectAction();
 
    virtual void initialize();
protected:
    int index = 0;
    GenericCallback< Container_Menu& >* viewCallback;
};
 
#endif // CONTAINER_MENU_HPP
#include <gui/containers/Container_Menu.hpp>
#include <touchgfx/Color.hpp>
 
Container_Menu::Container_Menu() : viewCallback(0)
{
}
 
void Container_Menu::initialize()
{
    Container_MenuBase::initialize();
}
 
void Container_Menu::setupListElement(TEXTS iconTextID, int _index)
{
	index = _index;
    text_menu.setTypedText(TypedText(iconTextID));
    text_menu.resizeToCurrentText();
    invalidate();
}
 
void Container_Menu::setSelection(int selected)
{
	bg_selected.setVisible(index == selected);
	text_menu.setColor(index == selected? Color::getColorFrom24BitRGB(255, 255, 255) : Color::getColorFrom24BitRGB(0, 0, 0));
	invalidate();
}
 
int Container_Menu::getIndex(){ return index; }
 
void Container_Menu::setAction(GenericCallback< Container_Menu& >& callback)
{
    viewCallback = &callback;
}
 
void Container_Menu::selectAction()
{
    // Inform the view of the event
    if (viewCallback->isValid())
    {
        viewCallback->execute(*this);
    }
}
#ifndef SCREEN_LANGUAGEVIEW_HPP
#define SCREEN_LANGUAGEVIEW_HPP
 
#include <gui_generated/screen_language_screen/Screen_LanguageViewBase.hpp>
#include <gui/screen_language_screen/Screen_LanguagePresenter.hpp>
#include <gui/containers/Container_Menu.hpp>
 
class Screen_LanguageView : public Screen_LanguageViewBase
{
public:
    Screen_LanguageView();
    virtual ~Screen_LanguageView() {}
    virtual void setupScreen();
    virtual void tearDownScreen();
    virtual void updateList();
    virtual void listElementClicked(Container_Menu& element);
protected:
    static const int item_count = 5;
    int selected = 0;
 
    Container_Menu listElements[item_count];
 
    Callback<Screen_LanguageView, Container_Menu&> listElementClickedCallback;
};
 
#endif // SCREEN_LANGUAGEVIEW_HPP
#include <gui/screen_language_screen/Screen_LanguageView.hpp>
 
Screen_LanguageView::Screen_LanguageView() : listElementClickedCallback(this, &Screen_LanguageView::listElementClicked)
{
 
}
 
void Screen_LanguageView::setupScreen()
{
    Screen_LanguageViewBase::setupScreen();
 
    list_language.setDirection(touchgfx::SOUTH);
 
    listElements[0].setupListElement(T_LIST_LANGUAGE_0, 0);
    listElements[1].setupListElement(T_LIST_LANGUAGE_1, 1);
    listElements[2].setupListElement(T_LIST_LANGUAGE_2, 2);
    listElements[3].setupListElement(T_LIST_LANGUAGE_3, 3);
    listElements[4].setupListElement(T_LIST_LANGUAGE_4, 4);
 
    for (uint8_t i = 0; i < item_count; ++i)
	{
    	listElements[i].setSelection(selected);
		listElements[i].setAction(listElementClickedCallback);
		list_language.add(listElements[i]);
	}
}
 
void Screen_LanguageView::tearDownScreen()
{
    Screen_LanguageViewBase::tearDownScreen();
}
 
void Screen_LanguageView::listElementClicked(Container_Menu& element)
{
	selected = element.getIndex();
	touchgfx_printf("Item Selected = %d\n" ,selected);
	updateList();
}
 
void Screen_LanguageView::updateList()
{
	list_language.removeAll();
	for (uint8_t i = 0; i < item_count; ++i)
	{
		listElements[i].setSelection(selected);
		listElements[i].setAction(listElementClickedCallback);
		list_language.add(listElements[i]);
	}
	list_language.invalidate();
}

1 ACCEPTED SOLUTION

Accepted Solutions
Romain DIELEMAN
ST Employee

What do you actually expect from this callback ? When should it be activated ? From the code I don't see anything wrong but it is a bit difficult to actually go through it clearly. I suppose your code is based on the UI template "ListLayout Example" where the callback is based on a button being clicked which calls the deleteAction() function (look at CustomListElementBase.cpp).

/Romain

View solution in original post

5 REPLIES 5
BKazi.1
Associate II

Hi ST Team, any solution to this issue? Please point out where I am making a mistake. A thing to mention that I was not having any issue with a similar code while using TouchGFX version 4.14.0. Thanks

BKazi.1
Associate II

Hi ST Team, still no solution has been given. My project is stuck due to this minor issue... Please help

Romain DIELEMAN
ST Employee

What do you actually expect from this callback ? When should it be activated ? From the code I don't see anything wrong but it is a bit difficult to actually go through it clearly. I suppose your code is based on the UI template "ListLayout Example" where the callback is based on a button being clicked which calls the deleteAction() function (look at CustomListElementBase.cpp).

/Romain

BKazi.1
Associate II

Well, that was a silly mistake I made by not linking the interaction to the virtual function I had created. Thanks for your assistance

No worries ^^, happy to hear it works now

/Romain