summaryrefslogtreecommitdiff
path: root/src/examples/genlist_example_03.c
diff options
context:
space:
mode:
authorRafael Antognolli <antognolli@gmail.com>2011-07-26 18:31:54 +0000
committerRafael Antognolli <antognolli@gmail.com>2011-07-26 18:31:54 +0000
commit60c59da1bb595aa3801c0239ee42827a91cd57cc (patch)
treea335da2f36fc4c81a9dc8631bbd449e84721376f /src/examples/genlist_example_03.c
parent80c5c810e8e926bfb9b05c37825cedcbe246a633 (diff)
elementary/genlist - Add some examples.
SVN revision: 61767
Diffstat (limited to 'src/examples/genlist_example_03.c')
-rw-r--r--src/examples/genlist_example_03.c136
1 files changed, 136 insertions, 0 deletions
diff --git a/src/examples/genlist_example_03.c b/src/examples/genlist_example_03.c
new file mode 100644
index 000000000..db306bbab
--- /dev/null
+++ b/src/examples/genlist_example_03.c
@@ -0,0 +1,136 @@
1//Compile with:
2//gcc -g `pkg-config --cflags --libs elementary` genlist_example_03.c -o genlist_example_03
3
4#include <Elementary.h>
5#ifdef HAVE_CONFIG_H
6# include "elementary_config.h"
7#else
8# define __UNUSED__
9#endif
10
11#define N_ITEMS 30
12
13static Elm_Genlist_Item_Class _itc;
14
15static char *
16_item_label_get(void *data, Evas_Object *obj __UNUSED__, const char *part)
17{
18 time_t t = (time_t)ecore_time_unix_get();
19 char buf[256];
20 int i = (int)(long)data;
21
22 if (!strcmp(part, "elm.text"))
23 snprintf(buf, sizeof(buf), "Item # %i", i);
24 else
25 {
26 int n;
27 snprintf(buf, sizeof(buf), "created at %s", ctime(&t));
28 n = strlen(buf);
29 buf[n - 1] = '\0';
30 }
31
32 return strdup(buf);
33}
34
35static Evas_Object *
36_item_icon_get(void *data __UNUSED__, Evas_Object *obj, const char *part)
37{
38 Evas_Object *ic = elm_icon_add(obj);
39
40 if (!strcmp(part, "elm.swallow.icon"))
41 elm_icon_standard_set(ic, "clock");
42
43 evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
44 return ic;
45}
46
47static void
48_item_sel_cb(void *data, Evas_Object *obj, void *event_info)
49{
50 printf("sel item data [%p] on genlist obj [%p], item pointer [%p]\n",
51 data, obj, event_info);
52}
53
54static Evas_Object *
55_genlist_add(Evas_Object *box)
56{
57 Evas_Object *list = elm_genlist_add(elm_object_parent_widget_get(box));
58 evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
59 evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
60 evas_object_size_hint_min_set(list, 200, 160);
61 elm_box_pack_end(box, list);
62 evas_object_show(list);
63
64 return list;
65}
66
67static void
68_genlist_fill(Evas_Object *list)
69{
70 int i;
71
72 for (i = 0; i < N_ITEMS; i++)
73 {
74 elm_genlist_item_append(list, &_itc,
75 (void *)(long)i, NULL,
76 ELM_GENLIST_ITEM_NONE,
77 _item_sel_cb, NULL);
78 }
79}
80
81int
82elm_main(int argc __UNUSED__, char **argv __UNUSED__)
83{
84 Evas_Object *win, *bg, *box;
85 Evas_Object *list;
86
87 win = elm_win_add(NULL, "icon", ELM_WIN_BASIC);
88 elm_win_title_set(win, "Icon");
89 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
90 elm_win_autodel_set(win, 1);
91
92 bg = elm_bg_add(win);
93 elm_bg_color_set(bg, 255,255 ,255);
94 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
95 elm_win_resize_object_add(win, bg);
96 evas_object_show(bg);
97
98 box = elm_box_add(win);
99 elm_box_horizontal_set(box, EINA_TRUE);
100 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
101 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
102 elm_win_resize_object_add(win, box);
103 evas_object_show(box);
104
105 _itc.item_style = "double_label";
106 _itc.func.label_get = _item_label_get;
107 _itc.func.icon_get = _item_icon_get;
108 _itc.func.state_get = NULL;
109 _itc.func.del = NULL;
110
111 list = _genlist_add(box);
112 _genlist_fill(list);
113
114 list = _genlist_add(box);
115 elm_genlist_horizontal_mode_set(list, ELM_LIST_LIMIT);
116 _genlist_fill(list);
117
118 list = _genlist_add(box);
119 elm_genlist_compress_mode_set(list, EINA_TRUE);
120 _genlist_fill(list);
121
122 list = _genlist_add(box);
123 elm_genlist_height_for_width_mode_set(list, EINA_TRUE);
124 _genlist_fill(list);
125
126 evas_object_size_hint_min_set(bg, 800, 160);
127 evas_object_size_hint_max_set(bg, 800, 640);
128 evas_object_resize(win, 800, 320);
129 evas_object_show(win);
130
131 elm_run();
132
133 return 0;
134}
135
136ELM_MAIN()