cancel
Showing results for 
Search instead for 
Did you mean: 

Callback from a common custom container to the current view

Professional
Senior

Hello

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

19 REPLIES 19
Martin KJELDSEN
Chief III

Hi @VKyri​,

Back from vacation here. Did you remember to update your handler to take a box with border?

/Martin

Professional
Senior

Hello,

thank you for your reply. I think we can close this topic, as i found a solution for it...

Best regards

Professional
Senior

My new problem is to draw a circle on each touch screen press (at the position of the press) and on each screen drawn in touchGFX project... if you have any simple idea...

I tried to add an invisible box on all the screen to detect the press, but now the button behind this box are not activated by touchGFX...

thanks best regards

Martin KJELDSEN
Chief III

You could simply overwrite View::handleClickEvent(ClickEvent& evt); and do something at the pressed coordinates.

Professional
Senior

thank for the tip, but how can i implement this ?

Should i use the  virtual void handleClickEvent(const ClickEvent& evt); from Screen.hpp ?

I tried in one of my screen code to add :

void DigicodeView::handleClickEvent(const ClickEvent& evt)

{

      circle1.setPosition(0, 0, 144, 80);

}

but i have an error of compilation

Error[Pe298]: inherited member is not allowed ...

Martin KJELDSEN
Chief III

Yes, you should. Which line does it complain about?

Also, what you should do is statically allocate memory for a number of circles (in an array or list, etc) which are all hidden. You can then, on each press on the screen, place the next circle at the pressed x,y call mycircle.setvisible(true) and mycircle.invalidate(); until there are no more circles left.

/Martin

Professional
Senior

on the handleClickEvent i have the error

I just want a circle that will appear on the key press : so maybe it is not usefull the array ?

Thanks

RMoha.2
Associate II

This might be an old thread, but found it useful to share for future references.

Probably the easiest solution I found that defines a communication from the container "Child" back to the View "Parent" is:

  • keep a flag in the Model. When the event happens, the flag is updated, and if needed:
  • the container is updated as well.
  • Each time the container is setup, it accesses the status from the Model using a reference from the FronendApplication:

void my_container::initialize()

{

   my_container_local_flag = static_cast<FrontendApplication*>(Application::getInstance())->get_Model_flag_status();

}

Hello @Martin KJELDSEN 

Thanks for your demo on this topic, it helps me a lot.

One more question: each time I click the box, it will call the callback twice(press and release the box).

Is there some way that I can listen to the release event only?

Thanks again!

Have a good day!

Finally, I got it.

Just checking the event type is enough:

void CustomContainer1::boxClickedHandler(const Box &box,
                                         const ClickEvent &event) {
  if (event.getType() != ClickEvent::RELEASED) {
    return;
  }

  if (&box == &box2) {
    touchgfx_printf("CustomCotainer: box clicked.\n");

    if (viewCallback && viewCallback->isValid()) {
      viewCallback->execute(type);
    }
  }
}