summaryrefslogtreecommitdiff
path: root/src/examples/index_example_01.c
diff options
context:
space:
mode:
authorDaniel Juyung Seo <seojuyung2@gmail.com>2013-11-20 10:40:02 +0900
committerDaniel Juyung Seo <seojuyung2@gmail.com>2013-11-20 10:46:10 +0900
commita8f359b60d7e2f9c0418a725629d1a70d2c72fbf (patch)
tree0a9d503908cb7af55872172b67a088a29c015d88 /src/examples/index_example_01.c
parent846e4c4cdf440f505a647d5697283716615067a6 (diff)
index_example_01.c: sample code internal refactoring.
- avoid using unnecessary global variable. - use common name for item variable, it. - print out more useful messages on _active_set.
Diffstat (limited to '')
-rw-r--r--src/examples/index_example_01.c102
1 files changed, 40 insertions, 62 deletions
diff --git a/src/examples/index_example_01.c b/src/examples/index_example_01.c
index 332c8dbca..d8627ed6d 100644
--- a/src/examples/index_example_01.c
+++ b/src/examples/index_example_01.c
@@ -12,22 +12,13 @@
12#include <Elementary.h> 12#include <Elementary.h>
13#include <assert.h> 13#include <assert.h>
14 14
15struct example_data
16{
17 Evas_Object *list, *index;
18};
19
20struct example_data d = {NULL, NULL};
21
22static const char *dict[] = \ 15static const char *dict[] = \
23{ 16{
24#include "dict.txt" 17#include "dict.txt"
25}; 18};
26 19
27static void 20static void
28_index_item_del(void *data, 21_index_item_del(void *data, Evas_Object *obj, void *event_info)
29 Evas_Object *obj,
30 void *event_info)
31{ 22{
32 fprintf(stdout, "Deleting index node (%s). Comparing index " 23 fprintf(stdout, "Deleting index node (%s). Comparing index "
33 "item data reported via callback with the one returned by " 24 "item data reported via callback with the one returned by "
@@ -39,55 +30,46 @@ _index_item_del(void *data,
39 30
40/* delete an index item */ 31/* delete an index item */
41static void 32static void
42_item_del(void *data, 33_item_del(void *data, Evas_Object *obj, void *event_info)
43 Evas_Object *obj,
44 void *event_info)
45{ 34{
46 Elm_Object_Item *iit = elm_index_selected_item_get(d.index, 0); 35 Elm_Object_Item *it = elm_index_selected_item_get(data, 0);
47 36
48 if (!iit) return; 37 if (!it) return;
49 38
50 fprintf(stdout, "Deleting last selected index item, which had letter" 39 fprintf(stdout, "Deleting last selected index item, which had letter"
51 " %s (pointing to %p)\n", elm_index_item_letter_get(iit), 40 " %s (pointing to %p)\n", elm_index_item_letter_get(it),
52 elm_object_item_data_get(iit)); 41 elm_object_item_data_get(it));
53 42
54 elm_object_item_del(iit); 43 elm_object_item_del(it);
55 elm_index_level_go(d.index, 0); 44 elm_index_level_go(data, 0);
56} 45}
57 46
58static void 47static void
59_item_del_all(void *data, 48_item_del_all(void *data, Evas_Object *obj, void *event_info)
60 Evas_Object *obj,
61 void *event_info)
62{ 49{
63 elm_index_item_clear(d.index); 50 elm_index_item_clear(data);
64 elm_index_level_go(d.index, 0); 51 elm_index_level_go(data, 0);
65} 52}
66 53
67static void 54static void
68_active_set(void *data, 55_active_set(void *data, Evas_Object *obj, void *event_info)
69 Evas_Object *obj,
70 void *event_info)
71{ 56{
72 elm_index_autohide_disabled_set 57 Eina_Bool disabled = elm_index_autohide_disabled_get(data);
73 (d.index, !elm_index_autohide_disabled_get(d.index)); 58 elm_index_autohide_disabled_set(data, !disabled);
74 59
75 fprintf(stdout, "Toggling index programmatically.\n"); 60 fprintf(stdout, "Toggling index programmatically to %s.\n",
61 !disabled ? "On" : "Off");
76} 62}
77 63
78/* "delay,changed" hook */ 64/* "delay,changed" hook */
79static void 65static void
80_index_changed(void *data, 66_index_changed(void *data, Evas_Object *obj, void *event_info)
81 Evas_Object *obj,
82 void *event_info)
83{ 67{
84 elm_list_item_bring_in(elm_object_item_data_get(event_info)); 68 elm_list_item_bring_in(elm_object_item_data_get(event_info));
85} 69}
86 70
87static void 71static void
88_index_selected(void *data, 72_index_selected(void *data, Evas_Object *obj, void *event_info)
89 Evas_Object *obj,
90 void *event_info)
91{ 73{
92 Elm_Object_Item *lit = event_info; 74 Elm_Object_Item *lit = event_info;
93 75
@@ -98,10 +80,9 @@ _index_selected(void *data,
98} 80}
99 81
100EAPI_MAIN int 82EAPI_MAIN int
101elm_main(int argc, 83elm_main(int argc, char **argv)
102 char **argv)
103{ 84{
104 Evas_Object *win, *hbox, *vbox, *bt, *sep; 85 Evas_Object *win, *hbox, *vbox, *bt, *sep, *list, *id;
105 Elm_Object_Item *lit; 86 Elm_Object_Item *lit;
106 unsigned int i; 87 unsigned int i;
107 char curr = 0; 88 char curr = 0;
@@ -110,28 +91,28 @@ elm_main(int argc,
110 91
111 win = elm_win_util_standard_add("index", "Index Example"); 92 win = elm_win_util_standard_add("index", "Index Example");
112 elm_win_autodel_set(win, EINA_TRUE); 93 elm_win_autodel_set(win, EINA_TRUE);
94 evas_object_resize(win, 320, 600);
95 evas_object_show(win);
113 96
114 vbox = elm_box_add(win); 97 vbox = elm_box_add(win);
115 evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 98 evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
116 elm_win_resize_object_add(win, vbox); 99 elm_win_resize_object_add(win, vbox);
117 evas_object_show(vbox); 100 evas_object_show(vbox);
118 101
119 d.list = elm_list_add(win); 102 list = elm_list_add(win);
120 evas_object_size_hint_weight_set(d.list, EVAS_HINT_EXPAND, 103 evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
121 EVAS_HINT_EXPAND); 104 evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
122 evas_object_size_hint_align_set(d.list, EVAS_HINT_FILL, EVAS_HINT_FILL); 105 evas_object_show(list);
123 evas_object_show(d.list); 106 elm_box_pack_end(vbox, list);
124 elm_box_pack_end(vbox, d.list);
125 107
126 d.index = elm_index_add(win); 108 id = elm_index_add(win);
127 evas_object_size_hint_weight_set(d.index, EVAS_HINT_EXPAND, 109 evas_object_size_hint_weight_set(id, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
128 EVAS_HINT_EXPAND); 110 elm_win_resize_object_add(win, id);
129 elm_win_resize_object_add(win, d.index); 111 evas_object_show(id);
130 evas_object_show(d.index);
131 112
132 for (i = 0; i < (sizeof(dict) / sizeof(dict[0])); i++) 113 for (i = 0; i < (sizeof(dict) / sizeof(dict[0])); i++)
133 { 114 {
134 lit = elm_list_item_append(d.list, dict[i], NULL, NULL, NULL, NULL); 115 lit = elm_list_item_append(list, dict[i], NULL, NULL, NULL, NULL);
135 116
136 if (curr != dict[i][0]) 117 if (curr != dict[i][0])
137 { 118 {
@@ -142,20 +123,20 @@ elm_main(int argc,
142 /* indexing by first letters */ 123 /* indexing by first letters */
143 124
144 snprintf(buf, sizeof(buf), "%c", curr); 125 snprintf(buf, sizeof(buf), "%c", curr);
145 index_it = elm_index_item_append(d.index, buf, NULL, lit); 126 index_it = elm_index_item_append(id, buf, NULL, lit);
146 127
147 /* this is here just to demostrate the API call */ 128 /* this is here just to demostrate the API call */
148 it = elm_index_item_find(d.index, lit); 129 it = elm_index_item_find(id, lit);
149 assert(it == index_it); 130 assert(it == index_it);
150 131
151 elm_object_item_del_cb_set(index_it, _index_item_del); 132 elm_object_item_del_cb_set(index_it, _index_item_del);
152 } 133 }
153 } 134 }
154 135
155 evas_object_smart_callback_add(d.index, "delay,changed", _index_changed, 136 evas_object_smart_callback_add(id, "delay,changed", _index_changed,
156 NULL); 137 NULL);
157 evas_object_smart_callback_add(d.index, "selected", _index_selected, NULL); 138 evas_object_smart_callback_add(id, "selected", _index_selected, NULL);
158 elm_index_level_go(d.index, 0); 139 elm_index_level_go(id, 0);
159 140
160 /* attribute setting knobs */ 141 /* attribute setting knobs */
161 sep = elm_separator_add(win); 142 sep = elm_separator_add(win);
@@ -172,25 +153,22 @@ elm_main(int argc,
172 153
173 bt = elm_button_add(win); 154 bt = elm_button_add(win);
174 elm_object_text_set(bt, "bring in index"); 155 elm_object_text_set(bt, "bring in index");
175 evas_object_smart_callback_add(bt, "clicked", _active_set, NULL); 156 evas_object_smart_callback_add(bt, "clicked", _active_set, id);
176 elm_box_pack_end(hbox, bt); 157 elm_box_pack_end(hbox, bt);
177 evas_object_show(bt); 158 evas_object_show(bt);
178 159
179 bt = elm_button_add(win); 160 bt = elm_button_add(win);
180 elm_object_text_set(bt, "delete last selected item"); 161 elm_object_text_set(bt, "delete last selected item");
181 evas_object_smart_callback_add(bt, "clicked", _item_del, NULL); 162 evas_object_smart_callback_add(bt, "clicked", _item_del, id);
182 elm_box_pack_end(hbox, bt); 163 elm_box_pack_end(hbox, bt);
183 evas_object_show(bt); 164 evas_object_show(bt);
184 165
185 bt = elm_button_add(win); 166 bt = elm_button_add(win);
186 elm_object_text_set(bt, "delete all items"); 167 elm_object_text_set(bt, "delete all items");
187 evas_object_smart_callback_add(bt, "clicked", _item_del_all, NULL); 168 evas_object_smart_callback_add(bt, "clicked", _item_del_all, id);
188 elm_box_pack_end(hbox, bt); 169 elm_box_pack_end(hbox, bt);
189 evas_object_show(bt); 170 evas_object_show(bt);
190 171
191 evas_object_resize(win, 320, 600);
192 evas_object_show(win);
193
194 elm_run(); 172 elm_run();
195 elm_shutdown(); 173 elm_shutdown();
196 174