jpeg pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=d4c92b39df3662064be0c002fd6ae2e181f64b75
commit d4c92b39df3662064be0c002fd6ae2e181f64b75 Author: Jean-Philippe Andre <[email protected]> Date: Thu Nov 2 18:42:09 2017 +0900 cxx: Modify button example with wref This is more of an experiment than anything else. @felipealmeida I would like to know what you think. Notes: - events still need a better API (event_add isn't part of the object definition...). - references are an issue, when you want to actually delete an object. --- src/examples/elementary/button_cxx_example_00.cc | 61 ++++++++++++------------ 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/src/examples/elementary/button_cxx_example_00.cc b/src/examples/elementary/button_cxx_example_00.cc index 037a15654b..30c58d84cd 100644 --- a/src/examples/elementary/button_cxx_example_00.cc +++ b/src/examples/elementary/button_cxx_example_00.cc @@ -1,44 +1,43 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#include "elementary_config.h" -#endif +// g++ -g `pkg-config --cflags --libs elementary-cxx efl-cxx eina-cxx eo-cxx ecore-cxx evas-cxx edje-cxx` button_cxx_example_00.cc -o button_cxx_example_00 +#define EFL_CXX_WREF_EASY #include <Elementary.hh> +#include <iostream> -EAPI_MAIN int -elm_main (int argc EINA_UNUSED, char **argv EINA_UNUSED) +using efl::eo::instantiate; + +static void +efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED) { elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN); - using efl::eo::instantiate; - - efl::ui::Win win(instantiate); -// //win.title_set("Hello, World!"); -// win.autohide_set(true); - -// ::elm::Button btn(win); -// btn.text_set("elm.text","Good-Bye, World!"); -// btn.eo_cxx::efl::Gfx::size_set(120, 30); -// btn.eo_cxx::efl::Gfx::position_set(60, 15); -// // btn.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); -// // btn.size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL); - // win.title_set("Hello, World!"); + auto win = efl::ui::Win(instantiate); + win.text_set("Button Example"); win.autohide_set(true); - efl::ui::Button btn(instantiate, win); - btn.text_set("Good-Bye, World!"); - btn.eo_cxx::efl::Gfx::size_set({120, 30}); - btn.eo_cxx::efl::Gfx::position_set({60, 15}); - btn.visible_set(true); + auto box = efl::ui::Box(instantiate, win); + win.content_set(box); + + auto bt = efl::ui::Button(instantiate, win); + bt.text_set("Hello world!"); + box.pack(bt); - auto on_click = std::bind([] () { elm_exit(); }); + auto wbt = bt._get_wref(); + auto cb = std::bind([wbt]() { + std::cout << wbt->text_get() << std::endl; + }); + efl::eolian::event_add(efl::ui::Clickable::clicked_event, bt, cb); - efl::eolian::event_add(efl::ui::Clickable::clicked_event, btn, on_click); + auto bt2 = efl::ui::Button(instantiate, win); + bt2.text_set("Click to quit"); + box.pack(bt2); - win.eo_cxx::efl::Gfx::size_set({240, 60}); - win.visible_set(true); + auto wwin = win._get_wref(); + auto cb2 = std::bind([wwin]() { + ::efl_del(wwin->_eo_ptr()); // FIXME: No proper C++ API to delete win + }); + efl::eolian::event_add(efl::ui::Clickable::clicked_event, bt2, cb2); - elm_run(); - return 0; + win.size_set({320,160}); } -ELM_MAIN() +EFL_MAIN() --
