ClickListener Callback Not Working
I have a custom container that has a box inside of it with the ClickListener enabled. I am trying to setup a callback for when the box is clicked. I have the following code setup:
#include <gui_generated/containers/NavbarBase.hpp>
class Navbar : public NavbarBase
{
public:
Navbar();
virtual ~Navbar() {}
virtual void initialize();
protected:
virtual void setupMenuItem(TextArea *label, Image *icon);
virtual void tMenuItemCallbackHandler(const touchgfx::Box &box, const touchgfx::ClickEvent &e);
touchgfx::Callback<Navbar, const touchgfx::Box&, const touchgfx::ClickEvent&> tMenuItemCallback;
};#include <gui/containers/Navbar.hpp>
Navbar::Navbar() : tMenuItemCallback(this, &Navbar::tMenuItemCallbackHandler) {
}
/**
* Adjusts the menu label's X position to be centered with the icon and
* adjusts the Y position to be centered with the space below the icon.
* Disabled touch interaction on both elements.
*/
void Navbar::setupMenuItem(TextArea *label, Image *icon) {
uint16_t labelAdjustedX = icon->getX() + (icon->getWidth() / 2) - (label->getTextWidth() / 2);
label->setX(labelAdjustedX);
uint16_t iconBaseY = icon->getY() + icon->getHeight();
uint16_t labelYPadding = (this->getHeight() - iconBaseY - label->getTextHeight()) / 2;
label->setY(iconBaseY + labelYPadding);
label->setTouchable(false);
icon->setTouchable(false);
}
void Navbar::tMenuItemCallbackHandler(const touchgfx::Box &box, const touchgfx::ClickEvent &e) {
this->DMenuIcon.setVisible(false);
}
void DMEModeNavbar::initialize()
{
NavbarBase::initialize();
// Adjust the positions of the text
this->setupMenuItem(&this->TMenuLabel, &this->TMenuIcon);
this->setupMenuItem(&this->DMenuLabel, &this->DMenuIcon);
this->setupMenuItem(&this->VMenuLabel, &this->VMenuIcon);
this->TMenuSelector.setTouchable(true);
this->TMenuSelector.setClickAction(this->tMenuItemCallback);
}
When TMenuSelector is clicked, DMenuIcon should disappear, however, nothing happens. I have looked through a variety of similar posts and code and I do not see what is going wrong here. Any direction would be appreciated.
