Skip to main content
JReed.1856
Associate II
December 2, 2019
Solved

How do I get the active screen from the model

  • December 2, 2019
  • 3 replies
  • 1155 views

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.
Best answer by Martin KJELDSEN

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
December 2, 2019

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
December 2, 2019

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

Martin KJELDSEN
Principal III
December 4, 2019

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

/Martin