2 //gcc -g `pkg-config --cflags --libs elementary` genlist_example_04.c -o genlist_example_04
4 #include <Elementary.h>
6 # include "elementary_config.h"
13 static Elm_Genlist_Item_Class _itc;
14 static Elm_Genlist_Item_Class _itc_group;
15 static int nitems = 0;
18 _item_label_get(void *data, Evas_Object *obj __UNUSED__, const char *part)
20 time_t t = (time_t)ecore_time_unix_get();
22 int i = (int)(long)data;
24 if (!strcmp(part, "elm.text"))
25 snprintf(buf, sizeof(buf), "Item # %i", i);
29 snprintf(buf, sizeof(buf), "realized at %s", ctime(&t));
38 _item_content_get(void *data __UNUSED__, Evas_Object *obj, const char *part)
40 Evas_Object *ic = elm_icon_add(obj);
42 if (!strcmp(part, "elm.swallow.icon"))
43 elm_icon_standard_set(ic, "clock");
45 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
50 _item_sel_cb(void *data, Evas_Object *obj, void *event_info)
52 printf("sel item data [%p] on genlist obj [%p], item pointer [%p]\n",
53 data, obj, event_info);
57 _group_label_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
60 int i = (int)(long)data;
62 snprintf(buf, sizeof(buf), "Group %d (item #%d)", i / 7, i);
68 _group_content_get(void *data __UNUSED__, Evas_Object *obj, const char *part __UNUSED__)
70 Evas_Object *ic = elm_icon_add(obj);
72 if (!strcmp(part, "elm.swallow.icon"))
73 elm_icon_standard_set(ic, "home");
75 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
80 _append_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
82 Evas_Object *list = data;
84 elm_genlist_item_append(list, &_itc,
85 (void *)(long)nitems++, NULL,
86 ELM_GENLIST_ITEM_NONE,
92 _prepend_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
94 Evas_Object *list = data;
96 elm_genlist_item_prepend(list, &_itc,
97 (void *)(long)nitems++, NULL,
98 ELM_GENLIST_ITEM_NONE,
104 _insert_before_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
106 Evas_Object *list = data;
107 Elm_Genlist_Item *it = elm_genlist_selected_item_get(list);
112 elm_genlist_item_insert_before(list, &_itc,
113 (void *)(long)nitems++, NULL,
114 it, ELM_GENLIST_ITEM_NONE,
120 _insert_after_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
122 Evas_Object *list = data;
123 Elm_Genlist_Item *it = elm_genlist_selected_item_get(list);
128 elm_genlist_item_insert_after(list, &_itc,
129 (void *)(long)nitems++, NULL,
130 it, ELM_GENLIST_ITEM_NONE,
136 _next_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
138 Evas_Object *list = data;
139 Elm_Genlist_Item *it;
141 it = elm_genlist_selected_item_get(list);
143 it = elm_genlist_item_next_get(it);
146 it = elm_genlist_first_item_get(list);
148 elm_genlist_item_selected_set(it, EINA_TRUE);
149 elm_genlist_item_show(it);
153 _prev_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
155 Evas_Object *list = data;
156 Elm_Genlist_Item *it;
158 it = elm_genlist_selected_item_get(list);
160 it = elm_genlist_item_prev_get(it);
163 it = elm_genlist_last_item_get(list);
165 elm_genlist_item_selected_set(it, EINA_TRUE);
166 elm_genlist_item_show(it);
170 _bring_in_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
172 Elm_Genlist_Item *it = data;
177 elm_genlist_item_bring_in(it);
181 _show_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
183 Elm_Genlist_Item *it = data;
188 elm_genlist_item_show(it);
192 _middle_in_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
194 Elm_Genlist_Item *it = data;
199 elm_genlist_item_middle_bring_in(it);
203 _middle_show_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
205 Elm_Genlist_Item *it = data;
210 elm_genlist_item_middle_show(it);
214 _top_in_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
216 Elm_Genlist_Item *it = data;
221 elm_genlist_item_top_bring_in(it);
225 _top_show_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
227 Elm_Genlist_Item *it = data;
232 elm_genlist_item_top_show(it);
236 _realize_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
238 Evas_Object *list = data;
239 Elm_Genlist_Item *it = elm_genlist_selected_item_get(list);
244 elm_genlist_item_update(it);
248 _button_add(Evas_Object *list, Evas_Object *box, const char *label, Evas_Smart_Cb cb)
252 bt = elm_button_add(elm_object_parent_widget_get(list));
253 elm_object_text_set(bt, label);
254 elm_box_pack_end(box, bt);
255 evas_object_show(bt);
258 evas_object_smart_callback_add(bt, "clicked", cb, list);
264 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
266 Evas_Object *win, *bg, *box, *fbox;
268 Evas_Object *bt_bring_in, *bt_show;
269 Evas_Object *bt_middle_in, *bt_middle_show;
270 Evas_Object *bt_top_in, *bt_top_show;
273 win = elm_win_add(NULL, "icon", ELM_WIN_BASIC);
274 elm_win_title_set(win, "Icon");
275 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
276 elm_win_autodel_set(win, EINA_TRUE);
278 bg = elm_bg_add(win);
279 elm_bg_color_set(bg, 255,255 ,255);
280 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
281 elm_win_resize_object_add(win, bg);
282 evas_object_show(bg);
284 box = elm_box_add(win);
285 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
286 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
287 elm_win_resize_object_add(win, box);
288 evas_object_show(box);
290 _itc.item_style = "double_label";
291 _itc.func.label_get = _item_label_get;
292 _itc.func.content_get = _item_content_get;
293 _itc.func.state_get = NULL;
294 _itc.func.del = NULL;
296 _itc_group.item_style = "group_index";
297 _itc_group.func.label_get = _group_label_get;
298 _itc_group.func.content_get = _group_content_get;
299 _itc_group.func.state_get = NULL;
300 _itc_group.func.del = NULL;
302 list = elm_genlist_add(win);
304 evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
305 evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
306 elm_box_pack_end(box, list);
307 evas_object_show(list);
309 fbox = elm_box_add(win);
310 elm_box_layout_set(fbox, evas_object_box_layout_flow_horizontal,
312 evas_object_size_hint_weight_set(fbox, EVAS_HINT_EXPAND, 0);
313 evas_object_size_hint_align_set(fbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
314 elm_box_pack_end(box, fbox);
315 evas_object_show(fbox);
317 _button_add(list, fbox, "prepend", _prepend_cb);
318 _button_add(list, fbox, "append", _append_cb);
319 _button_add(list, fbox, "insert before", _insert_before_cb);
320 _button_add(list, fbox, "insert after", _insert_after_cb);
321 _button_add(list, fbox, "prev", _prev_cb);
322 _button_add(list, fbox, "next", _next_cb);
323 _button_add(list, fbox, "realize", _realize_cb);
324 bt_bring_in = _button_add(list, fbox, "bring #50", NULL);
325 bt_show = _button_add(list, fbox, "show #50", NULL);
326 bt_middle_in = _button_add(list, fbox, "bring to middle #200", NULL);
327 bt_middle_show = _button_add(list, fbox, "show in middle #200", NULL);
328 bt_top_in = _button_add(list, fbox, "bring to top #250", NULL);
329 bt_top_show = _button_add(list, fbox, "show in top #250", NULL);
331 for (i = 0; i < N_ITEMS; i++)
333 Elm_Genlist_Item *gli, *glg;
337 glg = gli = elm_genlist_item_append(list, &_itc_group,
338 (void *)(long)nitems++, NULL,
339 ELM_GENLIST_ITEM_GROUP,
341 elm_genlist_item_display_only_set(glg, EINA_TRUE);
345 gli = elm_genlist_item_append(list, &_itc,
346 (void *)(long)nitems++, glg,
347 ELM_GENLIST_ITEM_NONE,
354 elm_genlist_item_disabled_set(gli, EINA_TRUE);
357 evas_object_smart_callback_add(
358 bt_bring_in, "clicked", _bring_in_cb, gli);
359 evas_object_smart_callback_add(
360 bt_show, "clicked", _show_cb, gli);
363 evas_object_smart_callback_add(
364 bt_middle_in, "clicked", _middle_in_cb, gli);
365 evas_object_smart_callback_add(
366 bt_middle_show, "clicked", _middle_show_cb, gli);
369 evas_object_smart_callback_add(
370 bt_top_in, "clicked", _top_in_cb, gli);
371 evas_object_smart_callback_add(
372 bt_top_show, "clicked", _top_show_cb, gli);
376 evas_object_size_hint_min_set(bg, 160, 160);
377 evas_object_size_hint_max_set(bg, 640, 640);
378 evas_object_resize(win, 420, 320);
379 evas_object_show(win);