What is the best way to update a custom component across multiple Screens?
I'm building a complex application with multiple screens in TouchGFX 4.16.
All those screens have the same menu bar with indications like battery energy level, time, etc.
All screens include the MenuBar custom component.
When the battery level changes, I want the model to be able to update MenuBar.
Currently, I'm doing this to update the battery:
In Model.cpp
bool bShouldNotify = pollBatteryState();
if (bShouldNotify)
{
modelListener->notifyBatteryStateChanged(m_oDeviceState.oBattery);
}In SomeScreen1Presenter.cpp
void SomeScreenPresenter::notifyBatteryStateChanged(oBatteryState_t const oBatteryState)
{
view.updateBatteryState(oBatteryState);
}In SomeScreen1View.cpp
void SomeScreenView::updateBatteryState(oBatteryState_t const oBatteryState)
{
// Update widgets
MenuBar.updateBattery(oBatteryState);
}If you need to do this for all screens, this will create a lot of code.
Is there a better way to update views that all use the same component?
An event-based system maybe?
Regards,
GB