To achieve this, you can follow these steps:
- Create a custom container class in TouchGFX that inherits from the
Container class.
- Inside this custom container class, define an
Interaction for the button press event. In the Interaction::activated() function, you can call a virtual function that will be defined and implemented in your view file.
In your custom container header file:
#include <touchgfx/widgets/container/Container.hpp>
#include <touchgfx/event_system/Interaction.hpp>
class CustomContainer : public touchgfx::Container
{
public:
CustomContainer();
virtual void onButtonPress();
Interaction interaction;
};
In your custom container implementation file:
#include "CustomContainer.hpp"
CustomContainer::CustomContainer()
: interaction(this, &CustomContainer::onButtonPress)
{
// Initialize your container and button here
}
void CustomContainer::onButtonPress()
{
// Call the virtual function here
onButtonPress();
}
- In your view file, create a public function that will be called when the button is pressed. You can also create a callback function that will be passed to your custom container as a parameter. When the button is pressed, the callback function will be called, which will then call the public function in your view file.
In your view file:
#include "CustomContainer.hpp"
class MyView : public touchgfx::View
{
public:
void myPublicFunction();
void callbackFunction();
};
void MyView::myPublicFunction()
{
// Your public function implementation here
}
void MyView::callbackFunction()
{
// Call your public function here
myPublicFunction();
}
void MyView::setupScreen()
{
// Create your custom container instance here
CustomContainer* customContainer = new CustomContainer();
// Set the callback function for the custom container
customContainer->setCallbackFunction(this, &MyView::callbackFunction);
// Add the custom container to your view
add(customContainer);
}
- Finally, in your