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 = NULL;
14 static Elm_Genlist_Item_Class *_itc_group = NULL;
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_Object_Item *glit = elm_genlist_selected_item_get(list);
111 elm_genlist_item_insert_before(list, _itc,
112 (void *)(long)nitems++, NULL,
113 glit, 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 *glit = elm_genlist_selected_item_get(list);
126 elm_genlist_item_insert_after(list, _itc,
127 (void *)(long)nitems++, NULL,
128 glit, ELM_GENLIST_ITEM_NONE,
134 _next_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
136 Evas_Object *list = data;
137 Elm_Object_Item *glit = elm_genlist_selected_item_get(list);
139 if (glit) glit = elm_genlist_item_next_get(glit);
140 if (!glit) glit = elm_genlist_first_item_get(list);
142 elm_genlist_item_selected_set(glit, EINA_TRUE);
143 elm_genlist_item_show(glit, ELM_GENLIST_ITEM_SCROLLTO_IN);
147 _prev_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
149 Evas_Object *list = data;
150 Elm_Object_Item *glit = elm_genlist_selected_item_get(list);
152 if (glit) glit = elm_genlist_item_prev_get(glit);
153 if (!glit) glit = elm_genlist_last_item_get(list);
155 elm_genlist_item_selected_set(glit, EINA_TRUE);
156 elm_genlist_item_show(glit, ELM_GENLIST_ITEM_SCROLLTO_IN);
160 _bring_in_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
162 Elm_Object_Item *glit = data;
165 elm_genlist_item_bring_in(glit, ELM_GENLIST_ITEM_SCROLLTO_IN);
169 _show_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
171 Elm_Object_Item *glit = data;
174 elm_genlist_item_show(glit, ELM_GENLIST_ITEM_SCROLLTO_IN);
178 _middle_in_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
180 Elm_Object_Item *glit = data;
183 elm_genlist_item_bring_in(glit, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
187 _middle_show_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
189 Elm_Object_Item *glit = data;
192 elm_genlist_item_show(glit, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
196 _top_in_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
198 Elm_Object_Item *glit = data;
201 elm_genlist_item_bring_in(glit, ELM_GENLIST_ITEM_SCROLLTO_TOP);
205 _top_show_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
207 Elm_Object_Item *glit = data;
210 elm_genlist_item_show(glit, ELM_GENLIST_ITEM_SCROLLTO_TOP);
214 _realize_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
216 Evas_Object *list = data;
217 Elm_Object_Item *glit = elm_genlist_selected_item_get(list);
220 elm_genlist_item_update(glit);
224 _button_add(Evas_Object *list, Evas_Object *box, const char *label, Evas_Smart_Cb cb)
228 bt = elm_button_add(elm_object_parent_widget_get(list));
229 elm_object_text_set(bt, label);
230 elm_box_pack_end(box, bt);
231 evas_object_show(bt);
234 evas_object_smart_callback_add(bt, "clicked", cb, list);
240 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
242 Evas_Object *win, *bg, *box, *fbox;
244 Evas_Object *bt_bring_in, *bt_show;
245 Evas_Object *bt_middle_in, *bt_middle_show;
246 Evas_Object *bt_top_in, *bt_top_show;
249 win = elm_win_add(NULL, "icon", ELM_WIN_BASIC);
250 elm_win_title_set(win, "Icon");
251 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
252 elm_win_autodel_set(win, EINA_TRUE);
254 bg = elm_bg_add(win);
255 elm_bg_color_set(bg, 255,255 ,255);
256 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
257 elm_win_resize_object_add(win, bg);
258 evas_object_show(bg);
260 box = elm_box_add(win);
261 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
262 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
263 elm_win_resize_object_add(win, box);
264 evas_object_show(box);
268 _itc = elm_genlist_item_class_new();
269 _itc->item_style = "default";
270 _itc->func.text_get = _item_label_get;
271 _itc->func.content_get = _item_content_get;
272 _itc->func.state_get = NULL;
273 _itc->func.del = NULL;
278 _itc_group = elm_genlist_item_class_new();
279 _itc_group->item_style = "default";
280 _itc_group->func.text_get = _item_label_get;
281 _itc_group->func.content_get = _item_content_get;
282 _itc_group->func.state_get = NULL;
283 _itc_group->func.del = NULL;
286 list = elm_genlist_add(win);
288 evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
289 evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
290 elm_box_pack_end(box, list);
291 evas_object_show(list);
293 fbox = elm_box_add(win);
294 elm_box_layout_set(fbox, evas_object_box_layout_flow_horizontal,
296 evas_object_size_hint_weight_set(fbox, EVAS_HINT_EXPAND, 0);
297 evas_object_size_hint_align_set(fbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
298 elm_box_pack_end(box, fbox);
299 evas_object_show(fbox);
301 _button_add(list, fbox, "prepend", _prepend_cb);
302 _button_add(list, fbox, "append", _append_cb);
303 _button_add(list, fbox, "insert before", _insert_before_cb);
304 _button_add(list, fbox, "insert after", _insert_after_cb);
305 _button_add(list, fbox, "prev", _prev_cb);
306 _button_add(list, fbox, "next", _next_cb);
307 _button_add(list, fbox, "realize", _realize_cb);
308 bt_bring_in = _button_add(list, fbox, "bring #50", NULL);
309 bt_show = _button_add(list, fbox, "show #50", NULL);
310 bt_middle_in = _button_add(list, fbox, "bring to middle #200", NULL);
311 bt_middle_show = _button_add(list, fbox, "show in middle #200", NULL);
312 bt_top_in = _button_add(list, fbox, "bring to top #250", NULL);
313 bt_top_show = _button_add(list, fbox, "show in top #250", NULL);
315 for (i = 0; i < N_ITEMS; i++)
317 Elm_Object_Item *gli, *glg;
321 glg = gli = elm_genlist_item_append(list, _itc_group,
322 (void *)(long)nitems++, NULL,
323 ELM_GENLIST_ITEM_GROUP,
325 elm_genlist_item_select_mode_set(git, ELM_OBJECT_DISPLAY_ONLY_SELECT);
329 gli = elm_genlist_item_append(list, _itc,
330 (void *)(long)nitems++, glg,
331 ELM_GENLIST_ITEM_NONE,
338 elm_object_item_disabled_set(gli, EINA_TRUE);
341 evas_object_smart_callback_add(
342 bt_bring_in, "clicked", _bring_in_cb, gli);
343 evas_object_smart_callback_add(
344 bt_show, "clicked", _show_cb, gli);
347 evas_object_smart_callback_add(
348 bt_middle_in, "clicked", _middle_in_cb, gli);
349 evas_object_smart_callback_add(
350 bt_middle_show, "clicked", _middle_show_cb, gli);
353 evas_object_smart_callback_add(
354 bt_top_in, "clicked", _top_in_cb, gli);
355 evas_object_smart_callback_add(
356 bt_top_show, "clicked", _top_show_cb, gli);
360 evas_object_size_hint_min_set(bg, 160, 160);
361 evas_object_size_hint_max_set(bg, 640, 640);
362 evas_object_resize(win, 420, 320);
363 evas_object_show(win);