What is the difference between the Callback and GenericCallback classes?
I'm trying to write a class that contain a clickable Box. The action of the click event is handled in the Screen1View.
I'm total loss with GenericCallback and Callback.
Here the code:
MyObj.hpp:
class MyObj : public TextureMapper
{
public:
MyObj();
~MyObj();
virtual void handleClickEvent(const ClickEvent& event);
void setAction(GenericCallback<const MyObj&>& callback)
{
action = &callback;
}
protected:
ClickListener< Box > clickable_box;
// Declaring callback type of box and clickEvent
GenericCallback< const MyObj& >* action;
};MyObj.cpp:
#include <gui\common\MyObj.hpp>
MyObj::MyObj() :
TextureMapper(),
action()
{
setTouchable(true);
//clickable_box.setClickAction(action);
}
MyObj::~MyObj()
{
}
void MyObj::handleClickEvent(const ClickEvent& event)
{
clickable_box.handleClickEvent(event);
}And in ScreenView:
ScreenView.hpp:
#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>
#include <gui/screen1_screen/Screen1Presenter.hpp>
#include <gui/common/MyObj.hpp>
#include <touchgfx/widgets/TextureMapper.hpp>
#include <touchgfx/Callback.hpp>
class Screen1View : public Screen1ViewBase
{
public:
Screen1View();
virtual ~Screen1View() {}
virtual void setupScreen();
virtual void tearDownScreen();
virtual void handleClickEvent(const ClickEvent& evt);
void handle_MyObj_click(const MyObj& b, const ClickEvent& e);
protected:
MyObj _myObj;
Callback< Screen1View, const MyObj&, const ClickEvent& > _myObj_clickable;
//GenericCallback< Screen1View, const MyObj&, const ClickEvent& > _myObj_clickable;
};ScreenView.cpp:
#include <gui/screen1_screen/Screen1View.hpp>
Screen1View::Screen1View():
_myObj_clickable(this, &Screen1View::handle_MyObj_click),
_myObj()
{
_myObj.setAction(_myObj_clickable); // error: C++ impossible to initialize a type reference (not qualified by const) with a type value
add(_myObj);
}
void Screen1View::setupScreen()
{
Screen1ViewBase::setupScreen();
}
void Screen1View::tearDownScreen()
{
Screen1ViewBase::tearDownScreen();
}
void Screen1View::handleClickEvent(const ClickEvent& evt)
{
View::handleClickEvent(evt);
}
void Screen1View::handle_MyObj_click(const MyObj& b, const ClickEvent& e)
{
// do something
}