cancel
Showing results for 
Search instead for 
Did you mean: 

How to change screen from user code space?

BParh.1
Senior III

Let say in Screen1 view I have custom widget widget1. In Widget widget1 upon certain user input, we want to switch to Screen2 view.

  • How can we do this?
  • Can we switch directly to Screen2 from widget1?
  • Or widget1 has to propagate the user input to Screen1 and then Screen1 switch to Screen2?

Basically I want to change screen from user code space instead of relying on TouchGFX designer interactions. This is due to various complex requirement when to change screen and doing so from the designer makes it looks messy and crowded - difficult to track.

3 REPLIES 3
Romain DIELEMAN
ST Employee

Hi,

This question is a bit vague 😅 What is your custom widget made of ? What are you trying to do ? Make it change screen when you click on it ? Or what is that user input you are talking about ?

What I usually do is to add in TouchGFX Designer a dummy interaction where I set as trigger "Hardware button is clicked" and as action "screen transition" to whatever screen you want to. When you go to the <screen name>ViewBase.cpp of your screen you will see that a goTo<OtherScreenName>Transition() function has been generated. What you will do is just to call that function in your custom widget when you want to change screen.

Concerning propagating the user input (once again, what type of input ?) have a look at tutorial 3 or at the Model-Presenter-View article to understand how to communicate between different screens.

/Romain

BParh.1
Senior III

Thank you @Romain DIELEMAN​ for the response and I apologies for the confusion :).

My project includes many screens and each screen contain several customized containers which contains various widget, so it was hard to ask for case by case, that is why I tried to ask in principle first.

I learn that if I use the TouchGFX designer to define all permutations of screen switching soon it would be quite complex and hard to understand and maintain. That is why I tried to implement the code by hand on user section part.

I think I found this method which seems what I am looking for. But it is currently empty implementation - I guess user need to implement. I wonder if you have a sample code for me:

class Application : public UIEventListener
{
public:
..............
 
    /**
     * An application specific function for switching screen. Overloading this can provide a
     * means to switch screen from places that does not have access to a pointer to the new
     * screen. Base implementation is empty.
     *
     * @param screenId An id that maps to the desired screen.
     */
    virtual void appSwitchScreen(uint8_t screenId)
    {
    }
...................
}

To use it, simply do this from the Screen View Class

application().appSwitchScreen(screenIdx);

I find this method is the most elegant solution for my case, but I don't know how to implement it

Designer prepare in common this for you. Simply create one interaction first for change screen and in generated base file you see for example this

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

then you control C this lines to editable gui common FrontendApplication.cpp and paste here and remove Base from name

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

too correct hpp and include. Then you can call gotoScreen... .

You can add parameter and case for uni