Button long press and custom widget over code generation question
Hi,
For my application I need a transparent (invisible) button with long press action.
I found this topic https://touchgfx.zendesk.com/hc/en-us/community/posts/206420309-Button-Longpress
It was helpful in fact, but I still have some issues.
I implemented this new widget in code.
Then for testing purpose I created a small project with 2 screens, and 1 button on each screen to swap between screens ( I did this from TouchGFX)
Then back to cube IDE, I modified Screen1ViewBase like this:
class Screen1ViewBase : public touchgfx::View<Screen1Presenter>
{
public:
Screen1ViewBase();
virtual ~Screen1ViewBase() {}
virtual void setupScreen();
protected:
FrontendApplication& application() {
return *static_cast<FrontendApplication*>(Application::getInstance());
}
/*
* Member Declarations
*/
touchgfx::Box box1;
// touchgfx::Button button1;
touchgfx:: HoldableButton button1; //-> redefinition of button1 to a HoldableButton
private:
/*
* Callback Handler Declarations
*/
void buttonCallbackHandler(const touchgfx::AbstractButton& src);
/*
* Callback Declarations
*/
touchgfx::Callback<Screen1ViewBase, const touchgfx::AbstractButton&> buttonCallback;
};Note that I only changed the definition of button1 from Button to HoldableButton.
The good news is that the long press does work !
But my problems are:
1/ Is there a way to call this new custom widget from TouchGFX and not only from code ?
because if I have to go back to TouchGFX, all my code is erased as Screen1ViewBase .hpp and .cpp are generated files. Is there a way to prevent that, ? or maybe I should call the widget elsewhere ?
2/ How to make this button invisible from code ?
3/ last but not least: the long press works, but the action is also triggered when the button is released and I do not want that, if the button is released before the long press occurs, it should do nothing.
The implementation proposed in the linked topic overwrites the 'handleClickEvent' method. But when the button is released before the long press ' AbstractButton::handleClickEvent ' get called (seen with a breakpoint).
Why does this happen ? Can i prevent that ?
Thanks a lot :).
Thomas.
