2024-12-17 7:48 AM - edited 2024-12-23 10:06 AM
hi
by this code click event enable for 2 Continer and work fine
void CNTR_A_ClickHandler(const CNTR_AntenaLevel&, const touchgfx::ClickEvent& e);
touchgfx::Callback<MainView, const CNTR_AntenaLevel&, const touchgfx::ClickEvent&> CNTR_A_ClickedCallback;
CNTR_AntenaLevel1.setClickAction(CNTR_A_ClickedCallback);
// *******************************
void CNTR_B_ClickHandler(const CNTR_TempLevel&, const touchgfx::ClickEvent& e);
touchgfx::Callback<MainView, const CNTR_TempLevel&, const touchgfx::ClickEvent&> CNTR_B_ClickedCallback;
CNTR_TempLevel1.setClickAction(CNTR_B_ClickedCallback);
but i have 14 Container in this method i have to add many code line for each container for "Click Event". is it possible use one container Clicked Callback for multi type of container?
2024-12-23 1:32 PM
Does anyone have any ideas?
I'm stuck here save me from this dilemma
2025-06-10 5:53 AM
As far as I know you have to use a separate callback function for each widget type.
Multiple instances of a widget type can share the same callback function.
Multiple callback functions could call a shared callback function with a pointer to plain widget class.
If the instances of the same type are defined consecutively and in order, then they are probably in that same order in the screen view base class. Therefore you can use a pointer to the first object and use that as an array. Then you can assign in a loop.
myScreenViewBase.hpp:
class myScreenViewBase : public touchgfx::View<myScreenViewPresenter>
{
public:
//...
protected:
touchgfx::ClickListener< touchgfx::Image > image1;
touchgfx::ClickListener< touchgfx::Image > image2;
touchgfx::ClickListener< touchgfx::TextArea > textArea1;
touchgfx::ClickListener< touchgfx::TextArea > textArea2;
}
myScreenView.hpp:
class myScreenView: public myScreenViewBase
{
public:
//...
void callback_handler(const Image& img, const ClickEvent& event);
void callback_handler(const TextArea& img, const ClickEvent& event);
void callback_handler(const Widget* w, const ClickEvent& event);
private:
//...
Callback<myScreenView, const Image&, const ClickEvent&> m_img_callback;
Callback<myScreenView, const TextArea&, const ClickEvent&> m_text_callback;
}
myScreenView.cpp:
myScreenView::myScreenView()
:
//...
m_img_callback(this, &myScreenView::callback_handler),
m_text_callback(this, &myScreenView::callback_handler)
{
image1.setClickAction(m_img_callback);
image2.setClickAction(m_img_callback);
textArea1.setClickAction(m_text_callback);
textArea2.setClickAction(m_text_callback);
}
void myScreenView::callback_handler(const Image& img, const ClickEvent& event)
{
callback_handler(reinterpret_cast<const Widget*>(&img), event);
}
void myScreenView::callback_handler(const TextArea& text, const ClickEvent& event)
{
callback_handler(reinterpret_cast<const Widget*>(&text), event);
}
void myScreenView::callback_handler(const Widget* widget, const ClickEvent& event)
{
if (widget == &image1)
{
}
//else if(widget ==
}
Pointer trick:
for (touchgfx::ClickListener< touchgfx::Image>* imgPtr = &image1; imgPtr <= &image2; ++imgPtr)
{
imgPtr->setClickAction(m_img_callback);
}
Or did you already solve it?