summaryrefslogtreecommitdiff
path: root/src/bin/elementary/test_ui_collection_view.c
diff options
context:
space:
mode:
authorCedric Bail <cedric.bail@free.fr>2019-09-20 15:01:49 -0700
committerCedric Bail <cedric.bail@free.fr>2019-09-24 11:12:46 -0700
commitd5a21c7998f9f4a4901a49b874ff1e2dec3c3c08 (patch)
treef53d9b8a03de52ffda5c0dda74d176605ff8c59b /src/bin/elementary/test_ui_collection_view.c
parent5096cd32ad580cfc8fa58c130b378b111112855a (diff)
elementary: add a basic test for MVVM infrastructure.
Differential Revision: https://phab.enlightenment.org/D10063
Diffstat (limited to '')
-rw-r--r--src/bin/elementary/test_ui_collection_view.c144
1 files changed, 144 insertions, 0 deletions
diff --git a/src/bin/elementary/test_ui_collection_view.c b/src/bin/elementary/test_ui_collection_view.c
new file mode 100644
index 0000000..4a3f2f7
--- /dev/null
+++ b/src/bin/elementary/test_ui_collection_view.c
@@ -0,0 +1,144 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#include <Efl_Ui.h>
6#include <Elementary.h>
7
8#define NUM_ITEMS 50
9
10static Efl_Model*
11_make_model(Efl_Ui_Win *win)
12{
13 Eina_Value vi;
14 Efl_Generic_Model *model, *child;
15 unsigned int i;
16
17 model = efl_add(EFL_GENERIC_MODEL_CLASS, win);
18 model = efl_add(EFL_UI_VIEW_MODEL_CLASS, model,
19 efl_ui_view_model_set(efl_added, model));
20 eina_value_setup(&vi, EINA_VALUE_TYPE_INT);
21
22 efl_ui_view_model_property_string_add(model, "relative", "Relative index ${child.index}", "WRONG", "WRONG");
23 efl_ui_view_model_property_string_add(model, "title", "Initial index ${initial}", "WRONG", "WRONG");
24
25
26 for (i = 0; i < (NUM_ITEMS); i++)
27 {
28 child = efl_model_child_add(model);
29 eina_value_set(&vi, i);
30 efl_model_property_set(child, "initial", &vi);
31 }
32
33 eina_value_flush(&vi);
34 return model;
35}
36
37static void
38_item_constructing(void *data EINA_UNUSED, const Efl_Event *ev)
39{
40 Efl_Gfx_Entity *item = ev->info;
41
42 if (!efl_ui_item_calc_locked_get(item))
43 efl_gfx_hint_size_min_set(item, EINA_SIZE2D(100, 50));
44}
45
46static void
47_item_select(void *data, const Efl_Event *ev)
48{
49 Efl_Ui_Widget *w = efl_ui_single_selectable_last_selected_get(ev->object);
50 Efl_Model *m = efl_ui_view_model_get(w);
51
52 if (m) efl_ui_view_model_set(data, m);
53}
54
55void test_efl_ui_collection_view(void *data EINA_UNUSED,
56 Evas_Object *obj EINA_UNUSED,
57 void *event_info EINA_UNUSED)
58{
59 Efl_Ui_Win *win;
60 Efl_Model *model;
61 Efl_Ui_Frame *f;
62 Efl_Ui_Table *tbl;
63 Efl_Ui_List_View *lv;
64 Efl_Ui_Grid_View *gv;
65 Efl_Ui_Factory *fg, *fl;
66 Efl_Ui_Box *ib;
67 Efl_Ui_Widget *o;
68 Efl_Model_Provider *provider;
69
70 win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
71 efl_ui_win_type_set(efl_added, EFL_UI_WIN_TYPE_BASIC),
72 efl_text_set(efl_added, "Efl.Ui.Collection_View"),
73 efl_ui_win_autodel_set(efl_added, EINA_TRUE));
74 tbl = efl_add(EFL_UI_TABLE_CLASS, win,
75 efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(500, 300)));
76 efl_content_set(win, tbl);
77
78 model = _make_model(win);
79 fg = efl_add(EFL_UI_LAYOUT_FACTORY_CLASS, win,
80 efl_ui_property_bind(efl_added, "text", "title"),
81 efl_ui_widget_factory_item_class_set(efl_added, EFL_UI_GRID_DEFAULT_ITEM_CLASS));
82 efl_event_callback_add(fg, EFL_UI_FACTORY_EVENT_ITEM_CONSTRUCTING, _item_constructing, NULL);
83 fl = efl_add(EFL_UI_LAYOUT_FACTORY_CLASS, win,
84 efl_ui_property_bind(efl_added, "text", "title"),
85 efl_ui_widget_factory_item_class_set(efl_added, EFL_UI_LIST_DEFAULT_ITEM_CLASS));
86 provider = efl_add(EFL_MODEL_PROVIDER_CLASS, win);
87
88 lv = efl_add(EFL_UI_LIST_VIEW_CLASS, tbl,
89 efl_ui_collection_view_factory_set(efl_added, fl),
90 efl_ui_view_model_set(efl_added, model));
91 efl_pack_table(tbl, lv, 0, 1, 1, 1);
92
93 gv = efl_add(EFL_UI_GRID_VIEW_CLASS, tbl,
94 efl_ui_collection_view_factory_set(efl_added, fg),
95 efl_ui_view_model_set(efl_added, model));
96 efl_pack_table(tbl, gv, 2, 1, 1, 1);
97
98 f = efl_add(EFL_UI_FRAME_CLASS, tbl,
99 efl_text_set(efl_added, "Selected item"),
100 efl_ui_frame_autocollapse_set(efl_added, EINA_FALSE));
101 efl_provider_register(f, EFL_MODEL_PROVIDER_CLASS, provider);
102 efl_pack_table(tbl, f, 1, 1, 1, 1);
103 efl_event_callback_add(lv, EFL_UI_SINGLE_SELECTABLE_EVENT_SELECTION_CHANGED, _item_select, provider);
104
105 ib = efl_add(EFL_UI_BOX_CLASS, f,
106 efl_gfx_hint_align_set(efl_added, EVAS_HINT_FILL, EVAS_HINT_FILL),
107 efl_gfx_hint_weight_set(efl_added, 1, 1),
108 efl_gfx_hint_fill_set(efl_added, EINA_TRUE, EINA_TRUE),
109 efl_content_set(f, efl_added));
110
111 o = elm_label_add(ib);
112 elm_object_text_set(o, "title:");
113 efl_gfx_hint_weight_set(o, 1, 0);
114 efl_gfx_hint_align_set(o, 0.5, 1.0);
115 efl_gfx_hint_aspect_set(o, EFL_GFX_HINT_ASPECT_BOTH, EINA_SIZE2D(1, 1));
116 efl_pack(ib, o);
117 efl_gfx_entity_visible_set(o, 1);
118
119 o = elm_label_add(ib);
120 elm_object_text_set(o, "NONE");
121 efl_ui_property_bind(o, "elm.text", "title");
122 efl_gfx_hint_weight_set(o, 1, 0);
123 efl_gfx_hint_align_set(o, 0.5, 1.0);
124 efl_gfx_hint_aspect_set(o, EFL_GFX_HINT_ASPECT_BOTH, EINA_SIZE2D(1, 1));
125 efl_pack(ib, o);
126 efl_gfx_entity_visible_set(o, 1);
127
128 o = elm_label_add(ib);
129 elm_object_text_set(o, "relative:");
130 efl_gfx_hint_weight_set(o, 1, 0);
131 efl_gfx_hint_align_set(o, 0.5, 1.0);
132 efl_gfx_hint_aspect_set(o, EFL_GFX_HINT_ASPECT_BOTH, EINA_SIZE2D(1, 1));
133 efl_pack(ib, o);
134 efl_gfx_entity_visible_set(o, 1);
135
136 o = elm_label_add(ib);
137 elm_object_text_set(o, "NONE");
138 efl_ui_property_bind(o, "elm.text", "relative");
139 efl_gfx_hint_weight_set(o, 1, 0);
140 efl_gfx_hint_align_set(o, 0.5, 1.0);
141 efl_gfx_hint_aspect_set(o, EFL_GFX_HINT_ASPECT_BOTH, EINA_SIZE2D(1, 1));
142 efl_pack(ib, o);
143 efl_gfx_entity_visible_set(o, 1);
144}