Skip to main content
Professional
Associate III
January 14, 2019
Solved

Callback from a common custom container to the current view

  • January 14, 2019
  • 15 replies
  • 4805 views

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

This topic has been closed for replies.
Best answer by Martin KJELDSEN

Here it is. A project that defines a screen with two custom containers (Both CustomContainer1). CustomContainer1 has a background and a ClickListener Box. When the Box is pressed, the CustomContainer catches this in an internal handler and then calls a Callback (set by the view) to communicate it's identity back. Based on this identity (The first or the second custom container) it will show/hide the custom containers.

I've written some comments in the code - Let me know if you need more information.

15 replies

Martin KJELDSEN
Principal III
August 5, 2019

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

Professional
Associate III
August 5, 2019

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
Principal III
August 5, 2019

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
Associate III
August 5, 2019

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 III
June 12, 2020

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();

}