Hello
I found my old example, just modify it for flexbutton, maybe this helps. The flexButton click handler is bit more tricky than other button types. Here in the example flexbutton has just Box with border- element.
------
One way is to create ClickListener to the FlexButton, so set it on at Mixins of your flexButton:
Then add the callback definitions to the screen1.hpp (or whatever you have)
class Screen1View : public Screen1ViewBase
{
public:
Screen1View();
virtual ~Screen1View() {}
virtual void setupScreen();
virtual void tearDownScreen();
// Add this public function definition:
void flexButtonClickHandler(const touchgfx::BoxWithBorderButtonStyle< touchgfx::TouchButtonTrigger > & ,const ClickEvent& e);
// int16_t pressCount=0;
// int16_t releaseCount=0;
protected:
// And add this protected function definition:
Callback<Screen1View, const touchgfx::BoxWithBorderButtonStyle< touchgfx::TouchButtonTrigger > &,const ClickEvent&> flexButtonClickedCallback;
};
and then in screen1.cpp:
#include <gui/screen1_screen/Screen1View.hpp>
#include <touchgfx/Utils.hpp>
// Add this callback to the constructor:
Screen1View::Screen1View():
flexButtonClickedCallback(this,&Screen1View::flexButtonClickHandler)
{
}
void Screen1View::setupScreen()
{
Screen1ViewBase::setupScreen();
// This sets the click action for flexButton1 !!
flexButton1.setClickAction(flexButtonClickedCallback);
}
void Screen1View::tearDownScreen()
{
Screen1ViewBase::tearDownScreen();
}
// Add this function
void Screen1View::flexButtonClickHandler(const touchgfx::BoxWithBorderButtonStyle< touchgfx::TouchButtonTrigger >& b,const ClickEvent& e)
{
if(&b==&flexButton1) // button1 -> your button name
{
switch(e.getType())
{
case ClickEvent::PRESSED:
touchgfx_printf("Pressed flexButton1 \r\n");
//pressCount++;
break;
//case ClickEvent::RELEASED:
//case ClickEvent::CANCEL:
default:
touchgfx_printf("Released or Cancel flexButton1 \r\n");
//releaseCount++;
// this handles REALEASED and CANCEL- events !
break;
}
//This is just debug print to display, since its tested also in device :
//Unicode::snprintf(CounterBuffer, COUNTER_SIZE, "press:%3u release:%3u",pressCount,releaseCount);
//Counter.invalidate();
}
}
Please note that this works only with flexButton that has only Box with border. If you have some other elements, check in screen1base.hpp the inheritance structure of your flexButton
/* Screen1ViewBase.hpp
* Member Declarations
*/
// HERE !!:
touchgfx::ClickListener< touchgfx::BoxWithBorderButtonStyle< touchgfx::TouchButtonTrigger > > flexButton1;
Only BoxWithBorder:
touchgfx::ClickListener< touchgfx::BoxWithBorderButtonStyle< touchgfx::TouchButtonTrigger > > flexButton1;
All 4 elements:
touchgfx::ClickListener< touchgfx::IconButtonStyle< touchgfx::TextButtonStyle< touchgfx::ImageButtonStyle< touchgfx::BoxWithBorderButtonStyle< touchgfx::TouchButtonTrigger > > > > > flexButton1;
This case you must replace the callback and clickHandler function parameters to match your flexbutton elements at in Screen1.cpp and .hpp !
Example is tested with Simulator and F769IDisco evalkit. BTW what hardware you are using ?