elm box -> use padding!
[framework/uifw/elementary.git] / src / bin / test_box.c
1 #include <Elementary.h>
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #endif
5 #ifndef ELM_LIB_QUICKLAUNCH
6 void
7 test_box_vert(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
8 {
9    Evas_Object *win, *bg, *bx, *ic;
10    char buf[PATH_MAX];
11
12    win = elm_win_add(NULL, "box-vert", ELM_WIN_BASIC);
13    elm_win_title_set(win, "Box Vert");
14    elm_win_autodel_set(win, 1);
15
16    bg = elm_bg_add(win);
17    elm_win_resize_object_add(win, bg);
18    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
19    evas_object_show(bg);
20
21    bx = elm_box_add(win);
22    elm_win_resize_object_add(win, bx);
23    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
24    evas_object_show(bx);
25
26    elm_box_padding_set(bx, 1000, 1000);
27
28    ic = elm_icon_add(win);
29    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR);
30    elm_icon_file_set(ic, buf, NULL);
31    elm_icon_scale_set(ic, 0, 0);
32    evas_object_size_hint_align_set(ic, 0.5, 0.5);
33    elm_box_pack_end(bx, ic);
34    evas_object_show(ic);
35
36    ic = elm_icon_add(win);
37    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR);
38    elm_icon_file_set(ic, buf, NULL);
39    elm_icon_scale_set(ic, 0, 0);
40    evas_object_size_hint_align_set(ic, 0.0, 0.5);
41    elm_box_pack_end(bx, ic);
42    evas_object_show(ic);
43
44    ic = elm_icon_add(win);
45    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR);
46    elm_icon_file_set(ic, buf, NULL);
47    elm_icon_scale_set(ic, 0, 0);
48    evas_object_size_hint_align_set(ic, EVAS_HINT_EXPAND, 0.5);
49    elm_box_pack_end(bx, ic);
50    evas_object_show(ic);
51
52    evas_object_show(win);
53 }
54
55 static void
56 _del_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
57 {
58    elm_box_unpack(data, obj);
59    evas_object_move(obj, 0, 0);
60    evas_object_color_set(obj, 128, 64, 0, 128);
61 //   evas_object_del(obj);
62 }
63
64 void
65 test_box_vert2(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
66 {
67    Evas_Object *win, *bg, *bx, *bt;
68
69    win = elm_win_add(NULL, "box-vert2", ELM_WIN_BASIC);
70    elm_win_title_set(win, "Box Vert 2");
71    elm_win_autodel_set(win, 1);
72
73    bg = elm_bg_add(win);
74    elm_win_resize_object_add(win, bg);
75    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
76    evas_object_show(bg);
77
78    bx = elm_box_add(win);
79    elm_win_resize_object_add(win, bx);
80    elm_box_padding_set(bx, 10, 10);
81    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
82    evas_object_show(bx);
83
84    bt = elm_button_add(win);
85    elm_button_label_set(bt, "Button 1");
86    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
87    evas_object_size_hint_weight_set(bt, 0.0, 0.0);
88    evas_object_smart_callback_add(bt, "clicked", _del_cb, bx);
89    elm_box_pack_end(bx, bt);
90    evas_object_show(bt);
91
92    bt = elm_button_add(win);
93    elm_button_label_set(bt, "Button 2");
94    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
95    evas_object_size_hint_weight_set(bt, 0.0, 0.0);
96    evas_object_smart_callback_add(bt, "clicked", _del_cb, bx);
97    elm_box_pack_end(bx, bt);
98    evas_object_show(bt);
99
100    bt = elm_button_add(win);
101    elm_button_label_set(bt, "Button 3");
102    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
103    evas_object_size_hint_weight_set(bt, 0.0, 0.0);
104    evas_object_smart_callback_add(bt, "clicked", _del_cb, bx);
105    elm_box_pack_end(bx, bt);
106    evas_object_show(bt);
107
108    bt = elm_button_add(win);
109    elm_button_label_set(bt, "Button 4");
110    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
111    evas_object_size_hint_weight_set(bt, 0.0, 0.0);
112    evas_object_smart_callback_add(bt, "clicked", _del_cb, bx);
113    elm_box_pack_end(bx, bt);
114    evas_object_show(bt);
115
116    bt = elm_button_add(win);
117    elm_button_label_set(bt, "Button 5");
118    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
119    evas_object_size_hint_weight_set(bt, 0.0, 0.0);
120    evas_object_smart_callback_add(bt, "clicked", _del_cb, bx);
121    elm_box_pack_end(bx, bt);
122    evas_object_show(bt);
123
124    evas_object_show(win);
125 }
126
127 void
128 test_box_horiz(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
129 {
130    Evas_Object *win, *bg, *bx, *ic;
131    char buf[PATH_MAX];
132
133    win = elm_win_add(NULL, "box-horiz", ELM_WIN_BASIC);
134    elm_win_title_set(win, "Box Horiz");
135    elm_win_autodel_set(win, 1);
136
137    bg = elm_bg_add(win);
138    elm_win_resize_object_add(win, bg);
139    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
140    evas_object_show(bg);
141
142    bx = elm_box_add(win);
143    elm_box_horizontal_set(bx, EINA_TRUE);
144    elm_win_resize_object_add(win, bx);
145    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
146    evas_object_show(bx);
147
148    ic = elm_icon_add(win);
149    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR);
150    elm_icon_file_set(ic, buf, NULL);
151    elm_icon_scale_set(ic, 0, 0);
152    evas_object_size_hint_align_set(ic, 0.5, 0.5);
153    elm_box_pack_end(bx, ic);
154    evas_object_show(ic);
155
156    ic = elm_icon_add(win);
157    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR);
158    elm_icon_file_set(ic, buf, NULL);
159    elm_icon_scale_set(ic, 0, 0);
160    evas_object_size_hint_align_set(ic, 0.5, 0.0);
161    elm_box_pack_end(bx, ic);
162    evas_object_show(ic);
163
164    ic = elm_icon_add(win);
165    snprintf(buf, sizeof(buf), "%s/images/logo_small.png", PACKAGE_DATA_DIR);
166    elm_icon_file_set(ic, buf, NULL);
167    elm_icon_scale_set(ic, 0, 0);
168    evas_object_size_hint_align_set(ic, 0.0, EVAS_HINT_EXPAND);
169    elm_box_pack_end(bx, ic);
170    evas_object_show(ic);
171
172    evas_object_show(win);
173 }
174
175 typedef struct
176 {
177    Eina_List *transitions;
178    Evas_Object *box;
179    Evas_Object_Box_Layout last_layout;
180 } Transitions_Data;
181
182 static void
183 _test_box_transition_change(void *data)
184 {
185    Transitions_Data *tdata = data;
186    Elm_Box_Transition *layout_data;
187    Evas_Object_Box_Layout next_layout;
188
189    if (!data) return;
190    next_layout = eina_list_data_get(tdata->transitions);
191    layout_data = elm_box_transition_new(2.0, tdata->last_layout,
192                                         NULL, NULL, next_layout, NULL, NULL,
193                                         _test_box_transition_change, tdata);
194    elm_box_layout_set(tdata->box, elm_box_layout_transition, layout_data, elm_box_transition_free);
195    tdata->last_layout = next_layout;
196
197    tdata->transitions = eina_list_demote_list(tdata->transitions, tdata->transitions);
198 }
199
200 static void
201 _win_del(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
202 {
203    Transitions_Data *tdata = data;
204    if (!data) return;
205    elm_box_layout_set(tdata->box, evas_object_box_layout_horizontal, NULL, NULL);
206    free(tdata);
207 }
208
209 void
210 test_box_transition(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
211 {
212    Evas_Object *win, *bg, *bx, *bt;
213    Transitions_Data *tdata;
214
215    win = elm_win_add(NULL, "box-transition", ELM_WIN_BASIC);
216    elm_win_title_set(win, "Box Transition");
217    elm_win_autodel_set(win, 1);
218
219    bg = elm_bg_add(win);
220    elm_win_resize_object_add(win, bg);
221    evas_object_size_hint_weight_set(bg, 1.0, 1.0);
222    evas_object_show(bg);
223
224    bx = elm_box_add(win);
225    elm_win_resize_object_add(win, bx);
226    evas_object_size_hint_weight_set(bx, 1.0, 1.0);
227
228    evas_object_show(bx);
229
230    bt = elm_button_add(win);
231    elm_button_label_set(bt, "Button 1");
232    evas_object_size_hint_weight_set(bt, 1.0, 1.0);
233    evas_object_size_hint_align_set(bt, -1.0, -1.0);
234    evas_object_smart_callback_add(bt, "clicked", _del_cb, bx);
235    elm_box_pack_end(bx, bt);
236    evas_object_resize(bt, 100, 100);
237    evas_object_show(bt);
238
239    bt = elm_button_add(win);
240    elm_button_label_set(bt, "Button 2");
241    evas_object_size_hint_weight_set(bt, 1.0, 1.0);
242    evas_object_size_hint_align_set(bt, -1.0, -1.0);
243    evas_object_smart_callback_add(bt, "clicked", _del_cb, bx);
244    elm_box_pack_end(bx, bt);
245    evas_object_resize(bt, 100, 100);
246    evas_object_show(bt);
247
248    bt = elm_button_add(win);
249    elm_button_label_set(bt, "Button 3");
250    evas_object_size_hint_weight_set(bt, 1.0, 1.0);
251    evas_object_size_hint_align_set(bt, -1.0, -1.0);
252    evas_object_smart_callback_add(bt, "clicked", _del_cb, bx);
253    elm_box_pack_end(bx, bt);
254    evas_object_resize(bt, 100, 100);
255    evas_object_show(bt);
256
257    tdata = calloc(1, sizeof(Transitions_Data));
258    tdata->box = bx;
259    tdata->last_layout = evas_object_box_layout_horizontal;
260    tdata->transitions = eina_list_append(tdata->transitions,
261          evas_object_box_layout_vertical);
262    tdata->transitions = eina_list_append(tdata->transitions,
263          evas_object_box_layout_horizontal);
264    tdata->transitions = eina_list_append(tdata->transitions,
265          evas_object_box_layout_stack);
266    tdata->transitions = eina_list_append(tdata->transitions,
267          evas_object_box_layout_homogeneous_vertical);
268    tdata->transitions = eina_list_append(tdata->transitions,
269          evas_object_box_layout_homogeneous_horizontal);
270    tdata->transitions = eina_list_append(tdata->transitions,
271          evas_object_box_layout_flow_vertical);
272    tdata->transitions = eina_list_append(tdata->transitions,
273          evas_object_box_layout_flow_horizontal);
274    tdata->transitions = eina_list_append(tdata->transitions,
275          evas_object_box_layout_stack);
276
277    evas_object_resize(win, 300, 300);
278    evas_object_resize(bx, 300, 300);
279    evas_object_smart_callback_add(win, "delete,request", _win_del, tdata);
280    evas_object_show(win);
281    elm_box_layout_set(bx, evas_object_box_layout_horizontal, NULL, NULL);
282    _test_box_transition_change(tdata);
283 }
284 #endif