Can you call a method on view from a custom container?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-22 12:21 AM
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
Solved! Go to Solution.
- Labels:
-
TouchGFX
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-28 02:24 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-24 05:48 AM
Hi @Professional​,
I'm back from travels. The easiest thing is to take a look at the Button widget. It does exactly what you're after. It takes a callback that you define a handler for in the view, and when you press the button, internally, the callback is fired and execution will enter your handler. You should have the code for Button inside touchgfx/widgets.
Let me know if you need more pointers!
Best regards,
Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-24 06:03 AM
Hello again!
i don't understand : the pb is not that the callback is not fired in the container (as a button in a view). The problem is to transmit this callback to the view integrating this container (several view can have this container, and action can be different according to the view...)
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-25 02:46 AM
Hi Professional,
If you create a simple designer project with a button and an interaction that reacts to that button, you'll see what i mean. Here's the code the designer generates - I've posted parts of the baseview cpp and hpp file. You'll see that :
- the buttonCallback is defined in the view base constructor. Here, the callback is tied to a handler method called buttonCallbackHandler() which is defined further down.
- The callback is templated with the recipient of the callback as well as a reference to the object responsible for the callback. And the handler takes just the responsible object reference.
- Once you set the action on the button, clicking it (due to button internals) should result in the handler method getting called.
I'm not sure if this helps clarify the process.
Screen1ViewBase::Screen1ViewBase() :
buttonCallback(this, &Screen1ViewBase::buttonCallbackHandler)
{
box1.setPosition(0, 0, 800, 480);
box1.setColor(touchgfx::Color::getColorFrom24BitRGB(255, 24, 24));
button1.setXY(246, 154);
button1.setBitmaps(Bitmap(BITMAP_BLUE_BUTTONS_ROUND_EDGE_SMALL_ID), Bitmap(BITMAP_BLUE_BUTTONS_ROUND_EDGE_SMALL_PRESSED_ID));
button1.setAction(buttonCallback);
add(box1);
add(button1);
}
void Screen1ViewBase::setupScreen()
{
}
void Screen1ViewBase::buttonCallbackHandler(const touchgfx::AbstractButton& src)
{
if (&src == &button1)
{
//Do something based on button 1 clicked
}
}
...
private:
/*
* Callback Handler Declarations
*/
void buttonCallbackHandler(const touchgfx::AbstractButton& src);
/*
* Callback Declarations
*/
touchgfx::Callback<Screen1ViewBase, const touchgfx::AbstractButton&> buttonCallback;
};
#endif // SCREEN1_VIEW_BASE_HPP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-25 04:56 AM
Hello
thanks for your reply, but this partly what i want to do : in my case, in the callback of a container i want to call another callback of the view containing this container. Going to the callback of the container is Ok, but then i would like to call a callback of the view
1) in the view pass a pointer of the view to the container
cont_home_warning1.setViewPtr(this);
2)in the container
void setViewPtr(touchgfx::View<Presenter> *v);
void Cont_home_warning::setViewPtr(touchgfx::View<Presenter> *v)
{
view_prt = v;
}
3) then call in the container callback th callback of the view
if (v != null)
{v->callback();}
but this doesn't compile..
How I can you pass a pointer to a container ?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-28 05:31 AM
Hello,
can some one help me on this subject
thanks
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-28 05:34 AM
Hi,
Can you please provide a build log? Maybe even your project.
Best regards,
Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-28 06:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-28 06:32 AM
Hi,
The project is not immediately working for me (some files missing) and i'm not seeing a lot of code. Only a custom container with a Box (ClickListener). Do i have the right files? You said you'd done some work on the actual container trying to store a pointer to the view. I also noticed it's a 4.8.0 project - You should consider upgrading to 4.10.0 which has a lot of new features.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-28 06:42 AM
Hello
don't know why the zip is not working (i use 4.10)
just a piece of code :
how can i jump from time_boxClickHandler to a callback in the view ?
thanks
CustomContainer1::CustomContainer1() :
BoxClickedCallback(this, &CustomContainer1::time_boxClickHandler)
{
box1.setClickAction(BoxClickedCallback);
}
void CustomContainer1::time_boxClickHandler(const Box& b, const ClickEvent& evt)
{
//treat only pressed event
if (evt.getType() != ClickEvent::PRESSED) return;
if (&b == &box1)
{
}
}