elm::bubble - Simple use with C++ binding

This example shows a bubble with all fields set - label, info, content and icon - and the selected corner changing when the bubble is clicked.

The first part consists of including the headers. In this case we are working with the Elementary and Evas C++ bindings and thus we need only to include them.

Evas

Attention
If necessary the C and/or the C++ headers should be include here as well.

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:

EAPI_MAIN int
elm_main (int argc, char *argv[])
{
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_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().

See also
For more details consult elm_policy_set

Next step is creating an Elementary window, where win calls a constructor and sets the type of the win to ELM_WIN_BASIC (Elm_Win_Type), which is the indicated type for most of our examples. Here we also set the title that will appear at the top of our window and then the autohide state for it.

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.

win.title_set("Bg Plain");
win.autohide_set(true);

Note
autodel and autohide are not mutually exclusive. The window will be destructed if both autodel and autohide is set to EINA_TRUE or true.

Now we construct the elm background using the C++ method below, setting it's parent.

::elm::bg bg(efl::eo::parent = win);

To better understand, the function size_hint_weight_set for C++ bindings originated from C bindings function evas_object_size_hint_weight_set, that is EFL Evas type function. With this function we set the hints for an object's weight.

The parameters are:

This is not a size enforcement in any way, it's just a hint that should be used whenever appropriate.

This is a hint on how a container object should resize a given child within its area.

Containers may adhere to the simpler logic of just expanding the child object's dimensions to fit its own (see the EVAS_HINT_EXPAND helper weight macro in the EFL Evas Documentation) or the complete one of taking each child's weight hint as real weights to how much of its size to allocate for them in each axis. A container is supposed to, after normalizing the weights of its children (with weight hints), distribute the space it has to layout them by those factors – most weighted children get larger in this process than the least ones.

bg.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);

Note
Default weight hint values are 0.0, for both axis.

Now we add the background as a resize_object to win informing that when the size of the win changes so should the background's size. And finally we make it visible.

Note
If a color it's not setted the standard color will be used.

Here we are creating an elm::label that is going to be used as the content for our bubble:

Despite it's name the bubble's icon in this case it's actually evas::rectangle, that we set it's color to blue and at the end make it visible.

And finally we have the actual bubble creation and the setting of it's label, info and content:

Remarks
Because we didn't set a corner, the default "top_left" will be used.

To have the selected corner change in a clockwise motion we are going to use the following callback using lambda:

See also
To learn more about consult Lambda Functions with Elementary - C++11.

Now that we have our bubble and callback all that is left is adding our lambda as a clicked callback:

This last bubble we created was very complete, so it's pertinent to show that most of that stuff is optional a bubble can be created with nothing but content:

Now we only have to set the size for our window and make it visible.

And finally, start the elm mainloop, starting to handle events and drawing operations.

Our example will look like this:

bubble_cxx_example_01.png
See also
Full source code bubble_cxx_example_01.cc .