elm_widget - reverted focus logic
[framework/uifw/elementary.git] / src / bin / test_button.c
1 #include <Elementary.h>
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #endif
5 #ifndef ELM_LIB_QUICKLAUNCH
6 static void
7 _bt_repeated(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
8 {
9    static int count;
10    char buf[16];
11
12    snprintf(buf, sizeof(buf), "count=%d", count++);
13    if (count >= 10000)
14      count = 0;
15    elm_object_text_set(obj, buf);
16 }
17
18 static void
19 _bt_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
20 {
21    int param = (int)(data);
22
23    printf("clicked event on Button:%d\n", param);
24 }
25
26 static void
27 _bt_unpressed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
28 {
29    int param = (int)(data);
30
31    printf("unpressed event on Button:%d\n", param);
32 }
33
34 void
35 test_button(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
36 {
37    Evas_Object *win, *bg, *scr, *bx, *ic, *bt;
38    char buf[PATH_MAX];
39
40    win = elm_win_add(NULL, "buttons", ELM_WIN_BASIC);
41    elm_win_title_set(win, "Buttons");
42    elm_win_autodel_set(win, 1);
43
44    bg = elm_bg_add(win);
45    elm_win_resize_object_add(win, bg);
46    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
47    evas_object_show(bg);
48
49    scr = elm_scroller_add(win);
50    elm_scroller_bounce_set(scr, EINA_FALSE, EINA_TRUE);
51    elm_scroller_policy_set(scr, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
52    elm_win_resize_object_add(win, scr);
53    evas_object_show(scr);
54    evas_object_size_hint_weight_set(scr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
55
56    bx = elm_box_add(win);
57    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
58    elm_scroller_content_set(scr, bx);
59    evas_object_show(bx);
60
61    ic = elm_icon_add(win);
62    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR);
63    elm_icon_file_set(ic, buf, NULL);
64    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
65    bt = elm_button_add(win);
66    elm_object_text_set(bt, "Icon sized to button");
67    elm_button_icon_set(bt, ic);
68    evas_object_smart_callback_add(bt, "clicked", _bt_clicked, (void *)1);
69    evas_object_smart_callback_add(bt, "unpressed", _bt_unpressed, (void *)1);
70    elm_box_pack_end(bx, bt);
71    evas_object_show(bt);
72    evas_object_show(ic);
73
74    ic = elm_icon_add(bx);
75    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR);
76    elm_icon_file_set(ic, buf, NULL);
77    elm_icon_scale_set(ic, 0, 0);
78    bt = elm_button_add(win);
79    elm_object_text_set(bt, "Icon no scale");
80    elm_button_icon_set(bt, ic);
81    evas_object_smart_callback_add(bt, "clicked", _bt_clicked, (void *)2);
82    evas_object_smart_callback_add(bt, "unpressed", _bt_unpressed, (void *)2);
83    elm_box_pack_end(bx, bt);
84    evas_object_show(bt);
85    evas_object_show(ic);
86
87    ic = elm_icon_add(win);
88    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR);
89    elm_icon_file_set(ic, buf, NULL);
90    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
91    bt = elm_button_add(win);
92    elm_object_text_set(bt, "Disabled Button");
93    elm_button_icon_set(bt, ic);
94    elm_object_disabled_set(bt, 1);
95    evas_object_smart_callback_add(bt, "clicked", _bt_clicked, (void *)3);
96    evas_object_smart_callback_add(bt, "unpressed", _bt_unpressed, (void *)3);
97    elm_box_pack_end(bx, bt);
98    evas_object_show(bt);
99    evas_object_show(ic);
100
101    ic = elm_icon_add(win);
102    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR);
103    elm_icon_file_set(ic, buf, NULL);
104    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
105    bt = elm_button_add(win);
106    elm_button_icon_set(bt, ic);
107    elm_object_disabled_set(bt, 1);
108    evas_object_smart_callback_add(bt, "clicked", _bt_clicked, (void *)4);
109    evas_object_smart_callback_add(bt, "unpressed", _bt_unpressed, (void *)4);
110    elm_box_pack_end(bx, bt);
111    evas_object_show(bt);
112    evas_object_show(ic);
113
114    bt = elm_button_add(win);
115    elm_object_text_set(bt, "Label Only");
116    evas_object_smart_callback_add(bt, "clicked", _bt_clicked, (void *)5);
117    evas_object_smart_callback_add(bt, "unpressed", _bt_unpressed, (void *)5);
118    elm_box_pack_end(bx, bt);
119    evas_object_smart_callback_add(bt, "repeated", _bt_repeated, NULL);
120    elm_button_autorepeat_set(bt, 1);
121    elm_button_autorepeat_initial_timeout_set(bt, 2.0);
122    elm_button_autorepeat_gap_timeout_set(bt, 0.5);
123    evas_object_show(bt);
124
125    ic = elm_icon_add(win);
126    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR);
127    elm_icon_file_set(ic, buf, NULL);
128    elm_icon_scale_set(ic, 0, 0);
129    bt = elm_button_add(win);
130    elm_button_icon_set(bt, ic);
131    evas_object_smart_callback_add(bt, "clicked", _bt_clicked, (void *)6);
132    evas_object_smart_callback_add(bt, "unpressed", _bt_unpressed, (void *)6);
133    elm_box_pack_end(bx, bt);
134    evas_object_show(bt);
135    evas_object_show(ic);
136
137    bt = elm_button_add(win);
138    elm_object_style_set(bt, "anchor");
139    elm_object_text_set(bt, "Anchor style");
140    evas_object_smart_callback_add(bt, "clicked", _bt_clicked, (void *)7);
141    evas_object_smart_callback_add(bt, "unpressed", _bt_unpressed, (void *)7);
142    elm_box_pack_end(bx, bt);
143    evas_object_show(bt);
144
145    ic = elm_icon_add(win);
146    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR);
147    elm_icon_file_set(ic, buf, NULL);
148    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
149    bt = elm_button_add(win);
150    elm_object_style_set(bt, "anchor");
151    elm_button_icon_set(bt, ic);
152    evas_object_smart_callback_add(bt, "clicked", _bt_clicked, (void *)8);
153    evas_object_smart_callback_add(bt, "unpressed", _bt_unpressed, (void *)8);
154    elm_box_pack_end(bx, bt);
155    evas_object_show(bt);
156    evas_object_show(ic);
157
158    ic = elm_icon_add(win);
159    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR);
160    elm_icon_file_set(ic, buf, NULL);
161    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
162    bt = elm_button_add(win);
163    elm_object_style_set(bt, "anchor");
164    elm_button_icon_set(bt, ic);
165    elm_object_disabled_set(bt, 1);
166    evas_object_smart_callback_add(bt, "clicked", _bt_clicked, (void *)9);
167    evas_object_smart_callback_add(bt, "unpressed", _bt_unpressed, (void *)9);
168    elm_box_pack_end(bx, bt);
169    evas_object_show(bt);
170    evas_object_show(ic);
171    evas_object_resize(win, 320, 480);
172    evas_object_show(win);
173 }
174 #endif