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_size_hint_weight_set(ds, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(ds, EVAS_HINT_FILL, EVAS_HINT_FILL);
for (i = 0; i < sizeof(lbl) / sizeof(lbl[0]); i++)
elm_diskselector_item_append(ds, lbl[i], NULL, NULL, NULL);
evas_object_show(ds);

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

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.

evas_object_size_hint_weight_set(ds, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(ds, EVAS_HINT_FILL, EVAS_HINT_FILL);
for (i = 0; i < sizeof(lbl) / sizeof(lbl[0]); i++)
elm_diskselector_item_append(ds, lbl[i], NULL, NULL, NULL);
evas_object_show(ds);

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:

evas_object_size_hint_weight_set(ds, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(ds, EVAS_HINT_FILL, EVAS_HINT_FILL);
for (i = 0; i < sizeof(lbl) / sizeof(lbl[0]); i++)
elm_diskselector_item_append(ds, lbl[i], NULL, NULL, NULL);

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.

evas_object_size_hint_weight_set(ds, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(ds, EVAS_HINT_FILL, EVAS_HINT_FILL);
for (i = 0; i < sizeof(lbl) / sizeof(lbl[0]); i++)
elm_diskselector_item_append(ds, lbl[i], NULL, NULL, NULL);
elm_scroller_bounce_set(ds, EINA_TRUE, EINA_TRUE);
elm_scroller_policy_set(ds, ELM_SCROLLER_POLICY_AUTO,
evas_object_show(ds);

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

diskselector_example_01.png