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