summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-08-23 23:40:46 -0700
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-09-10 10:08:08 +0200
commit449424d85a2247ce9959c26651256ad61e252e70 (patch)
tree46f2a7140b1de7e923957f727f16240dd19244c5
parentbfb6bc40b21c60a536349d65d4b7e9ab327fb173 (diff)
elementary: add an example to test Efl.Ui.CollectionView.
-rw-r--r--src/examples/elementary/efl_ui_collection_view_example_1.c115
-rw-r--r--src/examples/elementary/meson.build1
2 files changed, 116 insertions, 0 deletions
diff --git a/src/examples/elementary/efl_ui_collection_view_example_1.c b/src/examples/elementary/efl_ui_collection_view_example_1.c
new file mode 100644
index 0000000000..f4e91279c8
--- /dev/null
+++ b/src/examples/elementary/efl_ui_collection_view_example_1.c
@@ -0,0 +1,115 @@
1// gcc -o efl_ui_list_view_example_1 efl_ui_list_view_example_1.c `pkg-config --cflags --libs elementary`
2
3#ifdef HAVE_CONFIG_H
4# include "elementary_config.h"
5#else
6# define EFL_BETA_API_SUPPORT 1
7#endif
8
9#include <Efl_Ui.h>
10#include <Elementary.h>
11#include <Efl.h>
12#include <Eio.h>
13#include <stdio.h>
14
15#define NUM_ITEMS 400
16
17const char *styles[] = {
18 "odd",
19 "even"
20 };
21
22char edj_path[PATH_MAX];
23
24static void
25_realized_cb(void *data EINA_UNUSED, const Efl_Event *event)
26{
27 Efl_Ui_List_View_Item_Event *ie = event->info;
28 if (!ie->layout) return;
29
30 Efl_Ui_Layout *layout = ie->layout;
31 elm_object_focus_allow_set(layout, EINA_TRUE);
32}
33
34/*
35static void
36_unrealized_cb(void *data EINA_UNUSED, const Efl_Event *event)
37{
38 Efl_Ui_List_View_Item_Event *ie = event->info;
39
40 efl_ui_view_model_set(ie->layout, NULL);
41 efl_del(ie->layout);
42}
43*/
44static Efl_Model*
45_make_model(Evas_Object *win)
46{
47 Eina_Value vtext;
48 Efl_Generic_Model *model, *child;
49 unsigned int i, s;
50 char buf[256];
51
52 model = efl_add(EFL_GENERIC_MODEL_CLASS, win);
53 eina_value_setup(&vtext, EINA_VALUE_TYPE_STRING);
54
55 for (i = 0; i < (NUM_ITEMS); i++)
56 {
57 s = i%2;
58 child = efl_model_child_add(model);
59 eina_value_set(&vtext, styles[s]);
60 efl_model_property_set(child, "odd_style", &vtext);
61
62 snprintf(buf, sizeof(buf), "Item # %i", i);
63 eina_value_set(&vtext, buf);
64 efl_model_property_set(child, "title", &vtext);
65 }
66
67 eina_value_flush(&vtext);
68 return model;
69}
70
71EAPI_MAIN int
72elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
73{
74 Efl_Ui_Factory *factory;
75 Evas_Object *win, *li;
76 Eo *model;
77 Efl_Select_Model *selmodel;
78
79 win = elm_win_util_standard_add("list_view", "List_View");
80 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
81
82 elm_win_autodel_set(win, EINA_TRUE);
83
84 model = _make_model(win);
85 selmodel = efl_add(EFL_SELECT_MODEL_CLASS, efl_main_loop_get()
86 , efl_ui_view_model_set(efl_added, model)
87 );
88
89 factory = efl_add(EFL_UI_LAYOUT_FACTORY_CLASS, win);
90 efl_ui_widget_factory_item_class_set(factory, EFL_UI_LIST_DEFAULT_ITEM_CLASS);
91 efl_ui_property_bind(factory, "signal/efl,state,%v", "odd_style");
92 efl_ui_property_bind(factory, "signal/efl,state,%{selected;unselected}", "selected");
93 efl_ui_property_bind(factory, "efl.text", "title");
94
95 li = efl_add(EFL_UI_COLLECTION_VIEW_CLASS, win,
96 efl_ui_view_model_set(efl_added, selmodel));
97 efl_ui_collection_view_position_manager_set(li, efl_new(EFL_UI_POSITION_MANAGER_LIST_CLASS));
98
99 // efl_event_callback_add(li, EFL_UI_LIST_VIEW_EVENT_ITEM_REALIZED, _realized_cb, NULL);
100 // efl_event_callback_add(li, EFL_UI_LIST_VIEW_EVENT_ITEM_UNREALIZED, _unrealized_cb, NULL);
101
102 elm_win_resize_object_add(win, li);
103 evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
104 evas_object_size_hint_align_set(li, EVAS_HINT_FILL, EVAS_HINT_FILL);
105
106 //showall
107 evas_object_show(li);
108 evas_object_resize(win, 320, 320);
109 evas_object_show(win);
110
111 elm_run();
112
113 return 0;
114}
115ELM_MAIN()
diff --git a/src/examples/elementary/meson.build b/src/examples/elementary/meson.build
index 53d1213d4c..53489299cb 100644
--- a/src/examples/elementary/meson.build
+++ b/src/examples/elementary/meson.build
@@ -114,6 +114,7 @@ examples = [
114 'efl_ui_list_view_example_1', 114 'efl_ui_list_view_example_1',
115 'efl_ui_list_view_example_2', 115 'efl_ui_list_view_example_2',
116 'efl_ui_list_view_example_3', 116 'efl_ui_list_view_example_3',
117 'efl_ui_collection_view_example_1',
117 'efl_canvas_layout_text', 118 'efl_canvas_layout_text',
118 'efl_ui_theme_example_01', 119 'efl_ui_theme_example_01',
119 'efl_ui_theme_example_02', 120 'efl_ui_theme_example_02',