2 //gcc -g `pkg-config --cflags --libs elementary` genlist_example_01.c -o genlist_example_01
5 #include <Elementary.h>
7 # include "elementary_config.h"
14 static Elm_Genlist_Item_Class *_itc = NULL;
17 _item_label_get(void *data, Evas_Object *obj __UNUSED__, const char *part __UNUSED__)
19 time_t t = (time_t)ecore_time_unix_get();
21 int i = (int)(long)data;
25 snprintf(buf, sizeof(buf), "Very Long Item # %i - realized at %s", i, ctime(&t));
30 snprintf(buf, sizeof(buf), "short item # %i", i);
35 _item_content_get(void *data __UNUSED__, Evas_Object *obj, const char *part)
37 Evas_Object *ic = elm_icon_add(obj);
39 if (!strcmp(part, "elm.swallow.icon"))
40 elm_icon_standard_set(ic, "clock");
42 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
47 _item_sel_cb(void *data, Evas_Object *obj, void *event_info)
49 printf("sel item data [%p] on genlist obj [%p], item pointer [%p]\n",
50 data, obj, event_info);
54 _show_status_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
56 Evas_Object *list = data;
57 Evas_Coord x, y, w, h, mx, my;
58 Elm_Object_Item *glit = elm_genlist_selected_item_get(list);
60 const Eina_List *selected, *l, *realized;
61 printf("\nfirst selected item: %p\n", glit);
63 selected = elm_genlist_selected_items_get(list);
64 printf("all selected items (%d): ", eina_list_count(selected));
65 EINA_LIST_FOREACH(selected, l, glit)
69 realized = elm_genlist_realized_items_get(list);
70 printf("realized items (%d): ", eina_list_count(realized));
71 EINA_LIST_FOREACH(realized, l, glit)
74 printf("genlist mode: %s\n", elm_genlist_mode_type_get(list));
75 printf("mode item: %p\n", elm_genlist_mode_item_get(list));
77 evas_object_geometry_get(list, &x, &y, &w, &h);
80 glit = elm_genlist_at_xy_item_get(list, mx, my, NULL);
81 printf("item in the middle of the screen: %p\n", glit);
85 _realize_cb(void *data, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
87 Evas_Object *list = data;
88 elm_genlist_realized_items_update(list);
92 elm_main(int argc __UNUSED__, char **argv __UNUSED__)
94 Evas_Object *win, *bg, *box, *hbox;
95 Evas_Object *list, *btn;
98 win = elm_win_add(NULL, "genlist", ELM_WIN_BASIC);
99 elm_win_title_set(win, "Genlist - simple");
100 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
101 elm_win_autodel_set(win, EINA_TRUE);
103 bg = elm_bg_add(win);
104 elm_bg_color_set(bg, 255,255 ,255);
105 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
106 elm_win_resize_object_add(win, bg);
107 evas_object_show(bg);
109 box = elm_box_add(win);
110 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
111 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
112 elm_win_resize_object_add(win, box);
113 evas_object_show(box);
115 list = elm_genlist_add(win);
119 _itc = elm_genlist_item_class_new();
120 _itc->item_style = "default";
121 _itc->func.text_get = _item_label_get;
122 _itc->func.content_get = _item_content_get;
123 _itc->func.state_get = NULL;
124 _itc->func.del = NULL;
127 Eina_Bool hbounce, vbounce;
128 Elm_Scroller_Policy hp, vp;
130 printf("default values:\n");
131 printf("always select: %d\n", elm_genlist_always_select_mode_get(list));
132 elm_genlist_bounce_get(list, &hbounce, &vbounce);
133 printf("bounce - horizontal: %d, vertical: %d\n", hbounce, vbounce);
134 printf("compress mode: %d\n", elm_genlist_compress_mode_get(list));
135 printf("homogeneous: %d\n", elm_genlist_homogeneous_get(list));
136 printf("horizontal mode: %d\n", elm_genlist_mode_get(list));
137 printf("longpress timeout: %0.3f\n",
138 elm_genlist_longpress_timeout_get(list));
139 printf("multi selection: %d\n", elm_genlist_multi_select_get(list));
140 printf("no selection mode: %d\n", elm_genlist_no_select_mode_get(list));
141 printf("height for width enabled: %d\n",
142 elm_genlist_height_for_width_mode_get(list));
143 elm_genlist_scroller_policy_get(list, &hp, &vp);
144 printf("scroller policy - horizontal: %d, vertical: %d\n", hp, vp);
145 printf("block count: %d\n", elm_genlist_block_count_get(list));
148 elm_genlist_always_select_mode_set(list, EINA_FALSE);
149 elm_genlist_bounce_set(list, EINA_FALSE, EINA_FALSE);
150 elm_genlist_compress_mode_set(list, EINA_TRUE);
151 elm_genlist_homogeneous_set(list, EINA_FALSE);
152 elm_genlist_mode_set(list, ELM_LIST_LIMIT);
153 elm_genlist_multi_select_set(list, EINA_TRUE);
154 elm_genlist_no_select_mode_set(list, EINA_FALSE);
155 elm_genlist_height_for_width_mode_set(list, EINA_FALSE);
156 elm_genlist_scroller_policy_set(list, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_ON);
157 elm_genlist_longpress_timeout_set(list, 0.5);
158 elm_genlist_block_count_set(list, 16);
160 for (i = 0; i < N_ITEMS; i++)
162 elm_genlist_item_append(list, _itc,
163 (void *)(long)i, NULL,
164 ELM_GENLIST_ITEM_NONE,
168 evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
169 evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
170 elm_box_pack_end(box, list);
171 evas_object_show(list);
173 hbox = elm_box_add(win);
174 elm_box_horizontal_set(hbox, EINA_TRUE);
175 evas_object_size_hint_weight_set(hbox, EVAS_HINT_EXPAND, 0);
176 evas_object_size_hint_align_set(hbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
177 elm_box_pack_end(box, hbox);
178 evas_object_show(hbox);
180 btn = elm_button_add(win);
181 elm_object_text_set(btn, "Show status");
182 evas_object_size_hint_weight_set(btn, 0, 0);
183 evas_object_size_hint_align_set(btn, 0.5, 0.5);
184 evas_object_smart_callback_add(btn, "clicked", _show_status_cb, list);
185 elm_box_pack_end(hbox, btn);
186 evas_object_show(btn);
188 btn = elm_button_add(win);
189 elm_object_text_set(btn, "Realize");
190 evas_object_size_hint_weight_set(btn, 0, 0);
191 evas_object_size_hint_align_set(btn, 0.5, 0.5);
192 evas_object_smart_callback_add(btn, "clicked", _realize_cb, list);
193 elm_box_pack_end(hbox, btn);
194 evas_object_show(btn);
196 evas_object_size_hint_min_set(bg, 160, 160);
197 evas_object_size_hint_max_set(bg, 200, 640);
198 evas_object_resize(win, 200, 320);
199 evas_object_show(win);