2025-07-08 8:18 AM
I have placed several Image widgets in my Swipe Container, now I want the image widget to support clicks and call my function, how can I make it?
I have tried to inherit from the Image widget and implement handleClickEvent, however it doesn't implement the click event that I want.
My code:
#include <touchgfx/widgets/Image.hpp>
#include <touchgfx/Callback.hpp>
#include <touchgfx/Utils.hpp>
class ClickableImage : public Image {
public:
ClickableImage() : Image(), clickAction(0) {}
virtual void handleClickEvent(const ClickEvent& event) {
touchgfx_printf("img click\n"); // Not run
if (event.getType() == ClickEvent::PRESSED) {
if (clickAction && clickAction->isValid()) {
clickAction->execute(*this, event);
}
}
Image::handleClickEvent(event);
}
void setClickAction(GenericCallback<const ClickableImage&, const ClickEvent&>& callback) {
clickAction = &callback;
}
private:
GenericCallback<const ClickableImage&, const ClickEvent&>* clickAction;
};
2025-07-08 8:59 AM
Activate clickable on images, and create func in screen
void Screen4View::handleClickEvent(const ClickEvent& evt)
{
if(evt.getType()==ClickEvent::PRESSED && image.getAbsoluteRect().intersect(evt.getX(), evt.getY()))
...