cancel
Showing results for 
Search instead for 
Did you mean: 

ClickListener and Mixins

kvkhekale
Associate II

Hello All

I am trying to add a ClickListener to ScrollWheel in my project.

I am referring following link as a tutorial for the same

 https://touchgfx.zendesk.com/hc/en-us/articles/360002825452-Mixins-and-ClickListener

But, even afer following the tutorial as it is, I am getting following compilation error:

error: no match for call to '(touchgfx::Callback<Screen1View, const touchgfx::ScrollWheel&, const touchgfx::ClickEvent&>) (Screen1View*, void (Screen1View::*)(const touchgfx::ScrollWheel&, const touchgfx::ClickEvent&))'

   MyCallback(this, &Screen1View::MyCallbackHandler){}

I am inserting code snippet with this file:

Screen1View.cpp

#include <gui/screen1_screen/Screen1View.hpp>
#include "string.h"
#include "main.h"
extern UART_HandleTypeDef huart5;
Screen1View::Screen1View()
{
    MyCallback(this, &Screen1View::MyCallbackHandler){}
}
 
void Screen1View::setupScreen()
{
	scrollWheel1.setClickAction(MyCallback);
}
 
void Screen1View::tearDownScreen()
{
 
}

Screen1View.hpp

#ifndef SCREEN1_VIEW_HPP
#define SCREEN1_VIEW_HPP
 
#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>
#include <gui/screen1_screen/Screen1Presenter.hpp>
 
class Screen1View : public Screen1ViewBase
{
public:
    Screen1View();
    virtual ~Screen1View() {}
    virtual void setupScreen();
    virtual void tearDownScreen();
    void scrollWheel1UpdateItem(CustomContainer1& item, int16_t itemIndex);
    void scrollWheel2UpdateItem(CustomContainer2& item, int16_t itemIndex);
 //   virtual void handleClickEvent(const ClickEvent& evt);
 //   virtual void handleDragEvent(const DragEvent& drgevt);
 
    void MyCallbackHandler(const ScrollWheel &scroll, const ClickEvent &e);
 
 
protected:
    // Declaring callback type of box and clickEvent
    touchgfx::Callback<Screen1View, const ScrollWheel&, const ClickEvent&> MyCallback;
 
 
};
 
template<class T>
class ClickListener : public T
{
 
public:
	ClickListener() : T(), clickAction(0)
	{
		T::setTouchable(true);
	};
 
	virtual void handleClickEvent(const ClickEvent& event)
	{
	    T::handleClickEvent(event);
	    if (clickAction && clickAction->isValid())
	    {
	        clickAction->execute(*this, event);
	    }
	}
 
	void setClickAction(GenericCallback< const T&, const ClickEvent& > callback)
	{
	   clickAction = &callback;
	}
protected:
    touchgfx::GenericCallback<> *clickAction;  ///< The callback to be executed when T is clicked
 
};
 
 
 
#endif // SCREEN1_VIEW_HPP

Please tell me if I am doing any mistake in following the tutorial

2 REPLIES 2
Martin KJELDSEN
Chief III

Hi @kvkhekale​,

Are you still having troubles with this? Can you send me the project? I wouldn't rule out an error in the guide.

/Martin

AGama.1
Associate II

This part:

Screen1View::Screen1View()

{

MyCallback(this, &Screen1View::MyCallbackHandler){}

}

should be written as:

Screen1View::Screen1View():

MyCallback(this, &Screen1View::MyCallbackHandler)

{

}

And that is it.