diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/elementary/src/examples/index_example_02.c | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/libraries/elementary/src/examples/index_example_02.c b/libraries/elementary/src/examples/index_example_02.c new file mode 100644 index 0000000..ff2acde --- /dev/null +++ b/libraries/elementary/src/examples/index_example_02.c | |||
@@ -0,0 +1,152 @@ | |||
1 | /** | ||
2 | * Simple Elementary's <b>index widget</b> example, illustrating its | ||
3 | * usage and API -- now with sorted insertions. | ||
4 | * | ||
5 | * See stdout/stderr for output. Compile with: | ||
6 | * | ||
7 | * @verbatim | ||
8 | * gcc -g index_example.c -o index_example `pkg-config --cflags --libs elementary` | ||
9 | * @endverbatim | ||
10 | */ | ||
11 | |||
12 | #include <Elementary.h> | ||
13 | |||
14 | static const char *items[] = \ | ||
15 | { | ||
16 | "Judith", | ||
17 | "Paulina", | ||
18 | "Cathy", | ||
19 | "Vendella", | ||
20 | "Naomi", | ||
21 | "Ashley", | ||
22 | "Stacey", | ||
23 | "Gail" | ||
24 | }; | ||
25 | |||
26 | static void | ||
27 | _index_changed(void *data, | ||
28 | Evas_Object *obj, | ||
29 | void *event_info) | ||
30 | { | ||
31 | Elm_Object_Item *item = elm_object_item_data_get(event_info); | ||
32 | elm_gengrid_item_bring_in(item, ELM_GENGRID_ITEM_SCROLLTO_IN); | ||
33 | } | ||
34 | |||
35 | static void | ||
36 | _on_done(void *data, | ||
37 | Evas_Object *obj, | ||
38 | void *event_info) | ||
39 | { | ||
40 | elm_exit(); | ||
41 | } | ||
42 | |||
43 | static char * | ||
44 | _grid_label_get(void *data, | ||
45 | Evas_Object *obj, | ||
46 | const char *part) | ||
47 | { | ||
48 | int idx = (int)data; | ||
49 | return strdup(items[idx]); | ||
50 | } | ||
51 | |||
52 | Evas_Object * | ||
53 | _grid_content_get(void *data, | ||
54 | Evas_Object *obj, | ||
55 | const char *part) | ||
56 | { | ||
57 | if (!strcmp(part, "elm.swallow.icon")) | ||
58 | { | ||
59 | char buf[PATH_MAX]; | ||
60 | snprintf(buf, sizeof(buf), "%s/images/%s", elm_app_data_dir_get(), | ||
61 | "sky_01.jpg"); | ||
62 | |||
63 | Evas_Object *icon = elm_bg_add(obj); | ||
64 | elm_bg_file_set(icon, buf, NULL); | ||
65 | evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, | ||
66 | 1); | ||
67 | evas_object_show(icon); | ||
68 | return icon; | ||
69 | } | ||
70 | |||
71 | return NULL; | ||
72 | } | ||
73 | |||
74 | /* ordering alphabetically */ | ||
75 | static int | ||
76 | _index_icmp(const void *data1, | ||
77 | const void *data2) | ||
78 | { | ||
79 | const char *label1, *label2; | ||
80 | |||
81 | const Elm_Object_Item *index_it1 = data1; | ||
82 | const Elm_Object_Item *index_it2 = data2; | ||
83 | |||
84 | label1 = elm_index_item_letter_get(index_it1); | ||
85 | label2 = elm_index_item_letter_get(index_it2); | ||
86 | |||
87 | return strcasecmp(label1, label2); | ||
88 | } | ||
89 | |||
90 | EAPI_MAIN int | ||
91 | elm_main(int argc, | ||
92 | char **argv) | ||
93 | { | ||
94 | Evas_Object *win, *bg, *grid, *idx; | ||
95 | Elm_Object_Item *gg_it; | ||
96 | unsigned int i; | ||
97 | |||
98 | Elm_Gengrid_Item_Class gic; | ||
99 | |||
100 | elm_app_info_set(elm_main, "elementary", "images"); | ||
101 | win = elm_win_add(NULL, "index", ELM_WIN_BASIC); | ||
102 | elm_win_title_set(win, "Index Example"); | ||
103 | evas_object_smart_callback_add(win, "delete,request", _on_done, NULL); | ||
104 | |||
105 | bg = elm_bg_add(win); | ||
106 | elm_win_resize_object_add(win, bg); | ||
107 | evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
108 | evas_object_show(bg); | ||
109 | |||
110 | grid = elm_gengrid_add(win); | ||
111 | elm_gengrid_item_size_set(grid, 150, 150); | ||
112 | |||
113 | gic.item_style = "default"; | ||
114 | gic.func.text_get = _grid_label_get; | ||
115 | gic.func.content_get = _grid_content_get; | ||
116 | gic.func.state_get = NULL; | ||
117 | gic.func.del = NULL; | ||
118 | |||
119 | evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
120 | elm_win_resize_object_add(win, grid); | ||
121 | evas_object_show(grid); | ||
122 | |||
123 | idx = elm_index_add(win); | ||
124 | evas_object_size_hint_weight_set(idx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); | ||
125 | elm_win_resize_object_add(win, idx); | ||
126 | |||
127 | evas_object_show(idx); | ||
128 | |||
129 | for (i = 0; i < (sizeof(items) / sizeof(items[0])); i++) | ||
130 | { | ||
131 | char buf[32]; | ||
132 | |||
133 | gg_it = elm_gengrid_item_append(grid, &gic, (void *)i, NULL, NULL); | ||
134 | |||
135 | /* indexing by first letters */ | ||
136 | snprintf(buf, sizeof(buf), "%c", items[i][0]); | ||
137 | elm_index_item_sorted_insert(idx, buf, NULL, gg_it, _index_icmp, NULL); | ||
138 | } | ||
139 | |||
140 | evas_object_smart_callback_add(idx, "delay,changed", _index_changed, NULL); | ||
141 | |||
142 | evas_object_resize(win, 320, 300); | ||
143 | evas_object_show(win); | ||
144 | |||
145 | elm_index_autohide_disabled_set(idx, EINA_FALSE); | ||
146 | |||
147 | elm_run(); | ||
148 | elm_shutdown(); | ||
149 | |||
150 | return 0; | ||
151 | } | ||
152 | ELM_MAIN() | ||