The first part consists of including the headers. In this case we are only working with the Elementary C++ binding and thus we need only to include him.
Now we need to actually start the code and set the elm_policy, which defines for a given policy group/identifier a new policy's value, respectively. In this example the only policy we need to set a value for is
ELM_POLICY_QUIT, possibles values for it are:
ELM_POLICY_QUIT_NONE:Never quit the application automatically;
ELM_POLICY_QUIT_LAST_WINDOW_CLOSED:quit when the application's last window is closed;
ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN: quit when the application's last window is hidden;
As you can see, the policy we chose was to quit when the last win is hidden as opose to examples with the C bindings where we perpetually set it to quit when last win was closed. This changed was necessary because in C++ binding as the elm mainloop stop running all object are destroyed, references are unreferenced and events are stopped at ELM_MAIN().
Next step is creating an Elementary window, in this example we use the C++ binding method with the elm_win_util_standard_add that is a elm_win_legacy function, better explained below. And then we set the autohide state for it.
elm_win_util_standard_add (const char *name, const char *tittle) Adds a window object with standard setup.
name- The name of the window;
title- The title for the window.
This creates a window but also puts in a standard background with
elm_bg_add(), as well as setting the window title to
title. The window type created is of type
ELM_WIN_BASIC, with the
NULL as the parent widget. Returns the created object or
NULL on failure.
The autohide works similarly to
autodel, automatically handling "delete,request" signals when set to
true, with the difference that it will hide the window, instead of destroying it.
It is specially designed to work together with
ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN which allows exiting Elementary's main loop when all the windows are hidden.
autodeland autohide are not mutually exclusive. The window will be destructed if both autodel and autohide is set to
Now let's create the label with the C++ binding method, passing our window object as parent. We'll also set to this label the text that we'll use later on the popup.
Using the same method we'll create our popup passing our window object as parent. We'll also set the timeout to 3.0 seconds, label as content, the title and visibility true for our popup.
Our popup will hide every time the lambda type function is called. The lambda function get the popup object by reference and set it's visibility to false, making it invisible. In this example we are using std::bind to bind the parameters of our lambda function to return as std::function object to popup_hide which was declare as auto.
To learn more consult Lambda Functions with Elementary - C++11.
In this example we'll add the popup_hide in the timeout callback and the block_clicked callback. This results in hiding the popup in maximum of 3.0 seconds or when the popup block is clicked.
Finally we just have to make our window visible and set it's size, then run the elm mainloop, starting to handle events and drawing operations.
This example will initially look like this:
Once the popup is hidden after timeout: