2024-02-22 05:54 AM - edited 2024-02-23 01:14 AM
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:
Then, I create my screen:
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:
and
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:
Anyone can suggest the error's source?
Solved! Go to Solution.
2024-02-27 04:33 AM - edited 2024-09-16 02:13 AM
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 add the element later with the function add(yourElement).
Regards,
2024-02-27 04:33 AM - edited 2024-09-16 02:13 AM
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 add the element later with the function add(yourElement).
Regards,