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_text_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_text_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_Object_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,
119 _insert_after_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
121 Evas_Object *list = data;
122 Elm_Object_Item *it = elm_genlist_selected_item_get(list);
127 elm_genlist_item_insert_after(list, &_itc,
128 (void *)(long)nitems++, NULL,
129 it, ELM_GENLIST_ITEM_NONE,
134 _next_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
136 Evas_Object *list = data;
139 it = elm_genlist_selected_item_get(list);
141 it = elm_genlist_item_next_get(it);
144 it = elm_genlist_first_item_get(list);
146 elm_genlist_item_selected_set(it, EINA_TRUE);
147 elm_genlist_item_show(it);
151 _prev_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
153 Evas_Object *list = data;
156 it = elm_genlist_selected_item_get(list);
158 it = elm_genlist_item_prev_get(it);
161 it = elm_genlist_last_item_get(list);
163 elm_genlist_item_selected_set(it, EINA_TRUE);
164 elm_genlist_item_show(it);
168 _bring_in_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
170 Elm_Object_Item *it = data;
175 elm_genlist_item_bring_in(it);
179 _show_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
181 Elm_Object_Item *it = data;
186 elm_genlist_item_show(it);
190 _middle_in_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
192 Elm_Object_Item *it = data;
197 elm_genlist_item_middle_bring_in(it);
201 _middle_show_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
203 Elm_Object_Item *it = data;
208 elm_genlist_item_middle_show(it);
212 _top_in_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
214 Elm_Object_Item *it = data;
219 elm_genlist_item_top_bring_in(it);
223 _top_show_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
225 Elm_Object_Item *it = data;
230 elm_genlist_item_top_show(it);
234 _realize_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
236 Evas_Object *list = data;
237 Elm_Object_Item *it = elm_genlist_selected_item_get(list);
242 elm_genlist_item_update(it);
246 _button_add(Evas_Object *list, Evas_Object *box, const char *label, Evas_Smart_Cb cb)
250 bt = elm_button_add(elm_object_parent_widget_get(list));
251 elm_object_text_set(bt, label);
252 elm_box_pack_end(box, bt);
253 evas_object_show(bt);
256 evas_object_smart_callback_add(bt, "clicked", cb, list);
262 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
264 Evas_Object *win, *bg, *box, *fbox;
266 Evas_Object *bt_bring_in, *bt_show;
267 Evas_Object *bt_middle_in, *bt_middle_show;
268 Evas_Object *bt_top_in, *bt_top_show;
271 win = elm_win_add(NULL, "icon", ELM_WIN_BASIC);
272 elm_win_title_set(win, "Icon");
273 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
274 elm_win_autodel_set(win, EINA_TRUE);
276 bg = elm_bg_add(win);
277 elm_bg_color_set(bg, 255,255 ,255);
278 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
279 elm_win_resize_object_add(win, bg);
280 evas_object_show(bg);
282 box = elm_box_add(win);
283 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
284 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
285 elm_win_resize_object_add(win, box);
286 evas_object_show(box);
288 _itc.item_style = "double_label";
289 _itc.func.text_get = _item_text_get;
290 _itc.func.content_get = _item_content_get;
291 _itc.func.state_get = NULL;
292 _itc.func.del = NULL;
294 _itc_group.item_style = "group_index";
295 _itc_group.func.text_get = _group_text_get;
296 _itc_group.func.content_get = _group_content_get;
297 _itc_group.func.state_get = NULL;
298 _itc_group.func.del = NULL;
300 list = elm_genlist_add(win);
302 evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
303 evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
304 elm_box_pack_end(box, list);
305 evas_object_show(list);
307 fbox = elm_box_add(win);
308 elm_box_layout_set(fbox, evas_object_box_layout_flow_horizontal,
310 evas_object_size_hint_weight_set(fbox, EVAS_HINT_EXPAND, 0);
311 evas_object_size_hint_align_set(fbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
312 elm_box_pack_end(box, fbox);
313 evas_object_show(fbox);
315 _button_add(list, fbox, "prepend", _prepend_cb);
316 _button_add(list, fbox, "append", _append_cb);
317 _button_add(list, fbox, "insert before", _insert_before_cb);
318 _button_add(list, fbox, "insert after", _insert_after_cb);
319 _button_add(list, fbox, "prev", _prev_cb);
320 _button_add(list, fbox, "next", _next_cb);
321 _button_add(list, fbox, "realize", _realize_cb);
322 bt_bring_in = _button_add(list, fbox, "bring #50", NULL);
323 bt_show = _button_add(list, fbox, "show #50", NULL);
324 bt_middle_in = _button_add(list, fbox, "bring to middle #200", NULL);
325 bt_middle_show = _button_add(list, fbox, "show in middle #200", NULL);
326 bt_top_in = _button_add(list, fbox, "bring to top #250", NULL);
327 bt_top_show = _button_add(list, fbox, "show in top #250", NULL);
329 for (i = 0; i < N_ITEMS; i++)
331 Elm_Object_Item *gli, *glg;
335 glg = gli = elm_genlist_item_append(list, &_itc_group,
336 (void *)(long)nitems++, NULL,
337 ELM_GENLIST_ITEM_GROUP,
339 elm_genlist_item_display_only_set(glg, EINA_TRUE);
343 gli = elm_genlist_item_append(list, &_itc,
344 (void *)(long)nitems++, glg,
345 ELM_GENLIST_ITEM_NONE,
352 elm_genlist_item_disabled_set(gli, EINA_TRUE);
355 evas_object_smart_callback_add(
356 bt_bring_in, "clicked", _bring_in_cb, gli);
357 evas_object_smart_callback_add(
358 bt_show, "clicked", _show_cb, gli);
361 evas_object_smart_callback_add(
362 bt_middle_in, "clicked", _middle_in_cb, gli);
363 evas_object_smart_callback_add(
364 bt_middle_show, "clicked", _middle_show_cb, gli);
367 evas_object_smart_callback_add(
368 bt_top_in, "clicked", _top_in_cb, gli);
369 evas_object_smart_callback_add(
370 bt_top_show, "clicked", _top_show_cb, gli);
374 evas_object_size_hint_min_set(bg, 160, 160);
375 evas_object_size_hint_max_set(bg, 640, 640);
376 evas_object_resize(win, 420, 320);
377 evas_object_show(win);