cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement "SwitchScreen()" in touchgfx?

kvkhekale
Associate II

Hello all,

I am trying to switch the screen throuch code in touchgfx.

If I use SwitchScreen, how shall I state the argument (screen* newScreen)?

If, for example I want to switch to Screen7.

Shall I call the function with SwitchScreen(scr7)?

where scr7 is declared as follows:

ScreenView7 scr7;

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @HP​,

Yes, this is the way you transition to other screens. Using the designer, they're generated for you when you have a "change screen" interaction defined. Here's an example - From screen 2 i defined an interaction to go to screen1 with NO special transition animation. The possibilibies are:

  • No transition
  • Slide Transition
  • Cover Transition

This interaction will cause the following methods to be generated:

/*
 * Screen Transition Declarations
 */
// Screen1
 
void FrontendApplicationBase::gotoScreen1ScreenNoTransition()
{
    transitionCallback = touchgfx::Callback<FrontendApplicationBase>(this, &FrontendApplication::gotoScreen1ScreenNoTransitionImpl);
    pendingScreenTransitionCallback = &transitionCallback;
}
 
void FrontendApplicationBase::gotoScreen1ScreenNoTransitionImpl()
{
    makeTransition<Screen1View, Screen1Presenter, touchgfx::NoTransition, Model >(&currentScreen, &currentPresenter, frontendHeap, &currentTransition, &model);
}
 

If you'd chosen another transition then the methods and arguments would be different. If you want to transition to a screen programatically, e.g. if you get a certain message from the backend, you will call it like in the code in the previous post:

static_cast<FrontendApplication*>(Application::getInstance())->gotoScreen1ScreenNoTransition();

The methods generated by the designer are in gui_generated/src/common/FrontEndApplicationBase.cpp

You can add your own, manually, in gui/src/common/FrontEndApplication.cpp

/Martin

View solution in original post

33 REPLIES 33
Martin KJELDSEN
Chief III

Hi,

Just use the generated goto methods:

e.g. you may define a method void gotoScreen() that takes some enum, switch on the argument value to transition to a screen (Depending on the screen transition you will have goto methods with or without transitions):

void BasePresenter::gotoScreen(ScreenType _type)
{
...
  case SETTINGS:
    static_cast<FrontendApplication*>(Application::getInstance())->gotoSettingsScreen();
    break;
...
}

Does that make sense?

Yes, definitely. Thank you very much for the prompt response.

But, the parameters on which I have to decide whether to switch to a new screen or not depend wholly on code.

So, in the designer, I cant decide when to switch the screen.

Thats the reason, I wont be able to use the generated code, from thre designer.

Can you please tell me another alternativethan using the generated goto method?

There is a "problem" right now where you will not have your goto methods generated if you don't have an interaction to do so specified. You can get some inspiration from how to the designer generates gotomethods and define them yourself in your concrete user code version of FrontEndApplication ( Check out FrontEndApplicationBase in a project with a screen transition).

Once you have those, you can use the method i mentioned above.

/Martin

HP
Senior III

Sorry for bringing this thread back to life..

Is this still the preferred way to change screens or is there another way?

I must admit that I'm not all that familiar with those goto methods - where are they located?

I too need a way to programatically change the screen withouth button presses.

Hi @HP​,

Yes, this is the way you transition to other screens. Using the designer, they're generated for you when you have a "change screen" interaction defined. Here's an example - From screen 2 i defined an interaction to go to screen1 with NO special transition animation. The possibilibies are:

  • No transition
  • Slide Transition
  • Cover Transition

This interaction will cause the following methods to be generated:

/*
 * Screen Transition Declarations
 */
// Screen1
 
void FrontendApplicationBase::gotoScreen1ScreenNoTransition()
{
    transitionCallback = touchgfx::Callback<FrontendApplicationBase>(this, &FrontendApplication::gotoScreen1ScreenNoTransitionImpl);
    pendingScreenTransitionCallback = &transitionCallback;
}
 
void FrontendApplicationBase::gotoScreen1ScreenNoTransitionImpl()
{
    makeTransition<Screen1View, Screen1Presenter, touchgfx::NoTransition, Model >(&currentScreen, &currentPresenter, frontendHeap, &currentTransition, &model);
}
 

If you'd chosen another transition then the methods and arguments would be different. If you want to transition to a screen programatically, e.g. if you get a certain message from the backend, you will call it like in the code in the previous post:

static_cast<FrontendApplication*>(Application::getInstance())->gotoScreen1ScreenNoTransition();

The methods generated by the designer are in gui_generated/src/common/FrontEndApplicationBase.cpp

You can add your own, manually, in gui/src/common/FrontEndApplication.cpp

/Martin

Great, thanks for the pointers!

No problem!

/Martin

MPhil.1
Associate II

Can someone please help with providing a better example of creating custom methods that were not created by designer?

I need to enter a screen when a user presses a hardware button.

ABeck.1
Associate II

0690X00000DA17AQAT.pngFor me while screen transition, drag I can see, completely first screen is not going, when second screen comes . What to do to resolve this