Skip to main content
JPabl.1
Associate III
October 30, 2024
Solved

How to update single custom container for different screens

  • October 30, 2024
  • 3 replies
  • 844 views

Hi there Touchgfx team!

I've this ui requirement: A header with battery, date/time, battery, and extra icon. 

JPabl1_0-1730312593296.png

JPabl1_1-1730312622260.png

I also have 15 different screens. The model receives a signal from the backend and thats how it knows that it needs to show the USB icon. 

I know how to do a notify from model -> view, and I know I could do this for the 15 different screens. The problem I'm facing is that the USB icon needs to appear in the other screens if the user goes to a different screen. I know I could also setup a flag in the model and get the vale in the setupScreen()

 

My question is: is there an easier way to do this? I would like to avoid creating 15 different propagation functions for the USB, and other 15 for the other icon. I was thinking about creating a custom container and updating it from the model just once, and somehow all the views with the container will update.

 

I have the same question for the "date/time" text. At this moment, each view has a function that calls the presenter, and then the model, to get the date value. But, if the data/time text is in all the screens, is there a better way?

 

Thanks a lot in advance

Best answer by GaetanGodart

Hello @JPabl.1 ,

 

No, there is no other way of doing it as this is the role of the MVP.

I understand that created 2 functions for each screen is a bit annoying, but they are mostly copy paste.

 

Regards,

3 replies

GaetanGodart
GaetanGodartBest answer
Technical Moderator
November 1, 2024

Hello @JPabl.1 ,

 

No, there is no other way of doing it as this is the role of the MVP.

I understand that created 2 functions for each screen is a bit annoying, but they are mostly copy paste.

 

Regards,

Lead II
November 1, 2024

How much code does it take?

  • One method in model: IconBarData_t getIconBarData();
  • One method in modellistener: IconBarData_t getIconBarData() { return model->getIconBarData();}
  • and one line in each view's setupScreen(): iconBar.setIcons(presenter->getIconBarData());

Time can be pulled from the model every x ticks or pushed to the view when time changes.

My application has some display settings such as temperature unit (Celsius or Fahrenheit) and each screen pulls the unit from the model via the presenter (method defined in modellistener). Some screens do not pull the unit, but get values with units pushed to them.

"Kudo posts if you have the same problem and kudo replies if the solution works.Click ""Accept as Solution"" if a reply solved your problem. If no solution was posted please answer with your own."