cancel
Showing results for 
Search instead for 
Did you mean: 

Callbacks between container and view

Priyank
Associate III

Hi, I went through some other discussions discussing a similar problem, but they did not seem to help. 

I have screen one which displays (dynamically) a container. The container has a button on it, which when clicked, changes screens to screen 2. At the same time the container needs to send data to screen 2 (an int). The button is a flex button which I set up from the GUI call a virtual function. 

I would prefer a way where the container is not permanently tied to screen 2, as this container appears on multiple screens and does something similar.

1 ACCEPTED SOLUTION

Accepted Solutions

That is (one of) the issue with dynamic. I think your best bet is to store each of your element in an array or vector.

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)

View solution in original post

13 REPLIES 13
GaetanGodart
ST Employee

Hello @Priyank ,

 

What seems to be the problem exactly?

To me it seems that you want to have the same widget in multiple screens but this is not possible, you just have to add it to each screens individually to end up with the intended result.

When you click your button, you call a function doing 2 things :

  1. change screen
  2. send data

I would advise you start by sending the data to the model and then you change the screen to be safe.

Overall, just add your widget to each screens and start by sending your data before switching screen and your design will be fine.

 

I hope this helps! :smiling_face_with_smiling_eyes:
If this comment answers your question, I invite you to select it as "best answer".

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)
Priyank
Associate III

Thank you, here is is some more context:

I am adding these containers to each screen that needs it

I am just having a problem with getting the container to send data to the view/model. The tutorials say to use callbacks but I can't get that to work. Some are also binding the container itself to a view, but I don't want that because this container will be on many screens.


I am adding these containers to each screen that needs it


That is fine, I do it like that too myself.

 


I am just having a problem with getting the container to send data to the view/model. The tutorials say to use callbacks but I can't get that to work


Which tutorial are you following?
I advise you to look at these tutorials :

 


Some are also binding the container itself to a view, but I don't want that because this container will be on many screens.

What do you mean by "binding the container to the screen" ?

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)
Priyank
Associate III

I'm used Tutorial 3 method for most of my data sending but I'm not sure it would work in thi ssituation because 

1. the container shows up on the screen dynamically (it may appear once, twice, three times,etcA)

2. the container does not have a presenter to interact with the view/model

3. the button which is used to click the container is apart of the container itself

So, am I right to assume the data has to be sent through the container files? This is what I am thinking, but can't find a way to send the data from a container to a model/view


1. the container shows up on the screen dynamically (it may appear once, twice, three times,etcA)

It is not recommended to add elements dynamically, especially in your case, because how do you plan on getting access to containerName.mydata? What is the name of the containers you create dynamically?
Maybe you should add the maximum number in your GUI and set them as invisible.

 


2. the container does not have a presenter to interact with the view/model


Yes, but you can access it throught the screen it is in.
Such as : ContainerName.MyData.

Example:
In the container.cpp I add "int myData = 10;"
In the screen.cpp I add "touchgfx_printf("\nVal is : %d.", customContainer11.myData);"
I am able to correctly print the value 10.

 


3. the button which is used to click the container is apart of the container itself


Then, clicking the button should call a function (in the screen.cpp), in this function, you can access the value of the container such as "containerName.dataName" and send it to the presenter of the screen you are in.

 


So, am I right to assume the data has to be sent through the container files? This is what I am thinking, but can't find a way to send the data from a container to a model/view


The data starts from the container, goes to the screen, then presenter, then model.

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)
Priyank
Associate III

Gotcha, so most of what you said is only possible if the container is added to screen from gui and set invisible right? I planned on doing it dynamically is because the container is called product for example. The user can have anywhere from1-48 products which will appear on the product screen. I wanted to save space by dynamically adding only the amount of products they have. When I dynamically added the product container I also assigned the container an id for identifying it meaning the product container cpp/hpp has a variable for id. Would this be inefficienct? I am open to populating 48 products on the scroll wheel which they appear on, and keeping them invisible. However, it comes down to efficiency/memory usage, would setting 48 product containers be more efficient than dynamically added only the amount of products that the user has?

If you have a way to access the containers that you add dynamically it should be fine, it should work.

I don't think you will see performance difference and in either cases, your project would run without issue. Saving memory here doesn't seems necessary because it is not critical, therefore, it is up to you to implement it the way you prefer.

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)

Thank you, so if I keep it dynamic, how would I deal with sending the container id to the view/model? Since there is no presenter

That is (one of) the issue with dynamic. I think your best bet is to store each of your element in an array or vector.

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)