2024-04-03 04:49 AM
Hello TouchGFX Community,
As part of my project, I'm developing a menu system within a TouchGFX application. The menu is intended to display either ToggleButtons or standard Buttons based on configurations set by the user. The aim is for the UI to dynamically adapt to these configurations, showcasing different functionalities as per the user preferences.
I have read, that creating UI components dynamically on the screen at runtime is forbidden by TouchGFX design, however I've been exploring the possibility of dynamically generating these components before the screen initializes, tailored to the user's setup.
I've had success with dynamically creating buttons pre-initialization, but only when they are of the same type, so I could keep them in the same array/vector.
I know that the other route would be to predetermine all possible buttons in the .hpp file and manage their visibility according to user configurations, but I would prefer to avoid this method to save some of that memory.
Given this, I'm curious if anyone has insight or experience with dynamically generating different types of UI components in TouchGFX, particularly before the screen is fully initialized. Is there a known approach or documentation that might have eluded me?
Any advice, shared experiences, or pointers to relevant resources would be immensely appreciated. Thank you for your time and assistance!
Solved! Go to Solution.
2024-04-08 03:15 AM
Hello @mateo_906 ,
Indeed it is not recommended to add elements at runtime because embedded projects have limited memory.
The recommended method is to create 2 menus and only display the one the user want to see based on the parameters but you seems to already know that.
I have made an example of widget runtime creation : example create widget at runtime
It seems you were able to do the same thing.
You also used a vector to add the elements you created, so did I.
I cannot think of a method without the vector but creating 2 empty vector won't take much memory so you could go or that.
So creating 2 empty vectors and then adding the elements based on the users parameters seems to be what you want to do.
If this answered your question, I invite you to select this message as "best answer".
Regards,
2024-04-08 03:15 AM
Hello @mateo_906 ,
Indeed it is not recommended to add elements at runtime because embedded projects have limited memory.
The recommended method is to create 2 menus and only display the one the user want to see based on the parameters but you seems to already know that.
I have made an example of widget runtime creation : example create widget at runtime
It seems you were able to do the same thing.
You also used a vector to add the elements you created, so did I.
I cannot think of a method without the vector but creating 2 empty vector won't take much memory so you could go or that.
So creating 2 empty vectors and then adding the elements based on the users parameters seems to be what you want to do.
If this answered your question, I invite you to select this message as "best answer".
Regards,