summaryrefslogtreecommitdiff
path: root/src/examples/elementary
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-07-05 14:03:13 -0700
committerCedric Bail <cedric.bail@free.fr>2019-09-24 11:12:43 -0700
commit2e1317baedb844a490e96b574fcec3c1ef52c6d9 (patch)
tree881c05d1a268741e44cc296582b4c31d109db1d1 /src/examples/elementary
parent832d300e203621c9c32cb186fef16a529cc4306b (diff)
elementary: introduce Efl.Ui.CollectionView a generic listing View.
The idea of this widget is to provide to MVVM what Efl.Ui.Collection provide and leverage the same shared logic for layout. Co-authored-by: Mike Blumenkrantz <zmike@samsung.com> Co-authored-by: Marcel Hollerbach <mail@marcel-hollerbach.de> Differential Revision: https://phab.enlightenment.org/D9958
Diffstat (limited to 'src/examples/elementary')
-rw-r--r--src/examples/elementary/efl_ui_collection_view_example_1.c107
-rw-r--r--src/examples/elementary/meson.build1
2 files changed, 108 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 0000000..7296065
--- /dev/null
+++ b/src/examples/elementary/efl_ui_collection_view_example_1.c
@@ -0,0 +1,107 @@
1// gcc -o efl_ui_collection_view_example_1 efl_ui_collection_view_example_1.c `pkg-config --cflags --libs efl-ui
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
17static Efl_Model*
18_make_model(Evas_Object *win)
19{
20 Eina_Value vtext;
21 Efl_Generic_Model *model, *child;
22 unsigned int i;
23 char buf[256];
24
25 model = efl_add(EFL_GENERIC_MODEL_CLASS, win);
26 eina_value_setup(&vtext, EINA_VALUE_TYPE_STRING);
27
28 for (i = 0; i < (NUM_ITEMS); i++)
29 {
30 child = efl_model_child_add(model);
31 snprintf(buf, sizeof(buf), "Item # %i", i);
32 eina_value_set(&vtext, buf);
33 efl_model_property_set(child, "title", &vtext);
34 }
35
36 eina_value_flush(&vtext);
37 return model;
38}
39
40static void
41_item_constructing(void *data EINA_UNUSED, const Efl_Event *ev)
42{
43 Efl_Gfx_Entity *item = ev->info;
44
45 if (!efl_ui_item_calc_locked_get(item))
46 efl_gfx_hint_size_min_set(item, EINA_SIZE2D(50, 50));
47}
48
49EAPI_MAIN void
50efl_main(void *data EINA_UNUSED, const Efl_Event *ev)
51{
52 Efl_Ui_Factory *factory;
53 Evas_Object *win, *li;
54 Eo *model;
55 Eo *position_manager;
56 Efl_App *app = ev->object;
57 Eina_Accessor *ac;
58 Eina_Bool list = EINA_TRUE, multi = EINA_FALSE, none = EINA_FALSE;
59 Efl_Ui_Select_Mode mode = EFL_UI_SELECT_MODE_SINGLE;
60 const char *arg;
61 unsigned int i;
62
63 ac = efl_core_command_line_command_access(app);
64 EINA_ACCESSOR_FOREACH(ac, i, arg)
65 {
66 if (eina_streq(arg, "grid")) list = EINA_FALSE;
67 if (eina_streq(arg, "multi")) multi = EINA_TRUE;
68 if (eina_streq(arg, "none")) none = EINA_TRUE;
69 }
70 eina_accessor_free(ac);
71
72 if (multi) mode = EFL_UI_SELECT_MODE_MULTI;
73 if (none) mode = EFL_UI_SELECT_MODE_NONE;
74
75 win = efl_add(EFL_UI_WIN_CLASS, app,
76 efl_ui_win_type_set(efl_added, EFL_UI_WIN_TYPE_BASIC),
77 efl_ui_win_autohide_set(efl_added, EINA_TRUE));
78 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN);
79 model = _make_model(win);
80
81 factory = efl_add(EFL_UI_LAYOUT_FACTORY_CLASS, win);
82 efl_ui_property_bind(factory, "text", "title");
83
84 if (list)
85 {
86 position_manager = efl_new(EFL_UI_POSITION_MANAGER_LIST_CLASS);
87 efl_ui_widget_factory_item_class_set(factory, EFL_UI_LIST_DEFAULT_ITEM_CLASS);
88 }
89 else
90 {
91 position_manager = efl_new(EFL_UI_POSITION_MANAGER_GRID_CLASS);
92 efl_ui_widget_factory_item_class_set(factory, EFL_UI_GRID_DEFAULT_ITEM_CLASS);
93 efl_event_callback_add(factory, EFL_UI_FACTORY_EVENT_ITEM_CONSTRUCTING, _item_constructing, NULL);
94 }
95
96 li = efl_add(EFL_UI_COLLECTION_VIEW_CLASS, win,
97 efl_ui_collection_view_position_manager_set(efl_added, position_manager),
98 efl_ui_view_model_set(efl_added, model),
99 efl_ui_multi_selectable_async_select_mode_set(efl_added, mode),
100 efl_ui_collection_view_factory_set(efl_added, factory));
101
102 efl_content_set(win, li);
103
104 //showall
105 efl_gfx_entity_size_set(win, EINA_SIZE2D(320, 320));
106}
107EFL_MAIN()
diff --git a/src/examples/elementary/meson.build b/src/examples/elementary/meson.build
index 53d1213..5348929 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',