From 668fae61d9066dadda9437ae0aeb55e5ef736928 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Andre Date: Thu, 2 Nov 2017 18:42:09 +0900 Subject: [PATCH] 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. --- unsorted/elementary/button_cxx_example_00.cc | 61 ++++++++++---------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/unsorted/elementary/button_cxx_example_00.cc b/unsorted/elementary/button_cxx_example_00.cc index 037a1565..30c58d84 100644 --- a/unsorted/elementary/button_cxx_example_00.cc +++ b/unsorted/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 +#include -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 on_click = std::bind([] () { elm_exit(); }); + auto bt = efl::ui::Button(instantiate, win); + bt.text_set("Hello world!"); + box.pack(bt); - efl::eolian::event_add(efl::ui::Clickable::clicked_event, btn, on_click); + 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); - win.eo_cxx::efl::Gfx::size_set({240, 60}); - win.visible_set(true); + auto bt2 = efl::ui::Button(instantiate, win); + bt2.text_set("Click to quit"); + box.pack(bt2); - elm_run(); - return 0; + 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); + + win.size_set({320,160}); } -ELM_MAIN() +EFL_MAIN()