summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLarry Jr <larry.olj@gmail.com>2017-10-31 19:24:32 -0200
committerSangHyeon Jade Lee <dltkdgus1764@gmail.com>2017-11-15 17:06:45 +0900
commit898df348d94a2221373ded02e52fc90b824cda34 (patch)
tree4609a6138d99ac5df1af56fb2948515b7ed8d241
parent19efd4d826f8d4fb4b87973090151932052b4fb4 (diff)
elm: move calculate function for a job
-rw-r--r--src/lib/elementary/efl_ui_list.c4
-rw-r--r--src/lib/elementary/efl_ui_list_precise_layouter.c214
2 files changed, 142 insertions, 76 deletions
diff --git a/src/lib/elementary/efl_ui_list.c b/src/lib/elementary/efl_ui_list.c
index 18b603a9e5..b99640d6a2 100644
--- a/src/lib/elementary/efl_ui_list.c
+++ b/src/lib/elementary/efl_ui_list.c
@@ -76,7 +76,7 @@ _efl_ui_list_pan_elm_pan_pos_set(Eo *obj EINA_UNUSED, Efl_Ui_List_Pan_Data *psd,
76{ 76{
77 Evas_Coord ox, oy, ow, oh, cw; 77 Evas_Coord ox, oy, ow, oh, cw;
78 78
79 DBG("x: %d y: %d", (int)x, (int)y); 79 //DBG("x: %d y: %d", (int)x, (int)y);
80 if ((x == psd->x) && (y == psd->y)) return; 80 if ((x == psd->x) && (y == psd->y)) return;
81 81
82// evas_object_geometry_get(pd->obj, &ox, &oy, &ow, &oh); 82// evas_object_geometry_get(pd->obj, &ox, &oy, &ow, &oh);
@@ -150,7 +150,7 @@ _efl_ui_list_pan_elm_pan_content_size_get(Eo *obj EINA_UNUSED, Efl_Ui_List_Pan_D
150 if (w) *w = min.w; 150 if (w) *w = min.w;
151 if (h) *h = min.h; 151 if (h) *h = min.h;
152 152
153 DBG("w: %d h: %d", *w, *h); 153 //DBG("w: %d h: %d", *w, *h);
154} 154}
155 155
156EOLIAN static void 156EOLIAN static void
diff --git a/src/lib/elementary/efl_ui_list_precise_layouter.c b/src/lib/elementary/efl_ui_list_precise_layouter.c
index 1091298f19..63a43bffb4 100644
--- a/src/lib/elementary/efl_ui_list_precise_layouter.c
+++ b/src/lib/elementary/efl_ui_list_precise_layouter.c
@@ -18,16 +18,20 @@
18 18
19#define MY_CLASS EFL_UI_LIST_PRECISE_LAYOUTER_CLASS 19#define MY_CLASS EFL_UI_LIST_PRECISE_LAYOUTER_CLASS
20 20
21
22typedef struct _Efl_Ui_List_Precise_Layouter_Data 21typedef struct _Efl_Ui_List_Precise_Layouter_Data
23{ 22{
24 Eina_Bool initialized; 23 Eina_Bool initialized;
24 Eina_Bool recalc;
25 Eina_Hash* size_information; 25 Eina_Hash* size_information;
26 Eina_Size2D min; 26 Eina_Size2D min;
27 Efl_Model* model; 27 Efl_Model* model;
28 Efl_Ui_List_Model *modeler; 28 Efl_Ui_List_Model *modeler;
29 unsigned int count_total;
30 Efl_Future *count_future; 29 Efl_Future *count_future;
30 Ecore_Job *calc_job;
31 Eina_Accessor *nodes;
32 int first;
33 int count;
34 int count_total;
31} Efl_Ui_List_Precise_Layouter_Data; 35} Efl_Ui_List_Precise_Layouter_Data;
32 36
33typedef struct _Efl_Ui_List_Precise_Layouter_Size 37typedef struct _Efl_Ui_List_Precise_Layouter_Size
@@ -36,15 +40,17 @@ typedef struct _Efl_Ui_List_Precise_Layouter_Size
36 double weight_x, weight_y; 40 double weight_x, weight_y;
37} Efl_Ui_List_Precise_Layouter_Size; 41} Efl_Ui_List_Precise_Layouter_Size;
38 42
39
40typedef struct _Efl_Ui_List_Precise_Layouter_Callback_Data 43typedef struct _Efl_Ui_List_Precise_Layouter_Callback_Data
41{ 44{
42 Efl_Ui_List_Precise_Layouter_Data* pd; 45 Efl_Ui_List_Precise_Layouter_Data* pd;
43 Efl_Ui_List_Precise_Layouter_Size* size; 46 Efl_Ui_List_Precise_Layouter_Size* size;
44} Efl_Ui_List_Precise_Layouter_Callback_Data; 47} Efl_Ui_List_Precise_Layouter_Callback_Data;
45 48
49
46#include "efl_ui_list_precise_layouter.eo.h" 50#include "efl_ui_list_precise_layouter.eo.h"
47 51
52
53static void _efl_ui_list_relayout_layout_do(Efl_Ui_List_Precise_Layouter_Data *);
48static void _initilize(Eo *, Efl_Ui_List_Precise_Layouter_Data*, Efl_Ui_List_Model*); 54static void _initilize(Eo *, Efl_Ui_List_Precise_Layouter_Data*, Efl_Ui_List_Model*);
49static void _finalize(Eo *, Efl_Ui_List_Precise_Layouter_Data*); 55static void _finalize(Eo *, Efl_Ui_List_Precise_Layouter_Data*);
50 56
@@ -136,14 +142,23 @@ _on_item_size_hint_change(void *data, Evas *e EINA_UNUSED,
136 _item_min_calc(cb_data->pd, obj, cb_data->size, min); 142 _item_min_calc(cb_data->pd, obj, cb_data->size, min);
137} 143}
138 144
145
146static void
147_on_modeler_resize(void *data, Evas *e EINA_UNUSED,
148 Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
149{
150 Efl_Ui_List_Precise_Layouter_Data *pd = data;
151 pd->recalc = EINA_TRUE;
152}
153
139static void 154static void
140_initilize(Eo *obj EINA_UNUSED, Efl_Ui_List_Precise_Layouter_Data *pd, Efl_Ui_List_Model *modeler) 155_initilize(Eo *obj EINA_UNUSED, Efl_Ui_List_Precise_Layouter_Data *pd, Efl_Ui_List_Model *modeler)
141{ 156{
142 if(pd->initialized) 157 if(pd->initialized)
143 return; 158 return;
144 159
145 pd->modeler = modeler;
146 pd->initialized = EINA_TRUE; 160 pd->initialized = EINA_TRUE;
161 evas_object_event_callback_add(modeler, EVAS_CALLBACK_RESIZE, _on_modeler_resize, pd);
147 efl_ui_list_model_load_range_set(modeler, 0, 0); // load all 162 efl_ui_list_model_load_range_set(modeler, 0, 0); // load all
148 pd->min.w = 0; 163 pd->min.w = 0;
149 pd->min.h = 0; 164 pd->min.h = 0;
@@ -157,6 +172,8 @@ _finalize(Eo *obj EINA_UNUSED, Efl_Ui_List_Precise_Layouter_Data *pd)
157 Eina_Iterator *item_iterator; 172 Eina_Iterator *item_iterator;
158 void *data; 173 void *data;
159 174
175 evas_object_event_callback_del_full(pd->modeler, EVAS_CALLBACK_RESIZE, _on_modeler_resize, pd);
176
160 item_iterator = eina_hash_iterator_key_new(pd->size_information); 177 item_iterator = eina_hash_iterator_key_new(pd->size_information);
161 while(eina_iterator_next(item_iterator, &data)) 178 while(eina_iterator_next(item_iterator, &data))
162 { 179 {
@@ -175,6 +192,71 @@ _finalize(Eo *obj EINA_UNUSED, Efl_Ui_List_Precise_Layouter_Data *pd)
175 pd->initialized = EINA_FALSE; 192 pd->initialized = EINA_FALSE;
176} 193}
177 194
195static void
196_calc_size_job(void *data)
197{
198 Efl_Ui_List_Precise_Layouter_Size* size;
199 Efl_Ui_List_Precise_Layouter_Data *pd;
200 Efl_Ui_List_SegArray_Node *items_node;
201 Efl_Ui_List_LayoutItem *layout_item;
202 Eo *obj = data;
203 int i, j;
204
205 DBG(" >>>>> RECALC JOB <<<<<<< \n");
206 EINA_SAFETY_ON_NULL_RETURN(data);
207 pd = efl_data_scope_get(obj, MY_CLASS);
208 if (EINA_UNLIKELY(!pd)) return;
209
210 EINA_ACCESSOR_FOREACH(pd->nodes, i, items_node)
211 {
212 DBG("node first %d", items_node->first);
213 for(j = 0; j != items_node->length; ++j)
214 {
215 layout_item = items_node->pointers[j];
216 DBG("layout_do first %d count %d", pd->first, pd->count);
217 /* EINA_SAFETY_ON_NULL_RETURN(items); */
218
219 // cache size of new items
220 size = eina_hash_find(pd->size_information, &layout_item);
221 if(!size)
222 {
223 if(!layout_item->layout)
224 {
225 DBG("no layout, realizing");
226 efl_ui_list_model_realize(pd->modeler, layout_item);
227 }
228 else
229 {
230 DBG("already realized");
231 /* if(!layout_item->layout) */
232 /* { */
233 /* // error */
234 /* continue; */
235 /* } */
236 }
237
238 size = calloc(1, sizeof(Efl_Ui_List_Precise_Layouter_Size));
239 eina_hash_add(pd->size_information, &layout_item, size);
240 Eina_Size2D min = efl_gfx_size_hint_combined_min_get(layout_item->layout);
241 if(min.w && min.h)
242 {
243 // DBG("size was calculated");
244 _item_min_calc(pd, layout_item->layout, size, min);
245 }
246 Efl_Ui_List_Precise_Layouter_Callback_Data *cb_data = calloc(1, sizeof(Efl_Ui_List_Precise_Layouter_Callback_Data));
247 cb_data->pd = pd;
248 cb_data->size = size;
249 evas_object_event_callback_add(layout_item->layout, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _on_item_size_hint_change, cb_data);
250 }
251 }
252 }
253
254 pd->recalc = EINA_FALSE;
255 pd->calc_job = NULL;
256
257 _efl_ui_list_relayout_layout_do(pd);
258}
259
178EOLIAN static Efl_Object * 260EOLIAN static Efl_Object *
179_efl_ui_list_precise_layouter_efl_object_constructor(Eo *obj EINA_UNUSED, Efl_Ui_List_Precise_Layouter_Data *pd) 261_efl_ui_list_precise_layouter_efl_object_constructor(Eo *obj EINA_UNUSED, Efl_Ui_List_Precise_Layouter_Data *pd)
180{ 262{
@@ -216,73 +298,25 @@ _efl_ui_list_precise_layouter_efl_ui_list_relayout_model_set(Eo *obj EINA_UNUSED
216 } 298 }
217} 299}
218 300
219EOLIAN static void 301
220_efl_ui_list_precise_layouter_efl_ui_list_relayout_layout_do 302static void
221 (Eo *obj EINA_UNUSED, Efl_Ui_List_Precise_Layouter_Data *pd 303_efl_ui_list_relayout_layout_do(Efl_Ui_List_Precise_Layouter_Data *pd)
222 , Efl_Ui_List_Model *modeler, int first, int count, Eina_Accessor *nodes)
223{ 304{
224 Efl_Ui_List_LayoutItem* layout_item;
225 Efl_Ui_List_SegArray_Node* items_node;
226 Efl_Ui_List_Precise_Layouter_Size* size;
227 int i = 0, j = 0;
228 Eina_Bool horiz = EINA_FALSE/*_horiz(pd->orient)*/, zeroweight = EINA_FALSE; 305 Eina_Bool horiz = EINA_FALSE/*_horiz(pd->orient)*/, zeroweight = EINA_FALSE;
229 Evas_Coord ow, oh, want, scr_x, scr_y; 306 Evas_Coord ow, oh, want, scr_x, scr_y;
230 int boxx, boxy, boxw, boxh, length, pad, extra = 0, rounding = 0; 307 int boxx, boxy, boxw, boxh, length, pad, extra = 0, rounding = 0;
231 int boxl = 0, boxr = 0, boxt = 0, boxb = 0; 308 int boxl = 0, boxr = 0, boxt = 0, boxb = 0;
309 int i = 0, j = 0;
232 double cur_pos = 0, scale, box_align[2], weight[2] = { 0, 0 }; 310 double cur_pos = 0, scale, box_align[2], weight[2] = { 0, 0 };
233 Eina_Bool box_fill[2] = { EINA_FALSE, EINA_FALSE }; 311 Eina_Bool box_fill[2] = { EINA_FALSE, EINA_FALSE };
312 Efl_Ui_List_Precise_Layouter_Size* size;
313 Efl_Ui_List_LayoutItem* layout_item;
314 Efl_Ui_List_SegArray_Node *items_node;
234 315
235 DBG("layout_do first %d count %d", first, count); 316 evas_object_geometry_get(pd->modeler, &boxx, &boxy, &boxw, &boxh);
236 /* EINA_SAFETY_ON_NULL_RETURN(items); */ 317 efl_gfx_size_hint_margin_get(pd->modeler, &boxl, &boxr, &boxt, &boxb);
237
238 _initilize(obj, pd, modeler);
239
240 // cache size of new items
241 EINA_ACCESSOR_FOREACH(nodes, i, items_node)
242 {
243 DBG("node first %d", items_node->first);
244 for(j = 0; j != items_node->length; ++j)
245 {
246 layout_item = items_node->pointers[j];
247
248 size = eina_hash_find(pd->size_information, &layout_item);
249 if(!size)
250 {
251 if(!layout_item->layout)
252 {
253 DBG("no layout, realizing");
254 efl_ui_list_model_realize(modeler, layout_item);
255 }
256 else
257 {
258 DBG("already realized");
259 /* if(!layout_item->layout) */
260 /* { */
261 /* // error */
262 /* continue; */
263 /* } */
264 }
265
266 size = calloc(1, sizeof(Efl_Ui_List_Precise_Layouter_Size));
267 eina_hash_add(pd->size_information, &layout_item, size);
268 Eina_Size2D min = efl_gfx_size_hint_combined_min_get(layout_item->layout);
269 if(min.w && min.h)
270 {
271// DBG("size was calculated");
272 _item_min_calc(pd, layout_item->layout, size, min);
273 }
274 Efl_Ui_List_Precise_Layouter_Callback_Data *cb_data = calloc(1, sizeof(Efl_Ui_List_Precise_Layouter_Callback_Data));
275 cb_data->pd = pd;
276 cb_data->size = size;
277 evas_object_event_callback_add(layout_item->layout, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _on_item_size_hint_change, cb_data);
278 }
279 }
280 }
281
282 evas_object_geometry_get(modeler, &boxx, &boxy, &boxw, &boxh);
283 efl_gfx_size_hint_margin_get(modeler, &boxl, &boxr, &boxt, &boxb);
284 318
285 scale = evas_object_scale_get(modeler); 319 scale = evas_object_scale_get(pd->modeler);
286 // Box align: used if "item has max size and fill" or "no item has a weight" 320 // Box align: used if "item has max size and fill" or "no item has a weight"
287 // Note: cells always expand on the orthogonal direction 321 // Note: cells always expand on the orthogonal direction
288 box_align[0] = 0;/*pd->align.h;*/ 322 box_align[0] = 0;/*pd->align.h;*/
@@ -326,7 +360,7 @@ _efl_ui_list_precise_layouter_efl_ui_list_relayout_layout_do
326 /* Evas_Coord minw = pd->min.w + boxl + boxr; */ 360 /* Evas_Coord minw = pd->min.w + boxl + boxr; */
327 /* Evas_Coord minh = pd->min.h + boxt + boxb; */ 361 /* Evas_Coord minh = pd->min.h + boxt + boxb; */
328 362
329 efl_ui_list_model_min_size_set(modeler, pd->min); 363 efl_ui_list_model_min_size_set(pd->modeler, pd->min);
330 if (extra < 0) extra = 0; 364 if (extra < 0) extra = 0;
331 365
332 weight[0] = 1;//pd->weight.x; 366 weight[0] = 1;//pd->weight.x;
@@ -343,21 +377,20 @@ _efl_ui_list_precise_layouter_efl_ui_list_relayout_layout_do
343 // move bounding box according to box align 377 // move bounding box according to box align
344 cur_pos = extra * box_align[!horiz]; 378 cur_pos = extra * box_align[!horiz];
345 } 379 }
346 weight[!horiz] = count; 380 weight[!horiz] = pd->count;
347 } 381 }
348 382
349 elm_interface_scrollable_content_viewport_geometry_get 383 elm_interface_scrollable_content_viewport_geometry_get
350 (modeler, NULL, NULL, &ow, &oh); 384 (pd->modeler, NULL, NULL, &ow, &oh);
351 385
352 elm_interface_scrollable_content_pos_get(modeler, &scr_x, &scr_y); 386 elm_interface_scrollable_content_pos_get(pd->modeler, &scr_x, &scr_y);
353 // scan all items, get their properties, calculate total weight & min size 387 // scan all items, get their properties, calculate total weight & min size
354 // cache size of new items 388 // cache size of new items
355 /* EINA_ACCESSOR_FOREACH(items, i, layout_item) */ 389 EINA_ACCESSOR_FOREACH(pd->nodes, i, items_node)
356 EINA_ACCESSOR_FOREACH(nodes, i, items_node)
357 { 390 {
358 for(j = 0; j != items_node->length;++j) 391 for(j = 0; j != items_node->length;++j)
359 { 392 {
360 layout_item = items_node->pointers[j]; 393 layout_item = items_node->pointers[j];
361 double cx, cy, cw, ch, x, y, w, h; 394 double cx, cy, cw, ch, x, y, w, h;
362 double align[2]; 395 double align[2];
363 int item_pad[4]; 396 int item_pad[4];
@@ -386,7 +419,7 @@ _efl_ui_list_precise_layouter_efl_ui_list_relayout_layout_do
386 if (max.h < size->min.h) max.h = size->min.h; 419 if (max.h < size->min.h) max.h = size->min.h;
387 420
388 // extra rounding up (compensate cumulative error) 421 // extra rounding up (compensate cumulative error)
389 if ((i == (count - 1)) && (cur_pos - floor(cur_pos) >= 0.5)) 422 if ((i == (pd->count - 1)) && (cur_pos - floor(cur_pos) >= 0.5))
390 rounding = 1; 423 rounding = 1;
391 424
392 if (horiz) 425 if (horiz)
@@ -470,9 +503,42 @@ _efl_ui_list_precise_layouter_efl_ui_list_relayout_layout_do
470 503
471 /* layout_item->x = x; */ 504 /* layout_item->x = x; */
472 /* layout_item->y = y; */ 505 /* layout_item->y = y; */
473 } 506 } /* if (size) end */
474 } 507 }
508 } /* EINA ACCESSOR FOREACH END */
509
510 eina_accessor_free(pd->nodes);
511 pd->nodes = NULL;
512}
513
514EOLIAN static void
515_efl_ui_list_precise_layouter_efl_ui_list_relayout_layout_do
516 (Eo *obj EINA_UNUSED, Efl_Ui_List_Precise_Layouter_Data *pd
517 , Efl_Ui_List_Model *modeler, int first, int count, Eina_Accessor *nodes)
518{
519 int pop;
520 EINA_SAFETY_ON_NULL_RETURN(nodes);
521
522 _initilize(obj, pd, modeler);
523
524 pd->modeler = modeler;
525 pd->first = first;
526 pd->count = count;
527
528 if (pd->nodes)
529 eina_accessor_free(pd->nodes);
530 pd->nodes = nodes;
531
532 pop = eina_hash_population(pd->size_information);
533 if (pd->recalc || (first + count) > pop || pd->count_total > pop)
534 {
535 // cache size of new items
536 ecore_job_del(pd->calc_job);
537 pd->calc_job = ecore_job_add(_calc_size_job, obj);
538 return;
475 } 539 }
540
541 _efl_ui_list_relayout_layout_do(pd);
476} 542}
477 543
478#include "efl_ui_list_precise_layouter.eo.c" 544#include "efl_ui_list_precise_layouter.eo.c"