cancel
Showing results for 
Search instead for 
Did you mean: 

Ident number of button in custom container

JJame.1
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
GaetanGodart
ST Employee

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,

Gaetan Godart
Software engineer at ST (TouchGFX)

View solution in original post

6 REPLIES 6
GaetanGodart
ST Employee

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,

Gaetan Godart
Software engineer at ST (TouchGFX)


 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.

 

 

 



 

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,

Gaetan Godart
Software engineer at ST (TouchGFX)
GaetanGodart
ST Employee

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,

Gaetan Godart
Software engineer at ST (TouchGFX)

Hello @JJame.1 

 

Have you been able to move forward with your issue?

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)
JJame.1
Associate II

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.