cancel
Showing results for 
Search instead for 
Did you mean: 

Can you call a method on view from a custom container?

Professional
Senior

Hello, can someone help me on the current question already posted :

I have a custom container common to several screen (with OK button in it).

How can i call a callback of the current screen when a button is pressed in the container ?

I do call the callback of the custom containe, but don't know how to propagate it to the current view.

(for example when OK button is pressed i want to execute the action in each view containing this custom container)

I there an example of this ?

thanks

regards

18 REPLIES 18

Hello

do you understand my problem ?

thanks

best regards

Yes. I've created an example for you (4.10.0). I took inspiration from your old project having a custom container with a box as a clickable element to make it familiar. When clicking that box, it then calls a method on the view.

Have a look. I removed the touchgfx folder to keep the size down. You can substitute that with your own or simply import this gui into another application.

LRaim.2
Associate II

Hi, not sure this answers your question fuly, but might suggest other way. Actually I have a similar issue....I also have a base Container that is placed in all my views and thi container has some elements that I must draw on top of all other elements of the view. What I needed to do was to be able from the View to calla a method on the Container that would remove items from the container and place them IN the View as last elements added.

This is what I did:

In the Container added a method lie this

void addScreenShotBlocker(touchgfx::Container &Cont);

Implemented as such

void ccBaseTemplate::addScreenShotBlocker(touchgfx::Container &Cont)
{
	remove(SC_bBG);
	Cont.add(SC_bBG);
	remove(SC_tText);
	Cont.add(SC_tText);
}

Then in the View I would call this method (in setupscreen()) simply like this

_ccBaseTemplate.addScreenShotBlocker(this->container);

As I said my case is a littlebit different from what you whant since I actually have to reach the Container in the View to add elements, but this way I have been able to refer to the generic touchgfx::Container &Cont instead of having to call the specific View each time.

Hope it heps.

HPham.1590
Senior

Hello,

May be I met the same problem. Due to the custom container won't accept to use the presenter and model, so we can't save directly data from these container to the model. But in Screen View we can. Each Container is define in view and in this view we can access to any children of this object. You can see my custom container below: 0693W000004ImrPQAS.png

So in Custom Container, we can save the variable which need to save to model as public variable in CustomContainerView.hpp like:

public:
    int YourVariable = 10;

and in .cpp file, you can modify this variable in callback function or something like that.

In ScreenView, simply you only need to call this variable and save them to model manually:

YourCustomContainer.YourVariable;

Hieu

@Martin KJELDSEN​  Your ContainerCallback example works, but I have a variation on the OP's scenario. I have multiple screens using a common custom container (this is via designer), which has buttons and want to handle the clicks in the view. Would a more generic solution using templates be possible, or have the callback in the current view?

The best solution would be to have a base-view that had this custom container (+ the callback + callback handler), and then all the screens that needed it would inherit from that. Unless those views needed to do something differently of course. But this isn't possible atm - The designer team is working on getting it integrated.

Atm, you kind of have to set up a callback for each of the views and connect it to the callback inside the custom container.

/Martin

Yes. So the container shouldn't have a pointer to a view. Could you describe how the callbacks should be done?

In the same way as the example. For each concrete view, you would connect the callback in the view to the callback in the container and configure the handler to be called. Unfortunately, you have to do something for each view since base-views aren't supported yet - But this is a priority to get done. I don't remember if i shared a script that makes modifications to the generated files post-code-generation.

/Martin

Thanks for the code provided, exactly what I needed! And sorry for picking up an old thread.

Based on this example, is there's a way to implement this: two same clickable containers on the screen, how can I tell which one was clicked?

That is probably trivial task but I can't figure it out due to lack of c++ knowledge. Or I should use another approach?