2025-01-16 04:17 PM - edited 2025-01-16 04:20 PM
Brand new to TouchGFX (and C++) but enjoying so far!
I have togglebutton(s) on screen2 and I want the state to be set to off on powerup. (The defaul is on)
I have a splash screen that only displays on power up for 3 seconds. Is it best to set the state of toggles on screen2? If so, how would I reference those widgets on the second screen?
Is there a better way?
I may leave screen2 and come back to it so I don't want to use screen2::setupScreen()
Thanks!
2025-01-17 12:07 AM - edited 2025-01-17 01:04 AM
Hello
Maybe you could use model-class to save state of switches, if the state should save when re-enter to screen which contains switches.
Basically you need to read states from model at setupScreen function and then set state to switch.
And then, when user changes the state, you should save the new state to model.
And then model class keeps the state and you can also init those how you like.
So I recommend you to first study model-presenter-view communication.
Here is one example about communication, it might give you some inspiration, even it is not what you exactly ask.
Hope this helps
Br JTP
2025-01-17 05:21 AM
Hello @TIF ,
As JTP said, you should use the model view presenter architecture, you can read more about it here .
Also, you can learn you to use it by doing the tutorial 3 .
For your project, you want to have a variable in the model that you initialize to true (or "on"). Since it is in the model, it will only be initialized at the application's startup, not when the screen changes (unless you add code), then you simply use the same principle as in the tutorial 3 to allow the user to change the value.
Regards,