2021-06-14 10:29 AM
I am looking to implement back button to go back to previous screen (similar to UI on a smart phone). For this,
1. Need to remember current screen before a button is pressed.
2. In the new screen, when a back button is pressed, programmatically change to previous screen.
It would need a common memory area where current screen can be saved. This information should be accessible from any screen so that it can be read when a back button on that particular screen is pressed.
Here is a scenario:
Is this possible with TouchGFX?
Solved! Go to Solution.
2021-06-17 11:19 AM
I solved it using Model-View-Presenter method. Saved a variable in model that holds which previous screen. When back button is pressed, this model variable is used to jump to correct screen.
2021-06-14 01:34 PM
Yes, of course it is possible.
But you don't need to remember all these information yourself, because it is already built-in TouchGFX. Just define e.g. a back button on a screen and add an interaction (top right):
Good luck!
If the problem is resolved, please mark this topic as answered by selecting Select as best. This will help other users find that answer faster.
/Peter
2021-06-14 01:46 PM
Hi @Peter BENSCH
Sorry, perhaps I was not detailed with my question.
Please let me know.
2021-06-17 11:19 AM
I solved it using Model-View-Presenter method. Saved a variable in model that holds which previous screen. When back button is pressed, this model variable is used to jump to correct screen.
2023-06-06 11:40 AM
Hello,
could you please give us more details how did you realize this function?
thanks a lot.
2023-06-06 12:20 PM
Hi @JPan.4 ,
This is how I implemented it.
2023-06-08 04:14 AM - edited 2023-11-20 09:20 AM
Hi
In TouchGFX , I assign the interactions as below
NEXT_SCREEN
Choose button key = 2
PREVIOUS_SCREEN
Choose button key = 1
keys.cpp
unsigned char Key_UP=1;
unsigned char Key_DN=1;
/*****************************************************************
* Function
******************************************************************/
void Keys_Scan(void)
{
/********************** KEY UP ***********************************/
if (HAL_GPIO_ReadPin(PORT_Key_UP, PIN_Key_UP))
{ Key_UP=1; } else { Key_UP=0; }
/********************** KEY DN ***********************************/
if (HAL_GPIO_ReadPin(PORT_Key_DN, PIN_Key_DN))
{ Key_DN=1; } else { Key_DN=0; }
}
KeySampler.cpp
using namespace touchgfx;
static uint8_t btnstatus[4];
extern unsigned char Key_UP;
extern unsigned char Key_DN;
void KeySampler::init()
{
}
bool KeySampler::sample(uint8_t& key)
{
Keys_Scan();
if (Key_UP == 0)
{
key = 1;
HAL_Delay(100);
return true;
}
if (Key_DN == 0)
{
key = 2;
HAL_Delay(100);
return true;
}
return false;
}
Screen2ViewBase.cpp
void Screen2ViewBase::handleKeyEvent(uint8_t key)
{
if(2 == key)
{
//NEXT_SCREEN
//When hardware button 2 clicked change screen to Screen3
//Go to Screen3 with no screen transition
application().gotoScreen3ScreenNoTransition();
}
if(1 == key)
{
//PREVIOUS_SCREEN
//When hardware button 1 clicked change screen to Screen1
//Go to Screen1 with no screen transition
application().gotoScreen1ScreenNoTransition();
}
}
I hope , this will work fine
IN
2024-03-21 07:52 AM
the built-in way only works, if there is only one way to arrive at a specific screen.
If there are two ways to arrive at a screen you need to remember the id/index/... of the previous screen, so that you know to which screen you should go to.