summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-06-29 16:19:08 +0200
committerCedric BAIL <cedric.bail@free.fr>2019-07-24 10:38:22 -0700
commit577b82dad69c7f07856cbb254fcc60aab6f90999 (patch)
tree6292ee6c022553d826026362f33fc692f8f67e2c /src/bin
parent0cd5427c3f556135fffff79193fb03de6036eab4 (diff)
Introduce Efl.Ui.Item_Container
this is a new widget which aims to replace Efl.Ui.Grid / Efl.Ui.List. The widget is split up in a widget and a interface for item placement. Efl_Ui_Item_Position_Manager: The interface contains API which is used by the Item_Container to place the items, there is also a set of common tests which tests for the casual tripping wires, and ensures that the events are emitted in the correct moments (the later part still can be improved) Efl_Ui_Item_Container: The widget itself, it contains the API for the enduser to add Items to the widget, it handles the different modes for selection type and emits the events for selection changes. The pack API is conform with the spec unit test. An additional set of tests is defined which should be able to be run on every widget with a specific position_manager beeing set. Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Reviewed-by: Cedric BAIL <cedric.bail@free.fr> Differential Revision: https://phab.enlightenment.org/D9285
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/elementary/meson.build1
-rw-r--r--src/bin/elementary/test.c5
-rw-r--r--src/bin/elementary/test_ui_item_container.c272
3 files changed, 277 insertions, 1 deletions
diff --git a/src/bin/elementary/meson.build b/src/bin/elementary/meson.build
index 96b6e906a0..10372d9154 100644
--- a/src/bin/elementary/meson.build
+++ b/src/bin/elementary/meson.build
@@ -156,6 +156,7 @@ elementary_test_src = [
156 'test_gesture_framework.c', 156 'test_gesture_framework.c',
157 'test_ui_tab_pager.c', 157 'test_ui_tab_pager.c',
158 'test_ui_relative_layout.c', 158 'test_ui_relative_layout.c',
159 'test_ui_item_container.c',
159 'test.h' 160 'test.h'
160] 161]
161 162
diff --git a/src/bin/elementary/test.c b/src/bin/elementary/test.c
index b751d65321..2062f18acb 100644
--- a/src/bin/elementary/test.c
+++ b/src/bin/elementary/test.c
@@ -394,7 +394,8 @@ void test_ui_spotlight_scroll(void *data, Evas_Object *obj, void *event_info);
394 394
395void test_ui_relative_layout(void *data, Evas_Object *obj, void *event_info); 395void test_ui_relative_layout(void *data, Evas_Object *obj, void *event_info);
396void test_efl_ui_radio(void *data, Evas_Object *obj, void *event_info); 396void test_efl_ui_radio(void *data, Evas_Object *obj, void *event_info);
397 397void test_efl_ui_item_container_list(void *data, Evas_Object *obj, void *event_info );
398void test_efl_ui_item_container_grid(void *data, Evas_Object *obj, void *event_info);
398static void _list_udpate(void); 399static void _list_udpate(void);
399 400
400static Evas_Object *win, *tbx, *entry; // TODO: refactoring 401static Evas_Object *win, *tbx, *entry; // TODO: refactoring
@@ -868,6 +869,8 @@ add_tests:
868 ADD_TEST_EO(NULL, "Containers", "Efl.Ui.Table (Linear API)", test_ui_table_linear); 869 ADD_TEST_EO(NULL, "Containers", "Efl.Ui.Table (Linear API)", test_ui_table_linear);
869 ADD_TEST_EO(NULL, "Containers", "Efl.Ui.Table_Static", test_ui_table_static); 870 ADD_TEST_EO(NULL, "Containers", "Efl.Ui.Table_Static", test_ui_table_static);
870 ADD_TEST_EO(NULL, "Containers", "Efl.Ui.Relative_Layout", test_ui_relative_layout); 871 ADD_TEST_EO(NULL, "Containers", "Efl.Ui.Relative_Layout", test_ui_relative_layout);
872 ADD_TEST_EO(NULL, "Containers", "Efl.Ui.Item_Container List", test_efl_ui_item_container_list);
873 ADD_TEST_EO(NULL, "Containers", "Efl.Ui.Item_Container Grid", test_efl_ui_item_container_grid);
871 874
872 //------------------------------// 875 //------------------------------//
873 ADD_TEST_EO(NULL, "Events", "Event Refeed", test_events); 876 ADD_TEST_EO(NULL, "Events", "Event Refeed", test_events);
diff --git a/src/bin/elementary/test_ui_item_container.c b/src/bin/elementary/test_ui_item_container.c
new file mode 100644
index 0000000000..77f410a1b3
--- /dev/null
+++ b/src/bin/elementary/test_ui_item_container.c
@@ -0,0 +1,272 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#include <Efl_Ui.h>
6
7static void
8_selection_changed_cb(void *data, const Efl_Event *ev EINA_UNUSED)
9{
10 if (efl_ui_check_selected_get(ev->object))
11 efl_ui_layout_orientation_set(data, EFL_UI_LAYOUT_ORIENTATION_VERTICAL);
12 else
13 efl_ui_layout_orientation_set(data, EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL);
14}
15
16static void
17_scroll_to_animated_cb(void *data, const Efl_Event *ev EINA_UNUSED)
18{
19 Efl_Ui_Widget *element_1154 = efl_pack_content_get(data, 1154);
20
21 EINA_SAFETY_ON_NULL_RETURN(element_1154);
22
23 efl_ui_item_container_item_scroll(data, element_1154, EINA_TRUE);
24}
25
26static void
27_scroll_to_cb(void *data, const Efl_Event *ev EINA_UNUSED)
28{
29 Efl_Ui_Widget *element_10 = efl_pack_content_get(data, 10);
30
31 EINA_SAFETY_ON_NULL_RETURN(element_10);
32
33 efl_ui_item_container_item_scroll(data, element_10, EINA_FALSE);
34}
35
36static void
37_change_min_size_cb(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
38{
39 static Eina_Bool b = EINA_FALSE;
40 Efl_Ui_Widget *element_0 = efl_pack_content_get(data, 0);
41
42 EINA_SAFETY_ON_NULL_RETURN(element_0);
43
44 if (!b)
45 {
46 efl_gfx_hint_size_min_set(element_0, EINA_SIZE2D(40, 200));
47 }
48 else
49 {
50 efl_gfx_hint_size_min_set(element_0, EINA_SIZE2D(40, 40));
51 }
52 b = !b;
53}
54
55typedef struct {
56 Efl_Ui_Check *v, *h;
57 Efl_Ui_Item_Container *c;
58} Match_Content_Ctx;
59
60static void
61_selection_changed_match_content_cb(void *data, const Efl_Event *ev EINA_UNUSED)
62{
63 Match_Content_Ctx *c = data;
64 Eina_Bool v,h;
65
66 v = efl_ui_check_selected_get(c->v);
67 h = efl_ui_check_selected_get(c->h);
68
69 efl_ui_scrollable_match_content_set(c->c, v, h);
70}
71
72static void
73_widget_del_cb(void *data, const Efl_Event *ev EINA_UNUSED)
74{
75 free(data);
76}
77
78static void
79_add_item(Efl_Ui_Item_Container *c)
80{
81 Efl_Class *itc = efl_key_data_get(c, "__item_class");
82 char buf[PATH_MAX];
83 int r = 0, g = 0, b = 0;
84 int i = efl_content_count(c);
85 Eo *rect;
86 Eo *il;
87
88
89 il = efl_add(itc, c);
90
91 snprintf(buf, sizeof(buf), "%d - Test %d", i, i%13);
92 efl_text_set(il, buf);
93
94 rect = efl_add(EFL_CANVAS_RECTANGLE_CLASS, evas_object_evas_get(c));
95 switch (i % 5)
96 {
97 case 0:
98 r = 255;
99 break;
100 case 1:
101 g = 255;
102 break;
103 case 2:
104 b = 255;
105 break;
106 case 3:
107 r = g = b = 255;
108 break;
109 case 4:
110 r = g = b = 0;
111 break;
112 }
113 efl_gfx_color_set(rect, r, g, b, 255);
114 efl_content_set(il, rect);
115 if (itc == EFL_UI_GRID_DEFAULT_ITEM_CLASS)
116 efl_gfx_hint_size_min_set(il, EINA_SIZE2D(100, 180));
117 else
118 efl_gfx_hint_size_min_set(il, EINA_SIZE2D(40, 40+(i%2)*40));
119 efl_pack_end(c, il);
120}
121
122static void
123_remove_all_cb(void *data, const Efl_Event *ev EINA_UNUSED)
124{
125 efl_pack_clear(data);
126}
127
128static void
129_add_one_item(void *data, const Efl_Event *ev EINA_UNUSED)
130{
131 _add_item(data);
132}
133
134static void
135_add_thousend_items(void *data, const Efl_Event *ev EINA_UNUSED)
136{
137 for (int i = 0; i < 1000; ++i)
138 {
139 _add_item(data);
140 }
141}
142
143static void
144_select_value_cb(void *data, const Efl_Event *ev)
145{
146 Efl_Ui_Item_Container *c = data;
147
148 efl_ui_select_mode_set(c, efl_ui_radio_group_selected_value_get(ev->object));
149}
150
151void create_item_container_ui(Efl_Ui_Item_Position_Manager *manager, const Efl_Class *item, const char *name)
152{
153 Efl_Ui_Win *win, *o, *tbl, *item_container, *bx;
154 Match_Content_Ctx *ctx = calloc(1, sizeof(*ctx));
155
156 win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
157 efl_ui_win_type_set(efl_added, EFL_UI_WIN_TYPE_BASIC),
158 efl_text_set(efl_added, name),
159 efl_ui_win_autodel_set(efl_added, EINA_TRUE));
160 tbl = efl_add(EFL_UI_TABLE_CLASS, win);
161 efl_content_set(win, tbl);
162
163 item_container = o = efl_add(EFL_UI_ITEM_CONTAINER_CLASS, win,
164 efl_ui_item_container_position_manager_set(efl_added, manager));
165 efl_key_data_set(o, "__item_class", item);
166 efl_event_callback_add(o, EFL_EVENT_DEL, _widget_del_cb, ctx);
167 for (int i = 0; i < 2000; ++i)
168 {
169 _add_item(o);
170 }
171 efl_pack_table(tbl, o, 1, 0, 1, 11);
172 ctx->c = o;
173
174 o = efl_add(EFL_UI_BUTTON_CLASS, tbl,
175 efl_gfx_hint_weight_set(efl_added, 0.0, 0.0),
176 efl_gfx_hint_align_set(efl_added, 0, 0.5));
177 efl_text_set(o, "Scroll to 1154 ANIMATED");
178 efl_event_callback_add(o, EFL_UI_EVENT_CLICKED, _scroll_to_animated_cb, item_container);
179 efl_pack_table(tbl, o, 0, 1, 1, 1);
180
181 o = efl_add(EFL_UI_BUTTON_CLASS, tbl,
182 efl_gfx_hint_weight_set(efl_added, 0.0, 0.0),
183 efl_gfx_hint_align_set(efl_added, 0, 0.5));
184 efl_text_set(o, "Scroll to 10");
185 efl_event_callback_add(o, EFL_UI_EVENT_CLICKED, _scroll_to_cb, item_container);
186 efl_pack_table(tbl, o, 0, 2, 1, 1);
187
188 o = efl_add(EFL_UI_BUTTON_CLASS, tbl,
189 efl_gfx_hint_weight_set(efl_added, 0.0, 0.0),
190 efl_gfx_hint_align_set(efl_added, 0, 0.5));
191 efl_text_set(o, "Change min size of 0");
192 efl_event_callback_add(o, EFL_UI_EVENT_CLICKED, _change_min_size_cb, item_container);
193 efl_pack_table(tbl, o, 0, 3, 1, 1);
194
195 o = efl_add(EFL_UI_CHECK_CLASS, tbl,
196 efl_gfx_hint_weight_set(efl_added, 0.0, 0.0),
197 efl_gfx_hint_align_set(efl_added, 0, 0.5));
198 efl_text_set(o, "Vertical");
199 efl_event_callback_add(o, EFL_UI_CHECK_EVENT_SELECTED_CHANGED, _selection_changed_cb, item_container);
200 efl_ui_check_selected_set(o, EINA_TRUE);
201 efl_pack_table(tbl, o, 0, 4, 1, 1);
202
203 o = efl_add(EFL_UI_CHECK_CLASS, tbl,
204 efl_gfx_hint_weight_set(efl_added, 0.0, 0.0),
205 efl_gfx_hint_align_set(efl_added, 0, 0.5));
206 efl_text_set(o, "Match Vertical");
207 efl_event_callback_add(o, EFL_UI_CHECK_EVENT_SELECTED_CHANGED, _selection_changed_match_content_cb, ctx);
208 efl_pack_table(tbl, o, 0, 5, 1, 1);
209 ctx->v = o;
210
211 o = efl_add(EFL_UI_CHECK_CLASS, tbl,
212 efl_gfx_hint_weight_set(efl_added, 0.0, 0.0),
213 efl_gfx_hint_align_set(efl_added, 0, 0.5));
214 efl_text_set(o, "Match Horizontal");
215 efl_event_callback_add(o, EFL_UI_CHECK_EVENT_SELECTED_CHANGED, _selection_changed_match_content_cb, ctx);
216 efl_pack_table(tbl, o, 0, 6, 1, 1);
217 efl_gfx_entity_size_set(win, EINA_SIZE2D(260, 200));
218 ctx->h = o;
219
220 o = efl_add(EFL_UI_BUTTON_CLASS, tbl,
221 efl_gfx_hint_weight_set(efl_added, 0.0, 0.0),
222 efl_gfx_hint_align_set(efl_added, 0, 0.5));
223 efl_text_set(o, "Remove all items");
224 efl_event_callback_add(o, EFL_UI_EVENT_CLICKED, _remove_all_cb, item_container);
225 efl_pack_table(tbl, o, 0, 7, 1, 1);
226
227 o = efl_add(EFL_UI_BUTTON_CLASS, tbl,
228 efl_gfx_hint_weight_set(efl_added, 0.0, 0.0),
229 efl_gfx_hint_align_set(efl_added, 0, 0.5));
230 efl_text_set(o, "Add 1 item");
231 efl_event_callback_add(o, EFL_UI_EVENT_CLICKED, _add_one_item, item_container);
232 efl_pack_table(tbl, o, 0, 8, 1, 1);
233
234 o = efl_add(EFL_UI_BUTTON_CLASS, tbl,
235 efl_gfx_hint_weight_set(efl_added, 0.0, 0.0),
236 efl_gfx_hint_align_set(efl_added, 0, 0.5));
237 efl_text_set(o, "Add 1000 item");
238 efl_event_callback_add(o, EFL_UI_EVENT_CLICKED, _add_thousend_items, item_container);
239 efl_pack_table(tbl, o, 0, 9, 1, 1);
240
241 bx = efl_add(EFL_UI_RADIO_BOX_CLASS, tbl,
242 efl_gfx_hint_weight_set(efl_added, 0.0, 0.0),
243 efl_gfx_hint_align_set(efl_added, 0, 0.5));
244 efl_event_callback_add(bx, EFL_UI_RADIO_GROUP_EVENT_VALUE_CHANGED, _select_value_cb, item_container);
245 efl_pack_table(tbl, bx, 0, 10, 1, 1);
246 o = efl_add(EFL_UI_RADIO_CLASS, bx,
247 efl_ui_radio_state_value_set(efl_added, EFL_UI_SELECT_MODE_SINGLE));
248 efl_text_set(o, "Singleselect");
249 efl_pack_end(bx, o);
250 o = efl_add(EFL_UI_RADIO_CLASS, bx,
251 efl_ui_radio_state_value_set(efl_added, EFL_UI_SELECT_MODE_SINGLE_ALWAYS));
252 efl_text_set(o, "Singleselect Always");
253 efl_pack_end(bx, o);
254 o = efl_add(EFL_UI_RADIO_CLASS, bx,
255 efl_ui_radio_state_value_set(efl_added, EFL_UI_SELECT_MODE_MULTI));
256 efl_text_set(o, "Multiselect");
257 efl_pack_end(bx, o);
258}
259
260void test_efl_ui_item_container_grid(void *data EINA_UNUSED,
261 Evas_Object *obj EINA_UNUSED,
262 void *event_info EINA_UNUSED)
263{
264 create_item_container_ui(efl_new(EFL_UI_GRID_POSITION_MANAGER_CLASS), EFL_UI_GRID_DEFAULT_ITEM_CLASS, "Efl.Ui.Item_Container Grid");
265}
266
267void test_efl_ui_item_container_list(void *data EINA_UNUSED,
268 Evas_Object *obj EINA_UNUSED,
269 void *event_info EINA_UNUSED)
270{
271 create_item_container_ui(efl_new(EFL_UI_LIST_POSITION_MANAGER_CLASS), EFL_UI_LIST_DEFAULT_ITEM_CLASS, "Efl.Ui.Item_Container List");
272}