summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2014-07-17 16:52:41 -0300
committerSavio Sena <savio@expertisesolutions.com.br>2014-07-21 20:53:12 -0300
commit24b191a738e750b97ebc468d24ef68093db1858e (patch)
treeffbcd8d2c52f7b5bc944ee6f5d0577886748b563
parent109cd2e79985a076233e39844e83d218034218c4 (diff)
cxx: Changed C++ example to use lambdas
-rw-r--r--src/examples/box_cxx_example_02.cc158
1 files changed, 69 insertions, 89 deletions
diff --git a/src/examples/box_cxx_example_02.cc b/src/examples/box_cxx_example_02.cc
index bb2a3db81..b1f7bc951 100644
--- a/src/examples/box_cxx_example_02.cc
+++ b/src/examples/box_cxx_example_02.cc
@@ -28,88 +28,43 @@
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> 31#include <Eina.hh>
32
33typedef struct
34{
35 efl::eo::wref<elm_box> box;
36 std::deque<Evas_Object_Box_Layout> transitions;
37 Evas_Object_Box_Layout last_layout;
38} Transitions_Data;
39
40static void
41_add_cb(void *data, Evas_Object *obj, void *ev)
42{
43 Eina_List *children;
44 Transitions_Data *tdata = static_cast<Transitions_Data*>(data);
45
46 if(efl::eina::optional<elm_box> box = tdata->box.lock())
47 {
48 elm_button btn ( efl::eo::parent = *box );
49 btn.text_set("I do nothing");
50 efl::eina::list<efl::eo::base> childrens (box->children_get());
51 if (!children.empty())
52 {
53 box->pack_after(btn._eo_ptr(), childrens.front());
54 }
55 else
56 box->pack_end(btn._eo_ptr());
57 btn.visibility_set(true);
58 }
59}
60 32
61static void 33#include <deque>
62_clear_cb(void *data, Evas_Object *obj, void *ev)
63{
64 Transitions_Data *tdata = static_cast<Transitions_Data*>(data);
65 tdata->box.lock()->clear();
66}
67
68static void
69_unpack_cb(void *data, Evas_Object *obj, void *ev)
70{
71 Transitions_Data *tdata = static_cast<Transitions_Data*>(data);
72 tdata->box.lock()->unpack(obj);
73 evas_object_move(obj, 0, 50);
74 evas_object_color_set(obj, 128, 64, 0, 128);
75}
76 34
77static void 35// static void
78_test_box_transition_change(void *data) 36// _test_box_transition_change(void *data)
79{ 37// {
80 Transitions_Data *tdata = static_cast<Transitions_Data*>(data); 38// Transitions_Data *tdata = static_cast<Transitions_Data*>(data);
81 Elm_Box_Transition *layout_data; 39// Elm_Box_Transition *layout_data;
82 Evas_Object_Box_Layout next_layout; 40// Evas_Object_Box_Layout next_layout;
83 41
84 assert (!!data); 42// assert (!!data);
85 assert (!tdata->transitions.empty()); 43// assert (!tdata->transitions.empty());
86 44
87 if(efl::eina::optional<elm_box> box = tdata->box.lock()) 45// if(efl::eina::optional<elm_box> box = tdata->box.lock())
88 { 46// {
89 next_layout = tdata->transitions.front(); 47// next_layout = tdata->transitions.front();
90 layout_data = elm_box_transition_new(2.0, tdata->transitions.back(), 48// layout_data = elm_box_transition_new(2.0, tdata->transitions.back(),
91 nullptr, nullptr, next_layout, nullptr, nullptr, 49// nullptr, nullptr, next_layout, nullptr, nullptr,
92 _test_box_transition_change, tdata); 50// _test_box_transition_change, tdata);
93 box->layout_set(elm_box_layout_transition, layout_data, 51// box->layout_set(elm_box_layout_transition, layout_data,
94 elm_box_transition_free); 52// elm_box_transition_free);
95 tdata->last_layout = next_layout; 53// tdata->last_layout = next_layout;
96 54
97 tdata->transitions.push_back(tdata->transitions[0]); 55// tdata->transitions.push_back(tdata->transitions[0]);
98 tdata->transitions.pop_front(); 56// tdata->transitions.pop_front();
99 } 57// }
100} 58// }
101 59
102EAPI_MAIN int 60EAPI_MAIN int
103elm_main(int argc, char *argv[]) 61elm_main(int argc, char *argv[])
104{ 62{
105 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); 63 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
106 64
107 Transitions_Data tdata 65 efl::eo::wref<elm_box> weak_box;
108 { 66 std::deque<Evas_Object_Box_Layout> transitions;
109 elm_box{nullptr} 67 Evas_Object_Box_Layout last_layout;
110 , {}
111 , nullptr
112 };
113 68
114 { 69 {
115 ::elm_win win (elm_win_util_standard_add("box-transition", "Box Transition")); 70 ::elm_win win (elm_win_util_standard_add("box-transition", "Box Transition"));
@@ -129,13 +84,29 @@ elm_main(int argc, char *argv[])
129 add.text_set("Add"); 84 add.text_set("Add");
130 buttons.pack_end(add._eo_ptr()); 85 buttons.pack_end(add._eo_ptr());
131 add.visibility_set(true); 86 add.visibility_set(true);
132 evas_object_smart_callback_add(add._eo_ptr(), "clicked", _add_cb, &tdata); 87 add.event_clicked_callback_add
88 (std::bind([&weak_box]
89 {
90 if(efl::eina::optional<elm_box> box = weak_box.lock())
91 {
92 elm_button btn ( efl::eo::parent = *box );
93 btn.text_set("I do nothing");
94 efl::eina::range_list<efl::eo::base> childrens (box->children_get());
95 if (!childrens.empty())
96 {
97 box->pack_after(btn._eo_ptr(), childrens.front()._eo_ptr());
98 }
99 else
100 box->pack_end(btn._eo_ptr());
101 btn.visibility_set(true);
102 }
103 }));
133 104
134 elm_button clear ( efl::eo::parent = win ); 105 elm_button clear ( efl::eo::parent = win );
135 clear.text_set("Clear"); 106 clear.text_set("Clear");
136 buttons.pack_end(clear._eo_ptr()); 107 buttons.pack_end(clear._eo_ptr());
137 clear.visibility_set(true); 108 clear.visibility_set(true);
138 evas_object_smart_callback_add(clear._eo_ptr(), "clicked", _clear_cb, &tdata); 109 clear.event_clicked_callback_add(std::bind([&weak_box] { weak_box.lock()->clear(); }));
139 110
140 elm_box dynamic ( efl::eo::parent = win ); 111 elm_box dynamic ( efl::eo::parent = win );
141 dynamic.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 112 dynamic.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
@@ -143,9 +114,18 @@ elm_main(int argc, char *argv[])
143 bigbox.pack_end(dynamic._eo_ptr()); 114 bigbox.pack_end(dynamic._eo_ptr());
144 dynamic.visibility_set(true); 115 dynamic.visibility_set(true);
145 116
117 auto unpack = std::bind([&weak_box] (evas::clickable_interface obj)
118 {
119 weak_box.lock()->unpack(obj._eo_ptr());
120 elm_button btn = efl::eo::downcast<elm_button>(obj);
121 btn.position_set(0, 50);
122 btn.color_set(128, 64, 0, 128);
123 }, std::placeholders::_1)
124 ;
125
146 elm_button bt1 ( efl::eo::parent = win ); 126 elm_button bt1 ( efl::eo::parent = win );
147 bt1.text_set("Button 1"); 127 bt1.text_set("Button 1");
148 evas_object_smart_callback_add(bt1._eo_ptr(), "clicked", _unpack_cb, &tdata); 128 bt1.event_clicked_callback_add(unpack);
149 bt1.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 129 bt1.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
150 bt1.size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL); 130 bt1.size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL);
151 dynamic.pack_end(bt1._eo_ptr()); 131 dynamic.pack_end(bt1._eo_ptr());
@@ -155,29 +135,29 @@ elm_main(int argc, char *argv[])
155 bt2.text_set("Button 2"); 135 bt2.text_set("Button 2");
156 bt2.size_hint_weight_set(EVAS_HINT_EXPAND, 0.0); 136 bt2.size_hint_weight_set(EVAS_HINT_EXPAND, 0.0);
157 bt2.size_hint_align_set(1.0, 0.5); 137 bt2.size_hint_align_set(1.0, 0.5);
158 evas_object_smart_callback_add(bt2._eo_ptr(), "clicked", _unpack_cb, &tdata); 138 bt2.event_clicked_callback_add(unpack);
159 dynamic.pack_end(bt2._eo_ptr()); 139 dynamic.pack_end(bt2._eo_ptr());
160 bt2.visibility_set(true); 140 bt2.visibility_set(true);
161 141
162 elm_button bt3 ( efl::eo::parent = win ); 142 elm_button bt3 ( efl::eo::parent = win );
163 bt3.text_set("Button 3"); 143 bt3.text_set("Button 3");
164 evas_object_smart_callback_add(bt3._eo_ptr(), "clicked", _unpack_cb, &tdata); 144 bt3.event_clicked_callback_add(unpack);
165 dynamic.pack_end(bt3._eo_ptr()); 145 dynamic.pack_end(bt3._eo_ptr());
166 bt3.visibility_set(true); 146 bt3.visibility_set(true);
167 147
168 tdata.box = dynamic; 148 weak_box = dynamic;
169 tdata.last_layout = evas_object_box_layout_horizontal; 149 last_layout = evas_object_box_layout_horizontal;
170 tdata.transitions.push_back(evas_object_box_layout_vertical); 150 transitions.push_back(evas_object_box_layout_vertical);
171 tdata.transitions.push_back(evas_object_box_layout_horizontal); 151 transitions.push_back(evas_object_box_layout_horizontal);
172 tdata.transitions.push_back(evas_object_box_layout_stack); 152 transitions.push_back(evas_object_box_layout_stack);
173 tdata.transitions.push_back(evas_object_box_layout_homogeneous_vertical); 153 transitions.push_back(evas_object_box_layout_homogeneous_vertical);
174 tdata.transitions.push_back(evas_object_box_layout_homogeneous_horizontal); 154 transitions.push_back(evas_object_box_layout_homogeneous_horizontal);
175 tdata.transitions.push_back(evas_object_box_layout_flow_vertical); 155 transitions.push_back(evas_object_box_layout_flow_vertical);
176 tdata.transitions.push_back(evas_object_box_layout_flow_horizontal); 156 transitions.push_back(evas_object_box_layout_flow_horizontal);
177 tdata.transitions.push_back(evas_object_box_layout_stack); 157 transitions.push_back(evas_object_box_layout_stack);
178 158
179 dynamic.layout_set(evas_object_box_layout_horizontal, nullptr, nullptr); 159 dynamic.layout_set(evas_object_box_layout_horizontal, nullptr, nullptr);
180 _test_box_transition_change(&tdata); 160 // _test_box_transition_change(&tdata);
181 161
182 win.size_set(300, 320); 162 win.size_set(300, 320);
183 win.visibility_set(true); 163 win.visibility_set(true);