Skip to main content
Richard Lowe
Senior II
September 25, 2023
Solved

Dynamic Screens how to Create

  • September 25, 2023
  • 2 replies
  • 1476 views

I'd like to create a dynamic set of screens, where variables determine what containers are visable. Has anyone done anything like this?

For instance, will have a series of settings screens and based on those settings/variables, the screens will dynamically add or remove containers.

Best answer by Osman SOYKURT

Hello @Richard Lowe,

It's possible to decide which containers you want to show or hide, but all the elements of your screens need to be declared in the code. So if you mean that you want to create a new instance of a widget during runtime, it's not possible. it is possible under conditions:
- You need to have enough memory and allocate your elements in a determined range --> you need to be sure that you'll not overwrite in memory that is already used by TouchGFX

Let's say you have a custom container, and you want to show X number of this container depending on a variable value. TouchGFX can't can generate for you X of this container on runtime only if it is in a range you predefined in first place and which is safe to be overwritten. Another option instead is to have multiple instances of this custom container already declared in code, and hide/show them depending on a variable.

The function which hides or shows any drawable is the setVisible() and it's used like follows:

 

myContainer.setVisible(true);
myContainer.invalidate();

 


You can check this thread to know more about memory allocation when you need to add new widget runtime.

2 replies

Osman SOYKURT
Osman SOYKURTBest answer
Technical Moderator
September 25, 2023

Hello @Richard Lowe,

It's possible to decide which containers you want to show or hide, but all the elements of your screens need to be declared in the code. So if you mean that you want to create a new instance of a widget during runtime, it's not possible. it is possible under conditions:
- You need to have enough memory and allocate your elements in a determined range --> you need to be sure that you'll not overwrite in memory that is already used by TouchGFX

Let's say you have a custom container, and you want to show X number of this container depending on a variable value. TouchGFX can't can generate for you X of this container on runtime only if it is in a range you predefined in first place and which is safe to be overwritten. Another option instead is to have multiple instances of this custom container already declared in code, and hide/show them depending on a variable.

The function which hides or shows any drawable is the setVisible() and it's used like follows:

 

myContainer.setVisible(true);
myContainer.invalidate();

 


You can check this thread to know more about memory allocation when you need to add new widget runtime.

Osman SOYKURTST Software Developer | TouchGFX