List widget example

- Main Page
- Related Pages
- Modules
- Data Structures
- Files
- Examples

List widget example

This code places a single Elementary list widgets on a window, exemplifying a part of the widget's API.

First, we will just create a simple list, as done on List widget example :

static const char *lbl[] =
{
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};
li = elm_list_add(win);
elm_list_add
Evas_Object * elm_list_add(Evas_Object *parent)
Add a new list widget to the given parent Elementary (container) object.
Definition: elm_list.c:2513
evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, li);
for (i = 0; i < sizeof(lbl) / sizeof(lbl[0]); i++)
elm_list_item_append(li, lbl[i], NULL, NULL, NULL, NULL);
EVAS_HINT_EXPAND
#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
elm_list_item_append
Elm_Widget_Item * elm_list_item_append(Elm_List *obj, const char *label, Efl_Canvas_Object *icon, Efl_Canvas_Object *end, Evas_Smart_Cb func, const void *data)
Append a new item to the list object.
Definition: elm_list_eo.legacy.c:129
elm_win_resize_object_add
void elm_win_resize_object_add(Eo *obj, Evas_Object *subobj)
Add subobj as a resize object of window obj.
Definition: efl_ui_win.c:8997
evas_object_size_hint_weight_set
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

Now, let's customize this list a bit. First we will display items horizontally:

elm_list_horizontal_set(li, EINA_TRUE);
EINA_TRUE
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:539
elm_list_horizontal_set
void elm_list_horizontal_set(Elm_List *obj, Eina_Bool horizontal)
Control horizontal mode on the list object.
Definition: elm_list_eo.legacy.c:3

Then we will choose another list mode. There are four of them, and the default Elm_List_Mode is ELM_LIST_SCROLL. Let's set compress mode:

elm_list_mode_set(li, ELM_LIST_COMPRESS);
ELM_LIST_COMPRESS
@ ELM_LIST_COMPRESS
The list won't set any of its size hints to inform how a possible container should resize it.
Definition: elm_general.h:432
elm_list_mode_set
void elm_list_mode_set(Elm_List *obj, Elm_List_Mode mode)
Control which mode to use for the list object.
Definition: elm_list_eo.legacy.c:63

To enable multiple items selection, we need to enable it, since only one selected item is allowed by default:

elm_list_multi_select_set(li, EINA_TRUE);
elm_list_multi_select_set
void elm_list_multi_select_set(Elm_List *obj, Eina_Bool multi)
Control multiple items selection on the list object.
Definition: elm_list_eo.legacy.c:39

We are not adding items with callback functions here, since we'll explain it better on List - Items management. But if the callback need to be called everytime user clicks an item, even if already selected, it's required to enable this behavior:

elm_list_select_mode_set(li, ELM_OBJECT_SELECT_MODE_ALWAYS);
ELM_OBJECT_SELECT_MODE_ALWAYS
@ ELM_OBJECT_SELECT_MODE_ALWAYS
always select mode.
Definition: elm_general.h:39
elm_list_select_mode_set
void elm_list_select_mode_set(Elm_List *obj, Elm_Object_Select_Mode mode)
Control the list select mode.
Definition: elm_list_eo.legacy.c:15

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

elm_scroller_bounce_set(li, EINA_TRUE, EINA_TRUE);
elm_scroller_bounce_set
void elm_scroller_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
Set bouncing behavior.
Definition: elm_scroller.c:1050
elm_scroller_policy_set(li, ELM_SCROLLER_POLICY_AUTO,
ELM_SCROLLER_POLICY_ON);
elm_scroller_policy_set
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
@ ELM_SCROLLER_POLICY_ON
Always show scrollbars.
Definition: elm_scroller_legacy.h:16
ELM_SCROLLER_POLICY_AUTO
@ ELM_SCROLLER_POLICY_AUTO
Show scrollbars as needed.
Definition: elm_scroller_legacy.h:15

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