2019-01-21 11:25 PM
Hello
how can we get a pointer to the current view in a container (to get for example a variable value contained in the view object)
thanks
best regards
2019-01-24 05:46 AM
Hi @Professional,
You could pass "this" from your view to the container.
Best regards,
Martin
2019-01-24 05:55 AM
Hello,
thank for your answer but concretly i don't know how to do this : where is called the constructor of the container ?
i have the class :
class TimeView : public TimeViewBase
in the base class i have the container Cont_menu_bar cont_menu_bar1; declared.
But the creation of that is done in touchGFX generated code.
cont_menu_bar1 can fire a callback placed in the container, but i would like to call a TimeView callback (getting this may make it work..)
regards
2019-01-24 05:58 AM
If it's a custom container you should have a concrete implementation of this container. You can add a method there to set the pointer for the container and call that during setupScreen() of your view:
e.g.
::setupScreen()
{
myContainer.setViewPtr(this);
}
2019-01-24 06:24 AM
yes i have tried to have a function in my container.hpp and cpp :
#include <mvp/View.hpp>
void setViewPointer(View * this);
but i can't compile that as View is not defined...
have you a complete example ?
thanks
regards
2019-01-28 02:32 PM
Just to clarify. I've posted an example of how to do this in your other post. Basically you want a pointer to your concrete view, e.g. MyView in order to access whatever methods you want. And in order to avoid circular references, you have to make a forward declaration to your view from your container.
I'll attach the project here as well.
2019-01-28 11:32 PM
Hello
thank you for your example, but it doesn't solve completly my problem :
you have declared the function void setPtr(Screen1View* ptr);
But i would like to have a generic declaration for the view pointer : function void setPtr(View* ptr);
The goal is to call any kind of view from that container (Screen1View, Screen2View...)
How can i do this ? (i have trouble to compile such a declaration)
Thanks for your support
2019-01-29 02:49 AM
Then you need to either cast your view pointer (making the container type aware) or pass it a pointer to a base-view which would make it less type aware but still tied to a certain base view with certain capabilities.
I think what you need to do is something else. You need to pass in a new callback which is completely generic that you can define in whatever view you want and then pass whatever values to that view - Based on the values you make the view perform a certain action (You could have this callback functionality in a base view). Does that make sense?
Best regards,
Martin
2019-01-29 04:49 AM
Hello
thank you for your reply.
The problem is how to pass a generic function pointer to a container and then call this function from the container...
Bests regards
2019-01-29 04:52 AM
From the handler inside your Custom Container you simply call viewCallback->execute(SOME_VALUE). And because the view hooked the callback to a handler of it's own (regardless of view type) you will hit that handler and can now react to whatever value was passed by the container.