Skip to main content
JReed.1856
Associate II
Dec 2, 2019 12:12 PM UTC
Solved

How do I get the active screen from the model

I'd like to only update variables, which are shown on the current screen. How do I get the current screen in a switch case structure, in the model::tick() function. I tried to alter the tick function to get the currentScreen parameter from the FrontendApplication.hpp as a variable, but this did not work

This topic has been closed for replies.
Martin KJELDSEN
Martin KJELDSENBest answer
Principal III
Dec 2, 2019 2:11 PM UTC

I'd simply store the active screen in the model when you activate a screens presenter.

class MyView;
 
class MyPresenter : public Presenter, public ModelListener
{
public:
 MyPresenter(MyView& v);
 
 /**
 * The activate function is called automatically when this screen is "switched in"
 * (ie. made active). Initialization logic can be placed here.
 */
 virtual void activate()
 {
 model->setActiveScreen(MYSCREEN); 
 }
...

3 replies

Martin KJELDSEN
Martin KJELDSENBest answer
Principal III
Dec 2, 2019 2:11 PM UTC

I'd simply store the active screen in the model when you activate a screens presenter.

class MyView;
 
class MyPresenter : public Presenter, public ModelListener
{
public:
 MyPresenter(MyView& v);
 
 /**
 * The activate function is called automatically when this screen is "switched in"
 * (ie. made active). Initialization logic can be placed here.
 */
 virtual void activate()
 {
 model->setActiveScreen(MYSCREEN); 
 }
...

JReed.1856
Associate II
Dec 2, 2019 3:15 PM UTC

Ah thank you, that is actually an easy still elegant solution.=)

Martin KJELDSEN
Principal III
Dec 4, 2019 8:47 AM UTC

I think so too. You could do some type-checking magic, but this is a lot simpler and more readable.

/Martin