2024-03-19 09:35 AM
I want the user to hold a button for at least 3 seconds before it triggers its interaction. So I created a Repeat Button, because the documentation says on delay: "Delay specifies the time (ms) to wait when the button is pressed before starting the loop of triggers."
But when I configure a delay of e.g. 2000 ms and an interval time of 8000 ms, it triggers immediately and then after 2 seconds (and then every 8 seconds). Is this misleading in the documentation or a wrong behavior of the button?
Solved! Go to Solution.
2024-03-20 03:29 AM - edited 2024-03-20 03:55 AM
Hello @ulix ,
First, welcome to the TouchGFX community :)
The repeat button is working as it's supposed to be, it repeats the trigger every X ms. The delay is the delay between each triggers, e.g with a 2000ms the button will be triggered every 2000ms.
The behaviour you want can be done by using HandleClick on your button with HandleTick. by setting up a timer, that increments with HandleTick and allows you to click.
I hope it answers your question,
Regards,
2024-03-20 03:29 AM - edited 2024-03-20 03:55 AM
Hello @ulix ,
First, welcome to the TouchGFX community :)
The repeat button is working as it's supposed to be, it repeats the trigger every X ms. The delay is the delay between each triggers, e.g with a 2000ms the button will be triggered every 2000ms.
The behaviour you want can be done by using HandleClick on your button with HandleTick. by setting up a timer, that increments with HandleTick and allows you to click.
I hope it answers your question,
Regards,
2024-03-21 09:57 AM
Hello
You can also achieve your goal by modifing repeatButton.cpp
Browse to \Middlewares\ST\touchgfx\framework\source\touchgfx\widgets\- folder of your project and copy RepeatButton.cpp- file to \TouchGFX\gui\src\common\ folder. Edit that copy in \common\ folder.
Locate handleClickEvent and comment out executeAction- function call.
void RepeatButton::handleClickEvent(const ClickEvent& event)
{
pressed = false; // To prevent AbstractButton from calling action->execute().
invalidate(); // Force redraw after forced state change
Button::handleClickEvent(event);
if (event.getType() == ClickEvent::PRESSED)
{
//Comment out call to 'executeAction' to get initial delay before first click
//executeAction();
ticks = 0;
ticksBeforeContinuous = ticksDelay;
Application::getInstance()->registerTimerWidget(this);
}
else
{
Application::getInstance()->unregisterTimerWidget(this);
}
}
Then if needed to get only one delayed click, just add 'unregisterTimerWidget' after first click is generated after initial delay.
void RepeatButton::handleTickEvent()
{
Button::handleTickEvent();
if (!pressed)
{
return;
}
if (ticks == ticksBeforeContinuous)
{
executeAction();
ticks = 0;
ticksBeforeContinuous = ticksInterval;
// Add unregisterTimerWidget after first generated click
Application::getInstance()->unregisterTimerWidget(this);
}
else
{
ticks++;
}
}
Perhaps this kind of features would be nice to have directly from the Tgfx Designer in the future releases.
Br JTP
2024-03-21 10:26 AM
2024-03-22 01:45 AM
Hello all,
Thanks for your feedbacks, I will talk about this feature to the Team and see if there's an interest for it in a next release.
Regards,
2024-03-22 02:00 AM
thanks.
I see very common applications for both; eg,
That's just 2 straight off the top of my head.