aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/elementary/src/examples/button_example_01.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-04-22 09:20:32 +1000
committerDavid Walter Seikel2012-04-22 09:20:32 +1000
commit3ad3455551be0d7859ecb02290376206d5e66498 (patch)
tree497917e12b4d7f458dff9765d9b53f64c4e03fc3 /libraries/elementary/src/examples/button_example_01.c
parentUpdate EFL to latest beta. (diff)
downloadSledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.zip
SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.tar.gz
SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.tar.bz2
SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.tar.xz
And actually include new files, plus elementary libraries.
Diffstat (limited to 'libraries/elementary/src/examples/button_example_01.c')
-rw-r--r--libraries/elementary/src/examples/button_example_01.c265
1 files changed, 265 insertions, 0 deletions
diff --git a/libraries/elementary/src/examples/button_example_01.c b/libraries/elementary/src/examples/button_example_01.c
new file mode 100644
index 0000000..4005662
--- /dev/null
+++ b/libraries/elementary/src/examples/button_example_01.c
@@ -0,0 +1,265 @@
1/*
2 * gcc -o button_example_01 button_example_01.c `pkg-config --cflags --libs elementary`
3 */
4#include <Elementary.h>
5
6typedef struct
7{
8 Evas_Object *mid;
9 Evas_Object *icon_still;
10 struct {
11 Evas_Object *up;
12 Evas_Object *down;
13 Evas_Object *left;
14 Evas_Object *right;
15 } cursors;
16} App_Data;
17
18static void
19_btn_cursors_release_cb(void *data, Evas_Object *btn, void *ev)
20{
21 App_Data *app = data;
22 elm_object_part_content_set(app->mid, "icon", app->icon_still);
23 app->icon_still = NULL;
24}
25
26static void
27_btn_cursors_move_cb(void *data, Evas_Object *btn, void *ev)
28{
29 App_Data *app = data;
30 double ax, ay;
31
32 if (!app->icon_still)
33 {
34 Evas_Object *icon;
35 app->icon_still = elm_object_content_unset(app->mid);
36 evas_object_hide(app->icon_still);
37 icon = elm_icon_add(app->mid);
38 elm_icon_standard_set(icon, "chat");
39 elm_object_part_content_set(app->mid, "icon", icon);
40 }
41
42 evas_object_size_hint_align_get(app->mid, &ax, &ay);
43 if (btn == app->cursors.up)
44 {
45 ay -= 0.05;
46 if (ay < 0.0)
47 ay = 0.0;
48 }
49 else if (btn == app->cursors.down)
50 {
51 ay += 0.05;
52 if (ay > 1.0)
53 ay = 1.0;
54 }
55 else if (btn == app->cursors.left)
56 {
57 ax -= 0.05;
58 if (ax < 0.0)
59 ax = 0.0;
60 }
61 else if (btn == app->cursors.right)
62 {
63 ax += 0.05;
64 if (ax > 1.0)
65 ax = 1.0;
66 }
67 evas_object_size_hint_align_set(app->mid, ax, ay);
68}
69
70static void
71_btn_options_cb(void *data, Evas_Object *btn, void *ev)
72{
73 char *ptr;
74 double t;
75 App_Data *app = data;
76 const char *lbl = elm_object_text_get(btn);
77
78 ptr = strchr(lbl, ':');
79 ptr += 2;
80 t = strtod(ptr, NULL);
81
82 if (!strncmp(lbl, "Initial", 7))
83 {
84 elm_button_autorepeat_initial_timeout_set(app->cursors.up, t);
85 elm_button_autorepeat_initial_timeout_set(app->cursors.down, t);
86 elm_button_autorepeat_initial_timeout_set(app->cursors.left, t);
87 elm_button_autorepeat_initial_timeout_set(app->cursors.right, t);
88 }
89 else if (!strncmp(lbl, "Gap", 3))
90 {
91 elm_button_autorepeat_gap_timeout_set(app->cursors.up, t);
92 elm_button_autorepeat_gap_timeout_set(app->cursors.down, t);
93 elm_button_autorepeat_gap_timeout_set(app->cursors.left, t);
94 elm_button_autorepeat_gap_timeout_set(app->cursors.right, t);
95 }
96}
97
98EAPI_MAIN int
99elm_main(int argc, char *argv[])
100{
101 Evas_Object *win, *bg, *box, *box2, *btn, *icon;
102 static App_Data data;
103
104 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
105
106 win = elm_win_add(NULL, "Button example", ELM_WIN_BASIC);
107 elm_win_title_set(win, "Button example");
108 elm_win_autodel_set(win, EINA_TRUE);
109 evas_object_resize(win, 300, 320);
110 evas_object_show(win);
111
112 bg = elm_bg_add(win);
113 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
114 elm_win_resize_object_add(win, bg);
115 evas_object_show(bg);
116
117 box = elm_box_add(win);
118 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
119 elm_win_resize_object_add(win, box);
120 evas_object_show(box);
121
122 box2 = elm_box_add(win);
123 elm_box_horizontal_set(box2, EINA_TRUE);
124 evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, 0.0);
125 elm_box_pack_end(box, box2);
126 evas_object_show(box2);
127
128 btn = elm_button_add(win);
129 elm_object_text_set(btn, "Initial: 0.0");
130 elm_box_pack_end(box2, btn);
131 evas_object_show(btn);
132 evas_object_smart_callback_add(btn, "clicked", _btn_options_cb, &data);
133
134 btn = elm_button_add(win);
135 elm_object_text_set(btn, "Initial: 1.0");
136 elm_box_pack_end(box2, btn);
137 evas_object_show(btn);
138 evas_object_smart_callback_add(btn, "clicked", _btn_options_cb, &data);
139
140 btn = elm_button_add(win);
141 elm_object_text_set(btn, "Initial: 5.0");
142 elm_box_pack_end(box2, btn);
143 evas_object_show(btn);
144 evas_object_smart_callback_add(btn, "clicked", _btn_options_cb, &data);
145
146 box2 = elm_box_add(win);
147 elm_box_horizontal_set(box2, EINA_TRUE);
148 evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, 0.0);
149 elm_box_pack_end(box, box2);
150 evas_object_show(box2);
151
152 btn = elm_button_add(win);
153 elm_object_text_set(btn, "Gap: 0.1");
154 elm_box_pack_end(box2, btn);
155 evas_object_show(btn);
156 evas_object_smart_callback_add(btn, "clicked", _btn_options_cb, &data);
157
158 btn = elm_button_add(win);
159 elm_object_text_set(btn, "Gap: 0.5");
160 elm_box_pack_end(box2, btn);
161 evas_object_show(btn);
162 evas_object_smart_callback_add(btn, "clicked", _btn_options_cb, &data);
163
164 btn = elm_button_add(win);
165 elm_object_text_set(btn, "Gap: 1.0");
166 elm_box_pack_end(box2, btn);
167 evas_object_show(btn);
168 evas_object_smart_callback_add(btn, "clicked", _btn_options_cb, &data);
169
170 btn = elm_button_add(win);
171 elm_button_autorepeat_set(btn, EINA_TRUE);
172 elm_button_autorepeat_initial_timeout_set(btn, 1.0);
173 elm_button_autorepeat_gap_timeout_set(btn, 0.5);
174 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, 0.0);
175 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 0.0);
176 elm_box_pack_end(box, btn);
177 evas_object_show(btn);
178 evas_object_smart_callback_add(btn, "repeated", _btn_cursors_move_cb, &data);
179 evas_object_smart_callback_add(btn, "unpressed", _btn_cursors_release_cb,
180 &data);
181
182 icon = elm_icon_add(win);
183 elm_icon_standard_set(icon, "arrow_up");
184 elm_object_part_content_set(btn, "icon", icon);
185
186 data.cursors.up = btn;
187
188 box2 = elm_box_add(win);
189 elm_box_horizontal_set(box2, EINA_TRUE);
190 evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
191 evas_object_size_hint_align_set(box2, EVAS_HINT_FILL, EVAS_HINT_FILL);
192 elm_box_pack_end(box, box2);
193 evas_object_show(box2);
194
195 btn = elm_button_add(win);
196 elm_button_autorepeat_set(btn, EINA_TRUE);
197 elm_button_autorepeat_initial_timeout_set(btn, 1.0);
198 elm_button_autorepeat_gap_timeout_set(btn, 0.5);
199 evas_object_size_hint_weight_set(btn, 0.0, EVAS_HINT_EXPAND);
200 evas_object_size_hint_align_set(btn, 0.0, EVAS_HINT_FILL);
201 elm_box_pack_end(box2, btn);
202 evas_object_show(btn);
203 evas_object_smart_callback_add(btn, "repeated", _btn_cursors_move_cb, &data);
204 evas_object_smart_callback_add(btn, "unpressed", _btn_cursors_release_cb,
205 &data);
206
207 icon = elm_icon_add(win);
208 elm_icon_standard_set(icon, "arrow_left");
209 elm_object_part_content_set(btn, "icon", icon);
210
211 data.cursors.left = btn;
212
213 btn = elm_button_add(win);
214 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
215 elm_box_pack_end(box2, btn);
216 evas_object_show(btn);
217
218 icon = elm_icon_add(win);
219 elm_icon_standard_set(icon, "close");
220 elm_object_part_content_set(btn, "icon", icon);
221
222 data.mid = btn;
223
224 btn = elm_button_add(win);
225 elm_button_autorepeat_set(btn, EINA_TRUE);
226 elm_button_autorepeat_initial_timeout_set(btn, 1.0);
227 elm_button_autorepeat_gap_timeout_set(btn, 0.5);
228 evas_object_size_hint_weight_set(btn, 0.0, EVAS_HINT_EXPAND);
229 evas_object_size_hint_align_set(btn, 0.0, EVAS_HINT_FILL);
230 elm_box_pack_end(box2, btn);
231 evas_object_show(btn);
232 evas_object_smart_callback_add(btn, "repeated", _btn_cursors_move_cb, &data);
233 evas_object_smart_callback_add(btn, "unpressed", _btn_cursors_release_cb,
234 &data);
235
236 icon = elm_icon_add(win);
237 elm_icon_standard_set(icon, "arrow_right");
238 elm_object_part_content_set(btn, "icon", icon);
239
240 data.cursors.right = btn;
241
242 btn = elm_button_add(win);
243 elm_button_autorepeat_set(btn, EINA_TRUE);
244 elm_button_autorepeat_initial_timeout_set(btn, 1.0);
245 elm_button_autorepeat_gap_timeout_set(btn, 0.5);
246 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, 0.0);
247 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 0.0);
248 elm_box_pack_end(box, btn);
249 evas_object_show(btn);
250 evas_object_smart_callback_add(btn, "repeated", _btn_cursors_move_cb, &data);
251 evas_object_smart_callback_add(btn, "unpressed", _btn_cursors_release_cb,
252 &data);
253
254 icon = elm_icon_add(win);
255 elm_icon_standard_set(icon, "arrow_down");
256 elm_object_part_content_set(btn, "icon", icon);
257
258 data.cursors.down = btn;
259
260 elm_run();
261 elm_shutdown();
262
263 return 0;
264}
265ELM_MAIN()