Diskselector widget example

This code places 4 Elementary diskselector widgets on a window, each of them exemplifying a part of the widget's API.

All of them will have weekdays as items, since we won't focus on items management on this example. For an example about this subject, check Diskselector - Items management.

The first of them is a default diskselector.

static const char *lbl[] =
{
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};
Evas_Object * elm_diskselector_add(Evas_Object *parent)
Add a new diskselector widget to the given parent Elementary (container) object.
Definition: elm_diskselector.c:1408
for (i = 0; i < sizeof(lbl) / sizeof(lbl[0]); i++)
elm_diskselector_item_append(ds, lbl[i], NULL, NULL, NULL);
#define EVAS_HINT_EXPAND
Use with evas_object_size_hint_weight_set(), evas_object_size_hint_weight_get(), evas_object_size_hin...
Definition: Evas_Common.h:297
#define EVAS_HINT_FILL
Use with evas_object_size_hint_align_set(), evas_object_size_hint_align_get(), evas_object_size_hint_...
Definition: Evas_Common.h:298
void elm_box_pack_end(Elm_Box *obj, Efl_Canvas_Object *subobj)
Add an object at the end of the pack list.
Definition: elm_box_eo.legacy.c:57
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
EVAS_API void evas_object_size_hint_weight_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's weight.
Definition: evas_object_main.c:2638
EVAS_API void evas_object_size_hint_align_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's alignment.
Definition: evas_object_main.c:2650

We are just adding the diskselector, so as you can see, defaults for it are:

  • Only 3 items visible each time.
  • Only 3 characters are displayed for labels on side positions.
  • The first added item remains centered, i.e., it's the selected item.

To add items, we are just appending it on a loop, using function elm_diskselector_item_append(), that will be better explained on items management example.

For a circular diskselector, check the second widget. A circular diskselector will display first item after last, and last previous to the first one. So, as you can see, Sa will appears on left side of selected Sunday. This property is set with elm_diskselector_round_enabled_set().

Also, we decide to display only 2 character for side labels, instead of 3. For this we call elm_diskselector_side_text_max_length_set(). As result, we'll see Mo displayed instead of Mon, when Monday is on a side position.

for (i = 0; i < sizeof(lbl) / sizeof(lbl[0]); i++)
elm_diskselector_item_append(ds, lbl[i], NULL, NULL, NULL);
elm_diskselector_round_enabled_set(ds, EINA_TRUE);
elm_diskselector_side_text_max_length_set(ds, 2);
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:539

But so far, we are only displaying 3 items at once. If more are wanted, is enough to call elm_diskselector_display_item_num_set(), as you can see here:

for (i = 0; i < sizeof(lbl) / sizeof(lbl[0]); i++)
elm_diskselector_item_append(ds, lbl[i], NULL, NULL, NULL);
elm_diskselector_display_item_num_set(ds, 5);
Note
You can't set less than 3 items to be displayed.

You can get the number of items in the diskselector by calling elm_diskselector_display_item_num_get(), as you can see here:

printf("Number of Items in DiskSelector : %d\n", elm_diskselector_display_item_num_get(ds));

Finally, if a bounce effect is required, or you would like to see scrollbars, it is possible. But, for default theme, diskselector scrollbars will be invisible anyway.

for (i = 0; i < sizeof(lbl) / sizeof(lbl[0]); i++)
elm_diskselector_item_append(ds, lbl[i], NULL, NULL, NULL);
void elm_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
Set the scrollbar visibility policy.
Definition: elm_scroller.c:945
@ ELM_SCROLLER_POLICY_ON
Always show scrollbars.
Definition: elm_scroller_legacy.h:16
@ ELM_SCROLLER_POLICY_AUTO
Show scrollbars as needed.
Definition: elm_scroller_legacy.h:15
void elm_scroller_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
Set bouncing behavior.
Definition: elm_scroller.c:1050

See the full diskselector_example_01.c code, whose window should look like this picture: