2 * gcc -o button_example_01 button_example_01.c `pkg-config --cflags --libs elementary`
4 #include <Elementary.h>
6 # include "elementary_config.h"
14 Evas_Object *icon_still;
24 _btn_cursors_release_cb(void *data, Evas_Object *btn __UNUSED__, void *ev __UNUSED__)
27 elm_button_icon_set(app->mid, app->icon_still);
28 app->icon_still = NULL;
32 _btn_cursors_move_cb(void *data, Evas_Object *btn, void *ev __UNUSED__)
40 app->icon_still = elm_button_icon_unset(app->mid);
41 icon = elm_icon_add(app->mid);
42 elm_icon_standard_set(icon, "chat");
43 elm_button_icon_set(app->mid, icon);
46 evas_object_size_hint_align_get(app->mid, &ax, &ay);
47 if (btn == app->cursors.up)
53 else if (btn == app->cursors.down)
59 else if (btn == app->cursors.left)
65 else if (btn == app->cursors.right)
71 evas_object_size_hint_align_set(app->mid, ax, ay);
75 _btn_options_cb(void *data, Evas_Object *btn, void *ev __UNUSED__)
80 const char *lbl = elm_button_label_get(btn);
82 ptr = strchr(lbl, ':');
84 t = strtod(ptr, NULL);
86 if (!strncmp(lbl, "Initial", 7))
88 elm_button_autorepeat_initial_timeout_set(app->cursors.up, t);
89 elm_button_autorepeat_initial_timeout_set(app->cursors.down, t);
90 elm_button_autorepeat_initial_timeout_set(app->cursors.left, t);
91 elm_button_autorepeat_initial_timeout_set(app->cursors.right, t);
93 else if (!strncmp(lbl, "Gap", 3))
95 elm_button_autorepeat_gap_timeout_set(app->cursors.up, t);
96 elm_button_autorepeat_gap_timeout_set(app->cursors.down, t);
97 elm_button_autorepeat_gap_timeout_set(app->cursors.left, t);
98 elm_button_autorepeat_gap_timeout_set(app->cursors.right, t);
103 elm_main(int argc __UNUSED__, char *argv[] __UNUSED__)
105 Evas_Object *win, *bg, *box, *box2, *btn, *icon;
106 static App_Data data;
108 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
110 win = elm_win_add(NULL, "Button example", ELM_WIN_BASIC);
111 elm_win_title_set(win, "Button example");
112 elm_win_autodel_set(win, EINA_TRUE);
113 evas_object_resize(win, 300, 320);
114 evas_object_show(win);
116 bg = elm_bg_add(win);
117 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
118 elm_win_resize_object_add(win, bg);
119 evas_object_show(bg);
121 box = elm_box_add(win);
122 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
123 elm_win_resize_object_add(win, box);
124 evas_object_show(box);
126 box2 = elm_box_add(win);
127 elm_box_horizontal_set(box2, EINA_TRUE);
128 evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, 0.0);
129 elm_box_pack_end(box, box2);
130 evas_object_show(box2);
132 btn = elm_button_add(win);
133 elm_button_label_set(btn, "Initial: 0.0");
134 elm_box_pack_end(box2, btn);
135 evas_object_show(btn);
136 evas_object_smart_callback_add(btn, "clicked", _btn_options_cb, &data);
138 btn = elm_button_add(win);
139 elm_button_label_set(btn, "Initial: 1.0");
140 elm_box_pack_end(box2, btn);
141 evas_object_show(btn);
142 evas_object_smart_callback_add(btn, "clicked", _btn_options_cb, &data);
144 btn = elm_button_add(win);
145 elm_button_label_set(btn, "Initial: 5.0");
146 elm_box_pack_end(box2, btn);
147 evas_object_show(btn);
148 evas_object_smart_callback_add(btn, "clicked", _btn_options_cb, &data);
150 box2 = elm_box_add(win);
151 elm_box_horizontal_set(box2, EINA_TRUE);
152 evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, 0.0);
153 elm_box_pack_end(box, box2);
154 evas_object_show(box2);
156 btn = elm_button_add(win);
157 elm_button_label_set(btn, "Gap: 0.1");
158 elm_box_pack_end(box2, btn);
159 evas_object_show(btn);
160 evas_object_smart_callback_add(btn, "clicked", _btn_options_cb, &data);
162 btn = elm_button_add(win);
163 elm_button_label_set(btn, "Gap: 0.5");
164 elm_box_pack_end(box2, btn);
165 evas_object_show(btn);
166 evas_object_smart_callback_add(btn, "clicked", _btn_options_cb, &data);
168 btn = elm_button_add(win);
169 elm_button_label_set(btn, "Gap: 1.0");
170 elm_box_pack_end(box2, btn);
171 evas_object_show(btn);
172 evas_object_smart_callback_add(btn, "clicked", _btn_options_cb, &data);
174 btn = elm_button_add(win);
175 elm_button_autorepeat_set(btn, EINA_TRUE);
176 elm_button_autorepeat_initial_timeout_set(btn, 1.0);
177 elm_button_autorepeat_gap_timeout_set(btn, 0.5);
178 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, 0.0);
179 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 0.0);
180 elm_box_pack_end(box, btn);
181 evas_object_show(btn);
182 evas_object_smart_callback_add(btn, "repeated", _btn_cursors_move_cb, &data);
183 evas_object_smart_callback_add(btn, "unpressed", _btn_cursors_release_cb,
186 icon = elm_icon_add(win);
187 elm_icon_standard_set(icon, "arrow_up");
188 elm_button_icon_set(btn, icon);
190 data.cursors.up = btn;
192 box2 = elm_box_add(win);
193 elm_box_horizontal_set(box2, EINA_TRUE);
194 evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
195 evas_object_size_hint_align_set(box2, EVAS_HINT_FILL, EVAS_HINT_FILL);
196 elm_box_pack_end(box, box2);
197 evas_object_show(box2);
199 btn = elm_button_add(win);
200 elm_button_autorepeat_set(btn, EINA_TRUE);
201 elm_button_autorepeat_initial_timeout_set(btn, 1.0);
202 elm_button_autorepeat_gap_timeout_set(btn, 0.5);
203 evas_object_size_hint_weight_set(btn, 0.0, EVAS_HINT_EXPAND);
204 evas_object_size_hint_align_set(btn, 0.0, EVAS_HINT_FILL);
205 elm_box_pack_end(box2, btn);
206 evas_object_show(btn);
207 evas_object_smart_callback_add(btn, "repeated", _btn_cursors_move_cb, &data);
208 evas_object_smart_callback_add(btn, "unpressed", _btn_cursors_release_cb,
211 icon = elm_icon_add(win);
212 elm_icon_standard_set(icon, "arrow_left");
213 elm_button_icon_set(btn, icon);
215 data.cursors.left = btn;
217 btn = elm_button_add(win);
218 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
219 elm_box_pack_end(box2, btn);
220 evas_object_show(btn);
222 icon = elm_icon_add(win);
223 elm_icon_standard_set(icon, "close");
224 elm_button_icon_set(btn, icon);
228 btn = elm_button_add(win);
229 elm_button_autorepeat_set(btn, EINA_TRUE);
230 elm_button_autorepeat_initial_timeout_set(btn, 1.0);
231 elm_button_autorepeat_gap_timeout_set(btn, 0.5);
232 evas_object_size_hint_weight_set(btn, 0.0, EVAS_HINT_EXPAND);
233 evas_object_size_hint_align_set(btn, 0.0, EVAS_HINT_FILL);
234 elm_box_pack_end(box2, btn);
235 evas_object_show(btn);
236 evas_object_smart_callback_add(btn, "repeated", _btn_cursors_move_cb, &data);
237 evas_object_smart_callback_add(btn, "unpressed", _btn_cursors_release_cb,
240 icon = elm_icon_add(win);
241 elm_icon_standard_set(icon, "arrow_right");
242 elm_button_icon_set(btn, icon);
244 data.cursors.right = btn;
246 btn = elm_button_add(win);
247 elm_button_autorepeat_set(btn, EINA_TRUE);
248 elm_button_autorepeat_initial_timeout_set(btn, 1.0);
249 elm_button_autorepeat_gap_timeout_set(btn, 0.5);
250 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, 0.0);
251 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 0.0);
252 elm_box_pack_end(box, btn);
253 evas_object_show(btn);
254 evas_object_smart_callback_add(btn, "repeated", _btn_cursors_move_cb, &data);
255 evas_object_smart_callback_add(btn, "unpressed", _btn_cursors_release_cb,
258 icon = elm_icon_add(win);
259 elm_icon_standard_set(icon, "arrow_down");
260 elm_button_icon_set(btn, icon);
262 data.cursors.down = btn;