From: Bluezery <ohpowel@gmail.com>
[framework/uifw/elementary.git] / src / examples / box_example_02.c
1 #include <Elementary.h>
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #else
5 # define __UNUSED__
6 #endif
7
8 typedef struct
9 {
10    Eina_List *transitions;
11    Evas_Object *box;
12    Evas_Object_Box_Layout last_layout;
13 } Transitions_Data;
14
15 static void
16 _add_cb(void *data, Evas_Object *obj __UNUSED__, void *ev __UNUSED__)
17 {
18    Evas_Object *btn;
19    Eina_List *children;
20    Transitions_Data *tdata = data;
21
22    btn = elm_button_add(tdata->box);
23    elm_object_text_set(btn, "I do nothing");
24    children = (Eina_List *)elm_box_children_get(tdata->box);
25    if (children)
26      {
27         elm_box_pack_after(tdata->box, btn, (Evas_Object *)children->data);
28         eina_list_free(children);
29      }
30    else
31      elm_box_pack_end(tdata->box, btn);
32    evas_object_show(btn);
33 }
34
35 static void
36 _clear_cb(void *data, Evas_Object *obj __UNUSED__, void *ev __UNUSED__)
37 {
38    Transitions_Data *tdata = data;
39    elm_box_clear(tdata->box);
40 }
41
42 static void
43 _unpack_cb(void *data, Evas_Object *obj, void *ev __UNUSED__)
44 {
45    Transitions_Data *tdata = data;
46    elm_box_unpack(tdata->box, obj);
47    evas_object_move(obj, 0, 50);
48    evas_object_color_set(obj, 128, 64, 0, 128);
49 }
50
51 static void
52 _test_box_transition_change(void *data)
53 {
54    Transitions_Data *tdata = data;
55    Elm_Box_Transition *layout_data;
56    Evas_Object_Box_Layout next_layout;
57
58    if (!data) return;
59    next_layout = eina_list_data_get(tdata->transitions);
60    layout_data = elm_box_transition_new(2.0, tdata->last_layout,
61                                         NULL, NULL, next_layout, NULL, NULL,
62                                         _test_box_transition_change, tdata);
63    elm_box_layout_set(tdata->box, elm_box_layout_transition, layout_data,
64                       elm_box_transition_free);
65    tdata->last_layout = next_layout;
66
67    tdata->transitions = eina_list_demote_list(tdata->transitions,
68                                               tdata->transitions);
69 }
70
71 int
72 elm_main(int argc __UNUSED__, char *argv[] __UNUSED__)
73 {
74    Evas_Object *win, *bg, *bigbox, *bx, *bt;
75    static Transitions_Data tdata = {
76         .transitions = NULL,
77         .box = NULL,
78         .last_layout = NULL
79    };
80
81    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
82
83    win = elm_win_add(NULL, "box-transition", ELM_WIN_BASIC);
84    elm_win_title_set(win, "Box Transition");
85    elm_win_autodel_set(win, EINA_TRUE);
86    evas_object_resize(win, 300, 320);
87    evas_object_show(win);
88
89    bg = elm_bg_add(win);
90    elm_win_resize_object_add(win, bg);
91    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
92    evas_object_show(bg);
93
94    bigbox = elm_box_add(win);
95    evas_object_size_hint_weight_set(bigbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
96    elm_win_resize_object_add(win, bigbox);
97    evas_object_show(bigbox);
98
99    bx = elm_box_add(win);
100    elm_box_horizontal_set(bx, EINA_TRUE);
101    elm_box_pack_end(bigbox, bx);
102    evas_object_show(bx);
103
104    bt = elm_button_add(win);
105    elm_object_text_set(bt, "Add");
106    elm_box_pack_end(bx, bt);
107    evas_object_show(bt);
108    evas_object_smart_callback_add(bt, "clicked", _add_cb, &tdata);
109
110    bt = elm_button_add(win);
111    elm_object_text_set(bt, "Clear");
112    elm_box_pack_end(bx, bt);
113    evas_object_show(bt);
114    evas_object_smart_callback_add(bt, "clicked", _clear_cb, &tdata);
115
116    bx = elm_box_add(win);
117    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
118    evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, EVAS_HINT_FILL);
119    elm_box_pack_end(bigbox, bx);
120    evas_object_show(bx);
121
122    bt = elm_button_add(win);
123    elm_object_text_set(bt, "Button 1");
124    evas_object_smart_callback_add(bt, "clicked", _unpack_cb, &tdata);
125    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
126    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
127    elm_box_pack_end(bx, bt);
128    evas_object_show(bt);
129
130    bt = elm_button_add(win);
131    elm_object_text_set(bt, "Button 2");
132    evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0);
133    evas_object_size_hint_align_set(bt, 1.0, 0.5);
134    evas_object_smart_callback_add(bt, "clicked", _unpack_cb, &tdata);
135    elm_box_pack_end(bx, bt);
136    evas_object_show(bt);
137
138    bt = elm_button_add(win);
139    elm_object_text_set(bt, "Button 3");
140    evas_object_smart_callback_add(bt, "clicked", _unpack_cb, &tdata);
141    elm_box_pack_end(bx, bt);
142    evas_object_show(bt);
143
144    tdata.box = bx;
145    tdata.last_layout = evas_object_box_layout_horizontal;
146    tdata.transitions = eina_list_append(tdata.transitions,
147          evas_object_box_layout_vertical);
148    tdata.transitions = eina_list_append(tdata.transitions,
149          evas_object_box_layout_horizontal);
150    tdata.transitions = eina_list_append(tdata.transitions,
151          evas_object_box_layout_stack);
152    tdata.transitions = eina_list_append(tdata.transitions,
153          evas_object_box_layout_homogeneous_vertical);
154    tdata.transitions = eina_list_append(tdata.transitions,
155          evas_object_box_layout_homogeneous_horizontal);
156    tdata.transitions = eina_list_append(tdata.transitions,
157          evas_object_box_layout_flow_vertical);
158    tdata.transitions = eina_list_append(tdata.transitions,
159          evas_object_box_layout_flow_horizontal);
160    tdata.transitions = eina_list_append(tdata.transitions,
161          evas_object_box_layout_stack);
162
163    elm_box_layout_set(bx, evas_object_box_layout_horizontal, NULL, NULL);
164    _test_box_transition_change(&tdata);
165
166    elm_run();
167
168    return 0;
169 }
170 ELM_MAIN();