cancel
Showing results for 
Search instead for 
Did you mean: 

How to add custom container during runtime

FCola.1
Associate II

Hello everyone, 

I am trying to improve my skills with TouchGFX. I want to add dynamically a custom container at my current screen during runtime. 

Is there a method to do it without using a container widget? 

I don't want to put my custom container in current screen and use SetVisible() method (i don't want to waste memory).

 

P.S. 

Here is what I've done:

First of all, I create those  simples Custom Containers with TouchGFX:

 

 

FCola1_4-1708679383016.png

 

Catturast3.PNG

 Then, I create my screen:

Catturascreen.PNG

The idea is very simple: When User touchclicks "Right Button", the volume custom container will appears in the top right corner (container1).

 

Here is a part of the code:

FCola1_0-1708679065472.png

and 

FCola1_1-1708679077405.png

VolWidget 1 is the first Custom Container (Volume Custom Container).

Now, what I have accomplished is that the Custom Container indeed appears in the top right corner but I receive an exception frame: 

 

FCola1_3-1708679329082.png

Anyone can suggest the error's source?

1 ACCEPTED SOLUTION

Accepted Solutions
GaetanGodart
ST Employee

Hello @FCola.1 

 

From what I understood you want a single widget/element to appear when the user press a button?
You also want to avoid wasting memory space?

 

If you add an element, this element will have to be store, if you add it at runtime, it will have to have a specific memory address and space to be stored just like you would have to store it if you add it directly in Designer.

So whether you add the element in Designer or during runtime, it will take the same space after the element is added.

Therefore, there is no benefit to add an element during runtime.

 

As per the error you encounter, the TouchGFX application keeps all the element at a predefined and optimized memory address and space. It is not, by default, possible to add an extra element in that memory space which may be the reason of your error.

It could be possible to enlarge this memory space or to use the linker script to allocate a memory space to be added but in your project I would advise to keep your element in the screen at all time and setting it visible or not based on the user's actions, there is no need to make it more complex.

 

I also see that you are doing container1.add() which means that TouchGFX already know the type of container1. Indeed you seemed to already have added in in your ButtonLayout screen (c.f. picture 2). So in that case you do not need to add it. Re-adding it would generate an error.

You could use the function remove(yourElement) to remove an element from the screen but it will still be kept in memory, allowing you to adding the element later with the function add(yourElement).

 

Regards,

 

Gaetan Godart
Software engineer at ST (TouchGFX)

View solution in original post

1 REPLY 1
GaetanGodart
ST Employee

Hello @FCola.1 

 

From what I understood you want a single widget/element to appear when the user press a button?
You also want to avoid wasting memory space?

 

If you add an element, this element will have to be store, if you add it at runtime, it will have to have a specific memory address and space to be stored just like you would have to store it if you add it directly in Designer.

So whether you add the element in Designer or during runtime, it will take the same space after the element is added.

Therefore, there is no benefit to add an element during runtime.

 

As per the error you encounter, the TouchGFX application keeps all the element at a predefined and optimized memory address and space. It is not, by default, possible to add an extra element in that memory space which may be the reason of your error.

It could be possible to enlarge this memory space or to use the linker script to allocate a memory space to be added but in your project I would advise to keep your element in the screen at all time and setting it visible or not based on the user's actions, there is no need to make it more complex.

 

I also see that you are doing container1.add() which means that TouchGFX already know the type of container1. Indeed you seemed to already have added in in your ButtonLayout screen (c.f. picture 2). So in that case you do not need to add it. Re-adding it would generate an error.

You could use the function remove(yourElement) to remove an element from the screen but it will still be kept in memory, allowing you to adding the element later with the function add(yourElement).

 

Regards,

 

Gaetan Godart
Software engineer at ST (TouchGFX)