This example places three Elementary Datetime widgets on a window, each of them exemplifying the widget's different usage.
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, 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 win.
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.
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 and for this we use the C++ method below, setting it's parent.
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.
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.
A box arranges objects in a linear fashion, governed by a layout function that defines the details of this arrangement. The box will use an internal function to set the layout to a single row, vertical by default.
Now let's create the box with the C++ binding method, passing our window object as parent. Using Evas weight_set function again to hint on how a container object should resize a given child within its area.
Then we add the box as a resize-object to win informing that when the size of the win changes so should the box's size. Remember always to set the box visibility to true.
The first of them is "only Date display". We will create it using the C++ method below. The weight hint works with datetime the same as it did with background and box.
Now we have to The function size_hint_align_set
for C++ bindings originated from C bindings function evas_object_size_hint_align_set, that is EFL Evas type function. With this function we set the hints for an object's alignment. The parameters are:
These are hints on how to align an object inside the boundaries of a container/manager. Accepted values are in the 0.0 to 1.0 range, with the special value EVAS_HINT_FILL used to specify "justify" or "fill" by some users. In this case, maximum size hints should be enforced with higher priority, if they are set. Also, any padding hint set on objects should add up to the alignment space on the final scene composition.
For the horizontal component, 0.0 means to the left, 1.0 means to the right. Analogously, for the vertical component, 0.0 to the top, 1.0 means to the bottom.
This is not a size enforcement in any way, it's just a hint that should be used whenever appropriate.
An important feature for the datetime is the setting of what we want it to display. We can achieve that by using:
field_visible_set
( Elm_Datetime_Field_Type fieldtype_, bool visible_)
Parameters are:
fieldtype_:
type of the field, supports 6 fields:ELM_DATETIME_YEAR:
Indicates Year field.
ELM_DATETIME_MONTH:
Indicates Month field.
ELM_DATETIME_DATE:
Indicates Date field.
ELM_DATETIME_HOUR:
Indicates Hour field,
ELM_DATETIME_MINUTE:
Indicates Minute field.
ELM_DATETIME_AMPM:
Indicates AM/PM field.
visible_:
true
field can be visible, false
otherwise.true
.For this first datetime we are setting the HOUR, MINUTE and AM/PM to not be visible, doing this we'll display in our datetime the year, month and date.
When using the elm box the packing method of the subobj - datetime in this case - should be defined. There are four possible methods:
pack_start(subobj_)
- Add an object to the beginning of the pack list. Pack subobj_
into the box obj, placing it first in the list of children objects. The actual position the object will get on screen depends on the layout used. If no custom layout is set, it will be at the top or left, depending if the box is vertical or horizontal, respectively.pack_end(subobj_)
- Add an object at the end of the pack list. Pack subobj_
into the box obj, placing it last in the list of children objects. The actual position the object will get on screen depends on the layout used. If no custom layout is set, it will be at the bottom or right, depending if the box is vertical or horizontal, respectively.pack_before(subobj_, before_)
- Adds an object to the box before the indicated object. This will add the subobj_
to the box indicated before the object indicated with before_
. If before is not already in the box, results are undefined. Before means either to the left of the indicated object or above it depending on orientation.pack_after(subobj_, after_)
- Adds an object to the box after the indicated object. This will add the subobj_
to the box indicated after the object indicated with after_
. If after is not already in the box, results are undefined. After means either to the right of the indicated object or below it depending on orientation.In this and most examples we use pack_end by choice and practicality. In this part of the code we also make datetime visible.
For our second datetime, we'll also set the size hints weight and align, but in this case, the filds YEAR, MONTH and DATE will be not visible, and thus displaying in our datetime the hour, minute and AM/PM. Finally we choose it's packing method and set the visibility of datetime to true
.
For our third and last datetime, we setted the weight and align as before, chose our packing method and made it visible. Note that in this case we didn't exclude any type of field leaving all visible.
And finally, we set our win's visibility and start the elm mainloop, starting to handle events and drawing operations.
See the full datetime_cxx_example.cc .
This example should look like: