2024-09-09 03:20 AM
Hello,
I got a screen including 4 text areas with wild card and a 4 flex buttons on top. Clicking a flex button trigger a keyboard that allows to change the content of the corresponding text area.
When any flex button is clicked, I manage to identify which button is clicked thanks to an action defined (area_clicked) that is fed with the ident number (value) of the button. This value is manually defined for each button.
I got a lot of code for a given couple (text area)&(flex button) that looks generic so I decided to give try defining a corresponding custom container until I bumped into the problem of the said value.
Does a variable or symbol exist that would define the future number of the instance of my custom container which could be used in the container definition ?
Thanks for help.
Solved! Go to Solution.
2024-09-10 08:36 AM
You could do something similar by using the children/parent mechanism we use.
In TouchGFX, each children of an element (for instance, each images, buttons, etc on a screen) is stored on a linked list. Therefore, you can travel that linked list to know how many elements are present at that level.
For instance, when instantiating an element (in this case one of the custom containers), you could use the getNextSibling method to count how many elements are already present and give that number as ID to your newly instantiated element.
Alternatively, you could use getParent, then use the forEachChild method.
Read more here .
Regards,
2024-09-09 05:38 AM
Hello @JJame.1 ,
So you want to create a custom container with a button and a TextArea with wildcard.
Put 4 of these custom container in your screen and when one of the button is clicked, the keyboard open at the screen level.
Then you type something on the keyboard and when you press enter, the corresponding TextArea gets updated.
Where exactly are you blocked?
If I had to do that myself, I would make the button press call a function at the screen level to open the keyboard, keep in memory that a keyboard is already open (to prevent opening two at a time) and keep in memory the container number then, when you press "enter", update the wildcard based on the container number.
Is it at sending the value? If so, then you can just use an action as you did previously but this time, do not use a value. Instead create 4 interactions in the screen with trigger "receive action from custom container" and then you will have to specify from which custom container you receive the action (that's why you need to create 4 interactions) such as "customContainer1) and the executed action from that interaction will be a function or action with the value of the custom container (hand defined).
I hope this helps!
If this comment answers your question, I invite you to select it as "best answer".
Regards,
2024-09-09 01:42 PM
Hello Gaetan, yes, it helps a lot !!!
So you want to create a custom container with a button and a TextArea with wildcard.
Yes.
Put 4 of these custom container in your screen and when one of the button is clicked, the keyboard open at the screen level.
Yes, I achieved this without a such custom container.
Then you type something on the keyboard and when you press enter, the corresponding TextArea gets updated.
Yes, I achieved this without a custom container.
Where exactly are you blocked?
According to your two possible solutions here below, it is obvious that I am blocked with my actual design that I thought I could quickly transpose to a custom container.
If I had to do that myself, I would make the button press call a function at the screen level to open the keyboard, keep in memory that a keyboard is already open (to prevent opening two at a time)
Yes, I achieved this.
and keep in memory the container number then, when you press "enter", update the wildcard based on the container number.
For this first solution, how do you get the container number before you keep it in memory ?
Is it at sending the value? If so, then you can just use an action as you did previously but this time, do not use a value. Instead create 4 interactions in the screen with trigger "receive action from custom container" and then you will have to specify from which custom container you receive the action (that's why you need to create 4 interactions) such as "customContainer1) and the executed action from that interaction will be a function or action with the value of the custom container (hand defined).
Yes my issue was sending the value because each 4 instances would call the area_clicked action with a value defined once for all in the custom container definition. As a consequence, I would not be able to identify which button was clicked and so which text area would have his content to be changed.
I understand well your second solution but I am eager you answer my question here above regarding your first solution because it is close to the philosophy of what I initially tried.
Thank you so much.
2024-09-10 07:32 AM
Hello @JJame.1 ,
You are welcome!
I did not mean to give two solutions, sorry for the misunderstanding.
The "second" solution is just how to implement the first one in more detail.
I have made an example with a custom container having a button and a screen having 4 of these custom containers. When you click on a custom container, you print (at the screen level) the number of the container (that you set manually in an interaction but this still prevent duplicate code).
Regards,
2024-09-10 08:36 AM
You could do something similar by using the children/parent mechanism we use.
In TouchGFX, each children of an element (for instance, each images, buttons, etc on a screen) is stored on a linked list. Therefore, you can travel that linked list to know how many elements are present at that level.
For instance, when instantiating an element (in this case one of the custom containers), you could use the getNextSibling method to count how many elements are already present and give that number as ID to your newly instantiated element.
Alternatively, you could use getParent, then use the forEachChild method.
Read more here .
Regards,
2024-09-30 03:24 AM
Hello @JJame.1
Have you been able to move forward with your issue?
Regards,
2024-10-01 11:56 AM
Hello Gaetan,
My intention is to try the way of the ID.
In order to not duplicate the code of the interaction textarea+button with keyboard, I have to pack in one custom container the textarea+button with a keyboard. It would mean as many keyboard in RAM as textarea+button, not great but I will give it try.
At this time, I chose the path of duplication to have only one keyboard. I tried to make some scripts to modify the touchGFX file adding the interactions I don’t want to duplicate manually for each textarea+button I want to add.
At this stage, my problem is solved and you can close the topic.
Thank you so much for your help.
2024-10-03 12:58 AM
Hello @JJame.1 ,
I am glad you were able to solve your problem.
Don't hesitate if you have other TouchGFX related questions!
Regards,