summaryrefslogtreecommitdiff
path: root/src/examples/hoversel_cxx_example_01.cc
diff options
context:
space:
mode:
authorLuciana Magno de Almeida <luciana@expertisesolutions.com.br>2014-12-16 19:04:43 -0200
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-08-25 03:42:34 -0300
commitcf4d84c85b48d32fd85deeafdc7aee4543875725 (patch)
tree0c5c7a61507819bff113eb8ee8883c7026f33465 /src/examples/hoversel_cxx_example_01.cc
parentdfb979950cfcebc21d1b0e933d4f02ab2084e304 (diff)
cxx: Added examples and tutorial for C++ binding
Summary: Added the following examples: * bg_cxx_example_01 * bg_cxx_example_02 * bubble_cxx_example_01 * button_cxx_example_00 * button_cxx_example_01 * calendar_cxx_example_01 * calendar_cxx_example_02 * calendar_cxx_example_03 * calendar_cxx_example_04 * calendar_cxx_example_05 * clock_cxx_example * datetime_cxx_example * glview_cxx_example_01 * hoversel_cxx_example_01 * icon_cxx_example_01 * location_cxx_example_01 * menu_cxx_example_01 * popup_cxx_example_01 * radio_cxx_example_01 * separator_cxx_example_01 * slider_cxx_example * spinner_cxx_example * table_cxx_example_01 * table_cxx_example_02 * thumb_cxx_example_01 Added documentation for the above examples, as well as how using lambdas with C++ elm binding. How to use autohide feature and how to use the C++ wrappers to create windows, widgets and call Eo functions from them with automatic C++ type conversion and how to use signals from C++.
Diffstat (limited to 'src/examples/hoversel_cxx_example_01.cc')
-rw-r--r--src/examples/hoversel_cxx_example_01.cc84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/examples/hoversel_cxx_example_01.cc b/src/examples/hoversel_cxx_example_01.cc
new file mode 100644
index 0000000..776d92a
--- /dev/null
+++ b/src/examples/hoversel_cxx_example_01.cc
@@ -0,0 +1,84 @@
1#include <Elementary.hh>
2#include <Eina.hh>
3#include <Evas.hh>
4
5static void _print_items(void *data, Evas_Object *obj, void *event_info);
6static void _free(void *data, Evas_Object *obj, void *event_info);
7
8EAPI_MAIN int
9elm_main (int argc, char *argv[])
10{
11 efl::eina::eina_init eina_init;
12
13 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN);
14
15 ::elm::win_standard win;
16 win.title_set("Hoversel");
17 win.autohide_set(true);
18
19 evas::rectangle rect(efl::eo::parent = win);
20 rect.color_set(255, 0, 0, 255);
21 rect.visible_set(true);
22
23 ::elm::hoversel hoversel(efl::eo::parent = win);
24 hoversel.horizontal_set(false);
25 hoversel.text_set("elm.text", "Add an item to Hoversel");
26 hoversel.content_set(nullptr, rect);
27
28 hoversel.item_add("Print items", nullptr, ELM_ICON_NONE, &_print_items, NULL);
29 hoversel.item_add( "Option 2", "home", ELM_ICON_STANDARD, NULL,NULL);
30
31 auto add_item = std::bind([] (::elm::hoversel obj)
32 {
33 static int num = 0;
34 char *str = new char[sizeof(char) * 10];
35
36 snprintf(str, 10, "item %d", ++num);
37
38 elm::widget_item hoversel_item = obj.item_add(str, nullptr, ELM_ICON_NONE, NULL, str);
39 elm_object_item_del_cb_set(hoversel_item._eo_ptr(), &_free);
40 }, std::placeholders::_1);
41
42 hoversel.callback_clicked_add(add_item);
43
44 hoversel.size_set(180, 30);
45 hoversel.position_set( 10, 10);
46 hoversel.visible_set(true);
47
48 ::elm::button btn(efl::eo::parent = win);
49 btn.text_set("elm.text", "Clear all Items");
50
51 auto clear_btn_clicked = std::bind([&] () { hoversel.clear(); });
52
53 btn.callback_clicked_add(clear_btn_clicked);
54 btn.size_set(180, 30);
55 btn.position_set(10, 50);
56 btn.visible_set(true);
57
58 win.size_set(200, 300);
59 win.visible_set(true);
60
61 elm_run();
62
63 return 0;
64}
65ELM_MAIN()
66
67static void
68_print_items(void *data, Evas_Object *obj, void *event_info)
69{
70 efl::eina::range_list<const elm::hoversel_item> items(elm_hoversel_items_get(obj));
71
72 for (auto i : items)
73 try
74 {
75 std::cout << i.part_text_get(nullptr) << std::endl;
76 }
77 catch (std::logic_error const&) {}
78}
79
80static void
81_free(void *data, Evas_Object *obj, void *event_info)
82{
83 delete[] static_cast<char *>(data);
84}