2 * Elementary's <b>list widget</b> example, illustrating its API,
3 * covering most of item functions.
5 * See stdout/stderr for output. Compile with:
8 * gcc -g `pkg-config --cflags --libs elementary` list_example_03.c -o list_example_03
12 #include <Elementary.h>
14 # include "elementary_config.h"
19 static int counter = 3;
22 _on_done(void *data __UNUSED__,
23 Evas_Object *obj __UNUSED__,
24 void *event_info __UNUSED__)
30 _prepend_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
32 Elm_Object_Item *list_it;
33 Evas_Object *li = data;
36 snprintf(label, sizeof(label), "Item %i", counter++);
37 list_it = elm_list_item_prepend(li, label, NULL, NULL, NULL, NULL);
39 printf("Error adding item\n");
43 _add_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
45 Elm_Object_Item *list_it;
46 Evas_Object *li = data;
49 snprintf(label, sizeof(label), "Item %i", counter++);
50 list_it = elm_list_item_append(li, label, NULL, NULL, NULL, NULL);
52 printf("Error adding item\n");
56 _add_ic_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
58 Elm_Object_Item *list_it;
59 Evas_Object *ic, *li = data;
62 snprintf(label, sizeof(label), "Item %i", counter++);
63 ic = elm_icon_add(li);
64 elm_icon_standard_set(ic, "home");
65 elm_icon_resizable_set(ic, EINA_FALSE, EINA_FALSE);
67 list_it = elm_list_item_append(li, label, ic, NULL, NULL, NULL);
69 printf("Error adding item with icon\n");
73 _sel_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
75 Elm_Object_Item *list_it = event_info;
76 printf("Selected label: %s\n", elm_object_item_text_get(list_it));
80 _add_func_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
82 Elm_Object_Item *list_it;
83 Evas_Object *li = data;
86 snprintf(label, sizeof(label), "Item %i", counter++);
87 list_it = elm_list_item_append(li, label, NULL, NULL, _sel_cb, NULL);
89 printf("Error adding item\n");
93 _sel_data_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info)
96 Elm_Object_Item *list_it = event_info;
97 printf("Selected label: %s with data: %s\n",
98 elm_object_item_text_get(list_it), content);
102 _free_data(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
108 _add_data_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
110 Elm_Object_Item *list_it;
111 Evas_Object *li = data;
113 char *content = malloc(sizeof(char) * 32);
115 snprintf(content, 32, "Item content %i", counter);
116 snprintf(label, sizeof(label), "Item %i", counter++);
117 list_it = elm_list_item_append(li, label, NULL, NULL, _sel_data_cb, content);
119 printf("Error adding item\n");
122 elm_object_item_del_cb_set(list_it, _free_data);
126 _del_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
128 Elm_Object_Item *selected_item;
129 Evas_Object *li = data;
131 selected_item = elm_list_selected_item_get(li);
132 elm_object_item_del(selected_item);
136 _unselect_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
138 Elm_Object_Item *selected_item;
139 Evas_Object *li = data;
141 selected_item = elm_list_selected_item_get(li);
142 elm_list_item_selected_set(selected_item, EINA_FALSE);
146 _print_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
148 const Eina_List *l, *items;
149 Elm_Object_Item *list_it;
150 Evas_Object *li = data;
152 items = elm_list_items_get(li);
153 EINA_LIST_FOREACH(items, l, list_it)
154 printf("%s\n", elm_object_item_text_get(list_it));
158 _clear_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
160 Evas_Object *li = data;
165 _select_next_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
167 Elm_Object_Item *selected_item, *next_item;
168 Evas_Object *li = data;
170 selected_item = elm_list_selected_item_get(li);
171 if (!selected_item) return;
173 next_item = elm_list_item_next(selected_item);
175 elm_list_item_selected_set(next_item, EINA_TRUE);
179 _insert_after_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
181 Elm_Object_Item *selected_item, *list_it;
182 Evas_Object *li = data;
185 selected_item = elm_list_selected_item_get(li);
186 if (!selected_item) return;
188 snprintf(label, sizeof(label), "Item %i", counter++);
189 list_it = elm_list_item_insert_after(li, selected_item, label, NULL, NULL,
192 printf("Error adding item\n");
196 _select_prev_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
198 Elm_Object_Item *selected_item, *prev_item;
199 Evas_Object *li = data;
201 selected_item = elm_list_selected_item_get(li);
202 if (!selected_item) return;
204 prev_item = elm_list_item_prev(selected_item);
206 elm_list_item_selected_set(prev_item, EINA_TRUE);
210 _insert_before_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
212 Elm_Object_Item *selected_item, *list_it;
213 Evas_Object *li = data;
216 selected_item = elm_list_selected_item_get(li);
217 if (!selected_item) return;
219 snprintf(label, sizeof(label), "Item %i", counter++);
220 list_it = elm_list_item_insert_before(li, selected_item, label, NULL, NULL,
223 printf("Error adding item\n");
227 _set_separator_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
229 Elm_Object_Item *selected_item;
230 Evas_Object *li = data;
232 selected_item = elm_list_selected_item_get(li);
233 if (!selected_item) return;
234 elm_list_item_separator_set(selected_item, EINA_TRUE);
238 _disable_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
240 Elm_Object_Item *selected_item;
241 Evas_Object *li = data;
243 selected_item = elm_list_selected_item_get(li);
244 if (!selected_item) return;
245 elm_list_item_disabled_set(selected_item, EINA_TRUE);
249 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
251 Evas_Object *win, *bg, *bx, *hbx, *li, *bt;
253 win = elm_win_add(NULL, "list", ELM_WIN_BASIC);
254 elm_win_title_set(win, "List Items Example");
255 evas_object_smart_callback_add(win, "delete,request", _on_done, NULL);
257 bg = elm_bg_add(win);
258 elm_win_resize_object_add(win, bg);
259 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
260 evas_object_show(bg);
262 bx = elm_box_add(win);
263 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
264 elm_win_resize_object_add(win, bx);
265 evas_object_show(bx);
267 li = elm_list_add(win);
268 evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
269 evas_object_size_hint_align_set(li, EVAS_HINT_FILL, EVAS_HINT_FILL);
270 elm_box_pack_end(bx, li);
272 elm_list_item_append(li, "Item 0", NULL, NULL, NULL, NULL);
273 elm_list_item_append(li, "Item 1", NULL, NULL, NULL, NULL);
274 elm_list_item_append(li, "Item 2", NULL, NULL, NULL, NULL);
276 hbx = elm_box_add(win);
277 elm_box_horizontal_set(hbx, EINA_TRUE);
278 evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, 0);
279 evas_object_size_hint_align_set(hbx, EVAS_HINT_FILL, 0);
280 elm_box_pack_end(bx, hbx);
281 evas_object_show(hbx);
283 bt = elm_button_add(win);
284 elm_object_text_set(bt, "Prepend item");
285 evas_object_smart_callback_add(bt, "clicked", _prepend_cb, li);
286 elm_box_pack_end(hbx, bt);
287 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
288 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
289 evas_object_show(bt);
291 bt = elm_button_add(win);
292 elm_object_text_set(bt, "Append item");
293 evas_object_smart_callback_add(bt, "clicked", _add_cb, li);
294 elm_box_pack_end(hbx, bt);
295 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
296 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
297 evas_object_show(bt);
299 hbx = elm_box_add(win);
300 elm_box_horizontal_set(hbx, EINA_TRUE);
301 evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, 0);
302 evas_object_size_hint_align_set(hbx, EVAS_HINT_FILL, 0);
303 elm_box_pack_end(bx, hbx);
304 evas_object_show(hbx);
306 bt = elm_button_add(win);
307 elm_object_text_set(bt, "Append with icon");
308 evas_object_smart_callback_add(bt, "clicked", _add_ic_cb, li);
309 elm_box_pack_end(hbx, bt);
310 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
311 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
312 evas_object_show(bt);
314 bt = elm_button_add(win);
315 elm_object_text_set(bt, "Append with selected function");
316 evas_object_smart_callback_add(bt, "clicked", _add_func_cb, li);
317 elm_box_pack_end(hbx, bt);
318 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
319 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
320 evas_object_show(bt);
322 bt = elm_button_add(win);
323 elm_object_text_set(bt, "Append with data");
324 evas_object_smart_callback_add(bt, "clicked", _add_data_cb, li);
325 elm_box_pack_end(hbx, bt);
326 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
327 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
328 evas_object_show(bt);
330 hbx = elm_box_add(win);
331 elm_box_horizontal_set(hbx, EINA_TRUE);
332 evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, 0);
333 evas_object_size_hint_align_set(hbx, EVAS_HINT_FILL, 0);
334 elm_box_pack_end(bx, hbx);
335 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
336 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
337 evas_object_show(hbx);
339 bt = elm_button_add(win);
340 elm_object_text_set(bt, "Delete item");
341 evas_object_smart_callback_add(bt, "clicked", _del_cb, li);
342 elm_box_pack_end(hbx, bt);
343 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
344 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
345 evas_object_show(bt);
347 bt = elm_button_add(win);
348 elm_object_text_set(bt, "Unselect item");
349 evas_object_smart_callback_add(bt, "clicked", _unselect_cb, li);
350 elm_box_pack_end(hbx, bt);
351 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
352 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
353 evas_object_show(bt);
355 bt = elm_button_add(win);
356 elm_object_text_set(bt, "Print items");
357 evas_object_smart_callback_add(bt, "clicked", _print_cb, li);
358 elm_box_pack_end(hbx, bt);
359 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
360 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
361 evas_object_show(bt);
363 bt = elm_button_add(win);
364 elm_object_text_set(bt, "Clear");
365 evas_object_smart_callback_add(bt, "clicked", _clear_cb, li);
366 elm_box_pack_end(hbx, bt);
367 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
368 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
369 evas_object_show(bt);
371 hbx = elm_box_add(win);
372 elm_box_horizontal_set(hbx, EINA_TRUE);
373 evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, 0);
374 evas_object_size_hint_align_set(hbx, EVAS_HINT_FILL, 0);
375 elm_box_pack_end(bx, hbx);
376 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
377 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
378 evas_object_show(hbx);
380 bt = elm_button_add(win);
381 elm_object_text_set(bt, "Select next item");
382 evas_object_smart_callback_add(bt, "clicked", _select_next_cb, li);
383 elm_box_pack_end(hbx, bt);
384 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
385 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
386 evas_object_show(bt);
388 bt = elm_button_add(win);
389 elm_object_text_set(bt, "Insert after item");
390 evas_object_smart_callback_add(bt, "clicked", _insert_after_cb, li);
391 elm_box_pack_end(hbx, bt);
392 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
393 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
394 evas_object_show(bt);
396 bt = elm_button_add(win);
397 elm_object_text_set(bt, "Select previous item");
398 evas_object_smart_callback_add(bt, "clicked", _select_prev_cb, li);
399 elm_box_pack_end(hbx, bt);
400 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
401 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
402 evas_object_show(bt);
404 bt = elm_button_add(win);
405 elm_object_text_set(bt, "Insert before item");
406 evas_object_smart_callback_add(bt, "clicked", _insert_before_cb, li);
407 elm_box_pack_end(hbx, bt);
408 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
409 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
410 evas_object_show(bt);
412 hbx = elm_box_add(win);
413 elm_box_horizontal_set(hbx, EINA_TRUE);
414 evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, 0);
415 evas_object_size_hint_align_set(hbx, EVAS_HINT_FILL, 0);
416 elm_box_pack_end(bx, hbx);
417 evas_object_show(hbx);
419 bt = elm_button_add(win);
420 elm_object_text_set(bt, "Set as separator");
421 evas_object_smart_callback_add(bt, "clicked", _set_separator_cb, li);
422 elm_box_pack_end(hbx, bt);
423 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
424 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
425 evas_object_show(bt);
427 bt = elm_button_add(win);
428 elm_object_text_set(bt, "Disable item");
429 evas_object_smart_callback_add(bt, "clicked", _disable_cb, li);
430 elm_box_pack_end(hbx, bt);
431 evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0);
432 evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, 0);
433 evas_object_show(bt);
436 evas_object_show(li);
438 evas_object_resize(win, 320, 600);
439 evas_object_show(win);