summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2014-07-17 11:30:39 -0300
committerSavio Sena <savio@expertisesolutions.com.br>2014-07-21 20:53:12 -0300
commit109cd2e79985a076233e39844e83d218034218c4 (patch)
treeb04fdca7803f34667a2a36c59efc3573e2311731
parentcfd259d3bb86eb2aadb19455fac240289d96c27a (diff)
Removed C-style code from C++ example
-rw-r--r--src/examples/box_cxx_example_02.cc226
1 files changed, 107 insertions, 119 deletions
diff --git a/src/examples/box_cxx_example_02.cc b/src/examples/box_cxx_example_02.cc
index 3842ceb80..bb2a3db81 100644
--- a/src/examples/box_cxx_example_02.cc
+++ b/src/examples/box_cxx_example_02.cc
@@ -28,45 +28,48 @@
28#include <elm_box.eo.hh> 28#include <elm_box.eo.hh>
29#include <elm_button.eo.hh> 29#include <elm_button.eo.hh>
30 30
31#include <deque>
32
31typedef struct 33typedef struct
32{ 34{
33 Eina_List *transitions; 35 efl::eo::wref<elm_box> box;
34 Evas_Object *box; 36 std::deque<Evas_Object_Box_Layout> transitions;
35 Evas_Object_Box_Layout last_layout; 37 Evas_Object_Box_Layout last_layout;
36} Transitions_Data; 38} Transitions_Data;
37 39
38static void 40static void
39_add_cb(void *data, Evas_Object *obj, void *ev) 41_add_cb(void *data, Evas_Object *obj, void *ev)
40{ 42{
41 Evas_Object *btn;
42 Eina_List *children; 43 Eina_List *children;
43 Transitions_Data *tdata = static_cast<Transitions_Data*>(data); 44 Transitions_Data *tdata = static_cast<Transitions_Data*>(data);
44 45
45 btn = elm_button_add(tdata->box); 46 if(efl::eina::optional<elm_box> box = tdata->box.lock())
46 elm_object_text_set(btn, "I do nothing"); 47 {
47 children = (Eina_List *)elm_box_children_get(tdata->box); 48 elm_button btn ( efl::eo::parent = *box );
48 if (children) 49 btn.text_set("I do nothing");
49 { 50 efl::eina::list<efl::eo::base> childrens (box->children_get());
50 elm_box_pack_after(tdata->box, btn, (Evas_Object *)children->data); 51 if (!children.empty())
51 eina_list_free(children); 52 {
52 } 53 box->pack_after(btn._eo_ptr(), childrens.front());
53 else 54 }
54 elm_box_pack_end(tdata->box, btn); 55 else
55 evas_object_show(btn); 56 box->pack_end(btn._eo_ptr());
57 btn.visibility_set(true);
58 }
56} 59}
57 60
58static void 61static void
59_clear_cb(void *data, Evas_Object *obj, void *ev) 62_clear_cb(void *data, Evas_Object *obj, void *ev)
60{ 63{
61 Transitions_Data *tdata = static_cast<Transitions_Data*>(data); 64 Transitions_Data *tdata = static_cast<Transitions_Data*>(data);
62 elm_box_clear(tdata->box); 65 tdata->box.lock()->clear();
63} 66}
64 67
65static void 68static void
66_unpack_cb(void *data, Evas_Object *obj, void *ev) 69_unpack_cb(void *data, Evas_Object *obj, void *ev)
67{ 70{
68 Transitions_Data *tdata = static_cast<Transitions_Data*>(data); 71 Transitions_Data *tdata = static_cast<Transitions_Data*>(data);
69 elm_box_unpack(tdata->box, obj); 72 tdata->box.lock()->unpack(obj);
70 evas_object_move(obj, 0, 50); 73 evas_object_move(obj, 0, 50);
71 evas_object_color_set(obj, 128, 64, 0, 128); 74 evas_object_color_set(obj, 128, 64, 0, 128);
72} 75}
@@ -78,122 +81,107 @@ _test_box_transition_change(void *data)
78 Elm_Box_Transition *layout_data; 81 Elm_Box_Transition *layout_data;
79 Evas_Object_Box_Layout next_layout; 82 Evas_Object_Box_Layout next_layout;
80 83
81 if (!data) return; 84 assert (!!data);
82 next_layout = reinterpret_cast<Evas_Object_Box_Layout>(eina_list_data_get(tdata->transitions)); 85 assert (!tdata->transitions.empty());
83 layout_data = elm_box_transition_new(2.0, tdata->last_layout, 86
84 NULL, NULL, next_layout, NULL, NULL, 87 if(efl::eina::optional<elm_box> box = tdata->box.lock())
85 _test_box_transition_change, tdata); 88 {
86 elm_box_layout_set(tdata->box, elm_box_layout_transition, layout_data, 89 next_layout = tdata->transitions.front();
87 elm_box_transition_free); 90 layout_data = elm_box_transition_new(2.0, tdata->transitions.back(),
88 tdata->last_layout = next_layout; 91 nullptr, nullptr, next_layout, nullptr, nullptr,
89 92 _test_box_transition_change, tdata);
90 tdata->transitions = eina_list_demote_list(tdata->transitions, 93 box->layout_set(elm_box_layout_transition, layout_data,
91 tdata->transitions); 94 elm_box_transition_free);
95 tdata->last_layout = next_layout;
96
97 tdata->transitions.push_back(tdata->transitions[0]);
98 tdata->transitions.pop_front();
99 }
92} 100}
93 101
94EAPI_MAIN int 102EAPI_MAIN int
95elm_main(int argc, char *argv[]) 103elm_main(int argc, char *argv[])
96{ 104{
97 static Transitions_Data tdata = {
98 .transitions = NULL,
99 .box = NULL,
100 .last_layout = NULL
101 };
102
103 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); 105 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
104 106
105 { 107 Transitions_Data tdata
106 ::elm_win win ( ::eo_ref( elm_win_util_standard_add("box-transition", "Box Transition") ));
107 elm_win_autodel_set(win._eo_ptr(), EINA_TRUE);
108
109 elm_box bigbox ( ::eo_ref( elm_box_add(win._eo_ptr()) ));
110 bigbox.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
111 win.resize_object_add(bigbox._eo_ptr());
112 bigbox.visibility_set(true);
113
114 {
115 elm_box bx ( ::eo_ref( elm_box_add(win._eo_ptr()) ));
116 bx.horizontal_set(EINA_TRUE);
117 bigbox.pack_end(bx._eo_ptr());
118 bx.visibility_set(true);
119
120 {
121 elm_button bt ( ::eo_ref(elm_button_add(win._eo_ptr()) ));
122 bt.text_set("Add");
123 bx.pack_end(bt._eo_ptr());
124 bt.visibility_set(true);
125 evas_object_smart_callback_add(bt._eo_ptr(), "clicked", _add_cb, &tdata);
126 }
127
128 { 108 {
129 elm_button bt ( ::eo_ref(elm_button_add(win._eo_ptr()))); 109 elm_box{nullptr}
130 bt.text_set("Clear"); 110 , {}
131 bx.pack_end(bt._eo_ptr()); 111 , nullptr
132 bt.visibility_set(true); 112 };
133 evas_object_smart_callback_add(bt._eo_ptr(), "clicked", _clear_cb, &tdata);
134 }
135 }
136 113
137 { 114 {
138 elm_box bx ( ::eo_ref( elm_box_add(win._eo_ptr()))); 115 ::elm_win win (elm_win_util_standard_add("box-transition", "Box Transition"));
139 bx.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 116 win.autodel_set(true);
140 bx.size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL); 117
141 bigbox.pack_end(bx._eo_ptr()); 118 elm_box bigbox ( efl::eo::parent = win );
142 bx.visibility_set(true); 119 bigbox.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
143 120 win.resize_object_add(bigbox._eo_ptr());
144 { 121 bigbox.visibility_set(true);
145 elm_button bt ( ::eo_ref( elm_button_add(win._eo_ptr()) )); 122
146 bt.text_set("Button 1"); 123 elm_box buttons ( efl::eo::parent = win );
147 evas_object_smart_callback_add(bt._eo_ptr(), "clicked", _unpack_cb, &tdata); 124 buttons.horizontal_set(EINA_TRUE);
148 bt.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 125 bigbox.pack_end(buttons._eo_ptr());
149 bt.size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL); 126 buttons.visibility_set(true);
150 bx.pack_end(bt._eo_ptr()); 127
151 bt.visibility_set(true); 128 elm_button add ( efl::eo::parent = win );
152 } 129 add.text_set("Add");
153 130 buttons.pack_end(add._eo_ptr());
154 { 131 add.visibility_set(true);
155 elm_button bt ( ::eo_ref( elm_button_add(win._eo_ptr()) )); 132 evas_object_smart_callback_add(add._eo_ptr(), "clicked", _add_cb, &tdata);
156 bt.text_set("Button 2"); 133
157 bt.size_hint_weight_set(EVAS_HINT_EXPAND, 0.0); 134 elm_button clear ( efl::eo::parent = win );
158 bt.size_hint_align_set(1.0, 0.5); 135 clear.text_set("Clear");
159 evas_object_smart_callback_add(bt._eo_ptr(), "clicked", _unpack_cb, &tdata); 136 buttons.pack_end(clear._eo_ptr());
160 bx.pack_end(bt._eo_ptr()); 137 clear.visibility_set(true);
161 bt.visibility_set(true); 138 evas_object_smart_callback_add(clear._eo_ptr(), "clicked", _clear_cb, &tdata);
162 } 139
163 140 elm_box dynamic ( efl::eo::parent = win );
164 { 141 dynamic.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
165 elm_button bt ( ::eo_ref(elm_button_add(win._eo_ptr()))); 142 dynamic.size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL);
166 bt.text_set("Button 3"); 143 bigbox.pack_end(dynamic._eo_ptr());
167 evas_object_smart_callback_add(bt._eo_ptr(), "clicked", _unpack_cb, &tdata); 144 dynamic.visibility_set(true);
168 bx.pack_end(bt._eo_ptr()); 145
169 bt.visibility_set(true); 146 elm_button bt1 ( efl::eo::parent = win );
170 } 147 bt1.text_set("Button 1");
171 148 evas_object_smart_callback_add(bt1._eo_ptr(), "clicked", _unpack_cb, &tdata);
172 tdata.box = bx._eo_ptr(); 149 bt1.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
150 bt1.size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL);
151 dynamic.pack_end(bt1._eo_ptr());
152 bt1.visibility_set(true);
153
154 elm_button bt2 ( efl::eo::parent = win );
155 bt2.text_set("Button 2");
156 bt2.size_hint_weight_set(EVAS_HINT_EXPAND, 0.0);
157 bt2.size_hint_align_set(1.0, 0.5);
158 evas_object_smart_callback_add(bt2._eo_ptr(), "clicked", _unpack_cb, &tdata);
159 dynamic.pack_end(bt2._eo_ptr());
160 bt2.visibility_set(true);
161
162 elm_button bt3 ( efl::eo::parent = win );
163 bt3.text_set("Button 3");
164 evas_object_smart_callback_add(bt3._eo_ptr(), "clicked", _unpack_cb, &tdata);
165 dynamic.pack_end(bt3._eo_ptr());
166 bt3.visibility_set(true);
167
168 tdata.box = dynamic;
173 tdata.last_layout = evas_object_box_layout_horizontal; 169 tdata.last_layout = evas_object_box_layout_horizontal;
174 tdata.transitions = 170 tdata.transitions.push_back(evas_object_box_layout_vertical);
175 (eina_list_append(tdata.transitions, (void*)evas_object_box_layout_vertical)); 171 tdata.transitions.push_back(evas_object_box_layout_horizontal);
176 tdata.transitions = 172 tdata.transitions.push_back(evas_object_box_layout_stack);
177 (eina_list_append(tdata.transitions, (void*)evas_object_box_layout_horizontal)); 173 tdata.transitions.push_back(evas_object_box_layout_homogeneous_vertical);
178 tdata.transitions = 174 tdata.transitions.push_back(evas_object_box_layout_homogeneous_horizontal);
179 (eina_list_append(tdata.transitions, (void*)evas_object_box_layout_stack)); 175 tdata.transitions.push_back(evas_object_box_layout_flow_vertical);
180 tdata.transitions = 176 tdata.transitions.push_back(evas_object_box_layout_flow_horizontal);
181 (eina_list_append(tdata.transitions, (void*)evas_object_box_layout_homogeneous_vertical)); 177 tdata.transitions.push_back(evas_object_box_layout_stack);
182 tdata.transitions = 178
183 (eina_list_append(tdata.transitions, (void*)evas_object_box_layout_homogeneous_horizontal)); 179 dynamic.layout_set(evas_object_box_layout_horizontal, nullptr, nullptr);
184 tdata.transitions =
185 (eina_list_append(tdata.transitions, (void*)evas_object_box_layout_flow_vertical));
186 tdata.transitions =
187 (eina_list_append(tdata.transitions, (void*)evas_object_box_layout_flow_horizontal));
188 tdata.transitions =
189 (eina_list_append(tdata.transitions, (void*)evas_object_box_layout_stack));
190
191 bx.layout_set(evas_object_box_layout_horizontal, NULL, NULL);
192 _test_box_transition_change(&tdata); 180 _test_box_transition_change(&tdata);
193 }
194 181
195 win.size_set(300, 320); 182 win.size_set(300, 320);
196 win.visibility_set(true); 183 win.visibility_set(true);
184 win._release();
197 } 185 }
198 186
199 elm_run(); 187 elm_run();