Vesna
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Public Member Functions | List of all members
PopUpMessageButtonHandler Class Reference

#include <PopUpMessageButtonHandler.h>

Classes

class  DataClass
 

Public Member Functions

 PopUpMessageButtonHandler ()
 Constructor creates new handler and assigns it to the given pop-up message. More...
 
virtual ~PopUpMessageButtonHandler ()
 
void OnButtonClicked (PopUpMessageWidget::Button button)
 OnButtonClicked method is called when a button is clicked in pop-up message window. The parameter identifies which button was clicked. More...
 
void SetButtonAction (PopUpMessageWidget::Button button, ApplicationDefines::ButtonAction action)
 SetButtonAction sets action for a button identified by 'button' parameter. The action is an object of type ButtonAction, which is defined in class ApplicationDefines as follows: More...
 
void SetButtonRepeat (PopUpMessageWidget::Button button)
 SetButtonRepeat if the button given as parameter is clicked, button action is executed again and message will be repeated. More...
 
bool GetButtonRepeat (PopUpMessageWidget::Button button) const
 

Constructor & Destructor Documentation

PopUpMessageButtonHandler::PopUpMessageButtonHandler ( )
explicit

Constructor creates new handler and assigns it to the given pop-up message.

Parameters
parent- pop-up message instance, which will own this handler
PopUpMessageButtonHandler::~PopUpMessageButtonHandler ( )
virtual

Member Function Documentation

bool PopUpMessageButtonHandler::GetButtonRepeat ( PopUpMessageWidget::Button  button) const
void PopUpMessageButtonHandler::OnButtonClicked ( PopUpMessageWidget::Button  button)

OnButtonClicked method is called when a button is clicked in pop-up message window. The parameter identifies which button was clicked.

Parameters
button- button that was clicked (enum type from PopUpMessageWidget)
void PopUpMessageButtonHandler::SetButtonAction ( PopUpMessageWidget::Button  button,
ApplicationDefines::ButtonAction  action 
)

SetButtonAction sets action for a button identified by 'button' parameter. The action is an object of type ButtonAction, which is defined in class ApplicationDefines as follows:

using ButtonAction = std::function<void()>;

This means that the action must be a callable object (object with operator() or a function) with no parameters. An example would be:

void func()
{
puts("Ok button pressed");
}
class MyClass
{
public:
void ShowMessage()
{
...
}
};

Often we want the function to have some parameters we need to use in the function. In that case, std::bind should be used. It binds parameters to a function before it is called, and returns a function with corresponding signature. For example:

void func(Widget *widget, int width, int height)
{
widget->SetSize(width, height); // resize the widget
}
class MyClass
{
private:
Widget *widget;
public:
void ShowMessage()
{
ApplicationDefines::ButtonAction okAction = std::bind(func, widget, 800, 600); // std::bind returns an object of type std::function<void()>
...
}
};

func() can also be a member function (which is better if we want to call private member functions or use private members). If the function is non-static, the first argument in std::bind call is the object on which we want to call the function. Example:

class Widget
{
private:
int width;
int height;
void SetSize(int w, int h)
{
width = w;
height = h;
}
static void NotResizedInfo()
{
puts("Widget was not resized!");
}
public:
void ShowMessage()
{
ApplicationDefines::ButtonAction okAction = std::bind(&Widget::SetSize, this, 800, 600); // non-static function, first argument has to be the object (in this case it's 'this')
ApplicationDefines::ButtonAction cancelAction = Widget::NotResizedInfo; // static function, has no parameters
}
};

If the function is small, we can also use lambda functions. Setting an action for cancel button from the previous example can be replaced with:

handler->SetButtonAction(PopUpMessageWidget::Cancel, [](){ puts("Widget was not resized!"); });

If the lambda function is bigger, it makes the code less readable, so a normal function (or member function) should be used instead.

Parameters
button- button for which the action is set
action- action for the button

Here is the caller graph for this function:

void PopUpMessageButtonHandler::SetButtonRepeat ( PopUpMessageWidget::Button  button)

SetButtonRepeat if the button given as parameter is clicked, button action is executed again and message will be repeated.

Parameters
button- button for which the repeat is set

The documentation for this class was generated from the following files: