aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/elementary/efl_ui_list_precise_layouter.c
blob: 53d5b1bba6e34d64e31007c46a6f6126f53f4580 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#include <Elementary.h>

#include <assert.h>

#include "elm_priv.h"
#include "efl_ui_list_segarray.h"

#undef DBG
#define DBG(...) do { \
    fprintf(stderr, __FILE__ ":" "%d %s ", __LINE__, __PRETTY_FUNCTION__); \
    fprintf(stderr,  __VA_ARGS__);                                     \
    fprintf(stderr, "\n"); fflush(stderr);                              \
  } while(0)

#define MY_CLASS EFL_UI_LIST_PRECISE_LAYOUTER_CLASS

typedef struct _Efl_Ui_List_Precise_Layouter_Data
{
   Eina_Bool initialized;
   Eina_Bool recalc;
   Eina_Size2D min;
   Efl_Model* model;
   Efl_Ui_List_Model *modeler;
   Efl_Future *count_future;
   Ecore_Job *calc_job;
   Efl_Ui_List_SegArray *segarray;
   int first;
   unsigned int count;
   unsigned int count_total;
   unsigned int calc_progress;
} Efl_Ui_List_Precise_Layouter_Data;

typedef struct _Efl_Ui_List_Precise_Layouter_Node_Data
{
  Eina_Size2D min;
  Eina_Bool realized;
} Efl_Ui_List_Precise_Layouter_Node_Data;

typedef struct _Efl_Ui_List_Precise_Layouter_Callback_Data
{
  Efl_Ui_List_Precise_Layouter_Data* pd;
  Efl_Ui_List_SegArray_Node* node;
} Efl_Ui_List_Precise_Layouter_Callback_Data;


#include "efl_ui_list_precise_layouter.eo.h"


static void _efl_ui_list_relayout_layout_do(Efl_Ui_List_Precise_Layouter_Data *);
static void _initilize(Eo *, Efl_Ui_List_Precise_Layouter_Data*, Efl_Ui_List_Model*, Efl_Ui_List_SegArray*);
static void _finalize(Eo *, Efl_Ui_List_Precise_Layouter_Data*);
static void _node_realize(Efl_Ui_List_Precise_Layouter_Data*, Efl_Ui_List_SegArray_Node*);
static void _node_unrealize(Efl_Ui_List_Precise_Layouter_Data*, Efl_Ui_List_SegArray_Node*);

static void
_item_min_calc(Efl_Ui_List_Precise_Layouter_Data *pd, Efl_Ui_List_LayoutItem* item
                , Eina_Size2D min, Efl_Ui_List_SegArray_Node *itemnode)
{
   Efl_Ui_List_Precise_Layouter_Node_Data *nodedata = itemnode->layout_data;
   Efl_Ui_List_LayoutItem *layout_item;
   int i, pad[4];

   efl_gfx_size_hint_margin_get(item->layout, &pad[0], &pad[1], &pad[2], &pad[3]);

   min.w += pad[0] + pad[1];
   min.h += pad[2] + pad[3];

   pd->min.h += min.h - item->min.h;
   nodedata->min.h += min.h - item->min.h;

   if (nodedata->min.w <= min.w)
     nodedata->min.w = min.w;
   else if (nodedata->min.w == item->min.w)
     for (i = 0; i != itemnode->length; ++i)
       {
          layout_item = (Efl_Ui_List_LayoutItem *)itemnode->pointers[i];
          if (nodedata->min.w < layout_item->min.w)
            nodedata->min.w = layout_item->min.w;

          if (item->min.w == layout_item->min.w)
            break;
       }

   if (pd->min.w <= min.w)
     pd->min.w = min.w;
   else if (pd->min.w == item->min.w)
     {
        Efl_Ui_List_SegArray_Node *node;
        Eina_Accessor *nodes = efl_ui_list_segarray_node_accessor_get(pd->segarray);
        pd->min.w = min.w;

        EINA_ACCESSOR_FOREACH(nodes, i, node)
          {
             Efl_Ui_List_Precise_Layouter_Node_Data *nodedata = node->layout_data;
             if (pd->min.w < nodedata->min.w)
               pd->min.w = nodedata->min.w;

             if (item->min.w == nodedata->min.w)
               break;
          }
       eina_accessor_free(nodes);
     }

   item->min.w = min.w;
   item->min.h = min.h;
}

static void
_count_then(void * data, Efl_Event const* event)
{
   Efl_Ui_List_Precise_Layouter_Data *pd = data;
   EINA_SAFETY_ON_NULL_RETURN(pd);
   pd->count_future = NULL;

   pd->count_total = *(int*)((Efl_Future_Event_Success*)event->info)->value;

   if (pd->modeler && pd->count_total != efl_ui_list_segarray_count(pd->segarray))
     {
        pd->recalc = EINA_TRUE;
        efl_ui_list_model_load_range_set(pd->modeler, 0, 0); // load all
     }
}

static void
_count_error(void * data, Efl_Event const* event EINA_UNUSED)
{
   Efl_Ui_List_Precise_Layouter_Data *pd = data;
   EINA_SAFETY_ON_NULL_RETURN(pd);
   pd->count_future = NULL;
}

static void
_on_item_size_hint_change(void *data, Evas *e EINA_UNUSED,
                    Evas_Object *obj, void *event_info EINA_UNUSED)
{
   Efl_Ui_List_Precise_Layouter_Callback_Data *cb_data = data;
   Efl_Ui_List_SegArray_Node *node = cb_data->node;
   Efl_Ui_List_Precise_Layouter_Data *pd = cb_data->pd;
   Efl_Ui_List_LayoutItem *item;
   int i;

   Eina_Size2D min = efl_gfx_size_hint_combined_min_get(obj);

   for (i = 0; i != node->length; ++i)
     {
        item = (Efl_Ui_List_LayoutItem *)node->pointers[i];
        if (item->layout == obj)
          {
             Efl_Ui_List_Precise_Layouter_Node_Data *nodedata = node->layout_data;
             _item_min_calc(cb_data->pd, item, min, node);
             if (!nodedata->realized)
               {
                  //DBG("item size change unrealize");
                  free(evas_object_event_callback_del(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _on_item_size_hint_change));
                  efl_ui_list_model_unrealize(pd->modeler, item);
               }
             return;
          }
     }
}

static void
_on_modeler_resize(void *data, Evas *e EINA_UNUSED,
                    Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   //Efl_Ui_List_Precise_Layouter_Data *pd = data;
   //pd->recalc = EINA_TRUE;
}

static void
_initilize(Eo *obj EINA_UNUSED, Efl_Ui_List_Precise_Layouter_Data *pd, Efl_Ui_List_Model *modeler, Efl_Ui_List_SegArray *segarray)
{
   if(pd->initialized)
     return;

   pd->recalc = EINA_TRUE;
   pd->initialized = EINA_TRUE;

   pd->modeler = modeler;
   pd->segarray = segarray;

   evas_object_event_callback_add(modeler, EVAS_CALLBACK_RESIZE, _on_modeler_resize, pd);
   efl_ui_list_model_load_range_set(modeler, 0, 0); // load all

   pd->min.w = 0;
   pd->min.h = 0;
}

static void
_finalize(Eo *obj EINA_UNUSED, Efl_Ui_List_Precise_Layouter_Data *pd)
{
   Efl_Ui_List_SegArray_Node* node;
   int i = 0;

   evas_object_event_callback_del_full(pd->modeler, EVAS_CALLBACK_RESIZE, _on_modeler_resize, pd);

   Eina_Accessor *nodes = efl_ui_list_segarray_node_accessor_get(pd->segarray);
   EINA_ACCESSOR_FOREACH(nodes, i, node)
     _node_unrealize(pd, node);
   eina_accessor_free(nodes);

   pd->min.w = 0;
   pd->min.h = 0;

   efl_ui_list_model_min_size_set(pd->modeler, pd->min);

   pd->segarray = NULL;
   pd->modeler = NULL;

   pd->initialized = EINA_FALSE;
}

static void
_node_realize(Efl_Ui_List_Precise_Layouter_Data *pd, Efl_Ui_List_SegArray_Node *node)
{
   Efl_Ui_List_LayoutItem* layout_item;
   Efl_Ui_List_Precise_Layouter_Callback_Data *cb_data;
   Efl_Ui_List_Precise_Layouter_Node_Data *nodedata = node->layout_data;
   int i;

   if (nodedata->realized)
     return;

   DBG("node_realize %d", node->first);
   nodedata->realized = EINA_TRUE;

   for (i = 0; i != node->length; ++i)
     {
       layout_item = (Efl_Ui_List_LayoutItem *)node->pointers[i];
       efl_ui_list_model_realize(pd->modeler, layout_item);

       if (layout_item->layout)
         {
            cb_data = calloc(1, sizeof(Efl_Ui_List_Precise_Layouter_Callback_Data));
            cb_data->pd = pd;
            cb_data->node = node;
            evas_object_event_callback_add(layout_item->layout, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _on_item_size_hint_change, cb_data);
         }
     }
}

static void
_node_unrealize(Efl_Ui_List_Precise_Layouter_Data *pd, Efl_Ui_List_SegArray_Node *node)
{
   Efl_Ui_List_LayoutItem* layout_item;
   Efl_Ui_List_Precise_Layouter_Callback_Data *cb_data;
   Efl_Ui_List_Precise_Layouter_Node_Data *nodedata = node->layout_data;
   int i;

   if (!nodedata->realized)
     return;

   DBG("node_unrealize %d", node->first);
   nodedata->realized = EINA_FALSE;

   for (i = 0; i != node->length; ++i)
     {
       layout_item = (Efl_Ui_List_LayoutItem *)node->pointers[i];
       if (layout_item->layout)
         {
            cb_data = evas_object_event_callback_del(layout_item->layout, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _on_item_size_hint_change);
            free(cb_data);
         }
       efl_ui_list_model_unrealize(pd->modeler, layout_item);
     }
}

static void
_calc_range(Efl_Ui_List_Precise_Layouter_Data *pd)
{
   Efl_Ui_List_SegArray_Node *node;
   Evas_Coord ow, oh, scr_x, scr_y, ch;
   Efl_Ui_List_Precise_Layouter_Node_Data *nodedata;
   int i;

   elm_interface_scrollable_content_viewport_geometry_get
              (pd->modeler, NULL, NULL, &ow, &oh);
   elm_interface_scrollable_content_pos_get(pd->modeler, &scr_x, &scr_y);

   ch = 0;
   Eina_Accessor *nodes = efl_ui_list_segarray_node_accessor_get(pd->segarray);
   EINA_ACCESSOR_FOREACH(nodes, i, node)
     {
        nodedata = node->layout_data;
//        DBG("node %d h:%d ch:%d scr_y:%d oh:%d", node->first, nodedata->min.h, ch, scr_y, oh);
        if (!nodedata || !nodedata->min.h)
          continue;

        if ((ch >= scr_y || nodedata->min.h + ch >= scr_y) && (ch <= (scr_y + oh) || nodedata->min.h + ch <= scr_y + oh))
          _node_realize(pd, node);
        else
          _node_unrealize(pd, node);

        ch += nodedata->min.h;
     }
   eina_accessor_free(nodes);
}

static void
_calc_size_job(void *data)
{
   Efl_Ui_List_Precise_Layouter_Data *pd;
   Efl_Ui_List_SegArray_Node *node;
   Efl_Ui_List_LayoutItem *layout_item;
   Eo *obj = data;
   Eina_Size2D min;
   int i;
   double start_time = ecore_time_get();

   EINA_SAFETY_ON_NULL_RETURN(data);
   pd = efl_data_scope_get(obj, MY_CLASS);
   if (EINA_UNLIKELY(!pd)) return;

   pd->recalc = EINA_FALSE;

   Eina_Accessor *nodes = efl_ui_list_segarray_node_accessor_get(pd->segarray);
   while (eina_accessor_data_get(nodes, pd->calc_progress, (void **)&node))
     {
        pd->calc_progress++;
        if (!node->layout_data)
          node->layout_data = calloc(1, sizeof(Efl_Ui_List_Precise_Layouter_Node_Data));

        for (i = 0; i != node->length; ++i)
          {
            layout_item = (Efl_Ui_List_LayoutItem *)node->pointers[i];
            EINA_SAFETY_ON_NULL_RETURN(layout_item);

            // cache size of new items
            if ((layout_item->min.w == 0) && (layout_item->min.h == 0))
              {
                if (!layout_item->layout)
                  {
                    //DBG("no layout, realizing");
                    efl_ui_list_model_realize(pd->modeler, layout_item);
                  }

                min = efl_gfx_size_hint_combined_min_get(layout_item->layout);
                if (min.w && min.h)
                  {
                    DBG("size was calculated w:%d h:%d", min.w, min.h);
                    _item_min_calc(pd, layout_item, min, node);
                    efl_ui_list_model_unrealize(pd->modeler, layout_item);
                  }
                else
                  {
                     Efl_Ui_List_Precise_Layouter_Callback_Data *cb_data = calloc(1, sizeof(Efl_Ui_List_Precise_Layouter_Callback_Data));
                     cb_data->pd = pd;
                     cb_data->node = node;
                     evas_object_event_callback_add(layout_item->layout, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _on_item_size_hint_change, cb_data);
                  }
              }
          }
        if ( (ecore_time_get() - start_time ) > 0.01 )
          {
            ecore_job_del(pd->calc_job);
            pd->calc_job = ecore_job_add(_calc_size_job, obj);
            eina_accessor_free(nodes);
            return;
         }
     }
   eina_accessor_free(nodes);
   pd->calc_progress = 0;
   pd->calc_job = NULL;

   evas_object_smart_changed(pd->modeler);
   //_efl_ui_list_relayout_layout_do(pd);
}

EOLIAN static Efl_Object *
_efl_ui_list_precise_layouter_efl_object_constructor(Eo *obj EINA_UNUSED, Efl_Ui_List_Precise_Layouter_Data *pd)
{
   obj = efl_constructor(efl_super(obj, MY_CLASS));
   pd->initialized = EINA_FALSE;
   pd->count_future = NULL;

   return obj;
}

EOLIAN static void
_efl_ui_list_precise_layouter_efl_ui_list_relayout_model_set(Eo *obj EINA_UNUSED, Efl_Ui_List_Precise_Layouter_Data *pd, Efl_Model *model)
{
   if (pd->model == model)
     return;

   pd->count_total = 0;
   if (pd->count_future)
     {
        efl_future_cancel(pd->count_future);
        pd->count_future = NULL;
     }

   if (pd->model)
     {
        _finalize(obj, pd);
        efl_unref(pd->model);
        pd->model = NULL;
     }

   if (model)
     {
        pd->model = model;
        efl_ref(pd->model);
        pd->count_future = efl_model_children_count_get(pd->model);
        efl_future_then(pd->count_future, &_count_then, &_count_error, NULL, pd);
     }
}

static void
_efl_ui_list_relayout_layout_do(Efl_Ui_List_Precise_Layouter_Data *pd)
{
   Eina_Bool horiz = EINA_FALSE/*_horiz(pd->orient)*/, zeroweight = EINA_FALSE;
   Evas_Coord ow, oh, want, scr_x, scr_y;
   int boxx, boxy, boxw, boxh, length, pad, extra = 0, rounding = 0;
   int boxl = 0, boxr = 0, boxt = 0, boxb = 0;
   double cur_pos = 0, scale, box_align[2],  weight[2] = { 0, 0 };
   Eina_Bool box_fill[2] = { EINA_FALSE, EINA_FALSE };
   Efl_Ui_List_LayoutItem* layout_item;
   Efl_Ui_List_SegArray_Node *items_node;
   unsigned int i;
   int j = 0;

   _calc_range(pd);

   evas_object_geometry_get(pd->modeler, &boxx, &boxy, &boxw, &boxh);
   efl_gfx_size_hint_margin_get(pd->modeler, &boxl, &boxr, &boxt, &boxb);

   scale = evas_object_scale_get(pd->modeler);
   // Box align: used if "item has max size and fill" or "no item has a weight"
   // Note: cells always expand on the orthogonal direction
   box_align[0] = 0;/*pd->align.h;*/
   box_align[1] = 0;/*pd->align.v;*/
   if (box_align[0] < 0)
     {
        box_fill[0] = EINA_TRUE;
        box_align[0] = 0.5;
     }
   if (box_align[1] < 0)
     {
        box_fill[1] = EINA_TRUE;
        box_align[1] = 0.5;
     }

   // box outer margin
   boxw -= boxl + boxr;
   boxh -= boxt + boxb;
   boxx += boxl;
   boxy += boxt;

   // total space & available space
   if (horiz)
     {
        length = boxw;
        want = pd->min.w;
        pad = 0;//pd->pad.scalable ? (pd->pad.h * scale) : pd->pad.h;
     }
   else
     {
        length = boxh;
        want = pd->min.h;
        pad = 0;//pd->pad.scalable ? (pd->pad.v * scale) : pd->pad.v;
     }

   // padding can not be squeezed (note: could make it an option)
   length -= pad * (pd->count_total - 1);
   // available space. if <0 we overflow
   extra = length - want;

   /* Evas_Coord minw = pd->min.w + boxl + boxr; */
   /* Evas_Coord minh = pd->min.h + boxt + boxb; */

   efl_ui_list_model_min_size_set(pd->modeler, pd->min);
   if (extra < 0) extra = 0;

   weight[0] = 1;//pd->weight.x;
   weight[1] = 1;//pd->weight.y;
   if (EINA_DBL_EQ(weight[!horiz], 0))
     {
        if (box_fill[!horiz])
          {
             // box is filled, set all weights to be equal
             zeroweight = EINA_TRUE;
          }
        else
          {
             // move bounding box according to box align
             cur_pos = extra * box_align[!horiz];
          }
        weight[!horiz] = pd->count;
     }

   elm_interface_scrollable_content_viewport_geometry_get
              (pd->modeler, NULL, NULL, &ow, &oh);

   elm_interface_scrollable_content_pos_get(pd->modeler, &scr_x, &scr_y);

   DBG("scr_x: %d, scr_y: %d\n", (int)scr_x, (int)scr_y);
   
   // scan all items, get their properties, calculate total weight & min size
   // cache size of new items
   Eina_Accessor *nodes = efl_ui_list_segarray_node_accessor_get(pd->segarray);

   /* int sum_node_top = 0; */
   
   EINA_ACCESSOR_FOREACH(nodes, i, items_node)
     {
       Efl_Ui_List_Precise_Layouter_Node_Data *nodedata = items_node->layout_data;
       if (!nodedata)
         {
           DBG("no data in node!");
           continue;
         }

       /* int start_pos = ; */
       /* if(start_pos < 0) */
      /*   start_pos = 0; */
       if(scr_y < cur_pos + nodedata->min.h + boxh
          && scr_y + boxh + boxh > cur_pos) // start in this node
         {
            DBG("cur_pos: %d\n", (int)cur_pos);

            for(j = 0; j != items_node->length && scr_y + boxh + boxh > cur_pos;++j)
              {
                 DBG("cur_pos item by item: %d\n", (int)cur_pos);
                 layout_item = (Efl_Ui_List_LayoutItem *)items_node->pointers[j];
                 double cx, cy, cw, ch, x, y, w, h;
                 double weight_x, weight_y;
                 double align[2];
                 int item_pad[4];
                 Eina_Size2D max;
                 int pad = 0;

                 if(layout_item->min.w && layout_item->min.h)
                   {
//        DBG("size information for item %d width %d height %d", j, layout_item->min.w, layout_item->min.h);
                      if(!layout_item->layout)
                        {
                           DBG("realizing showing item\n");
                           efl_ui_list_model_realize(pd->modeler, layout_item);
                           assert(layout_item->layout != NULL);
                        }
                      efl_gfx_size_hint_weight_get(layout_item->layout, &weight_x, &weight_y);
                      efl_gfx_size_hint_align_get(layout_item->layout, &align[0], &align[1]);
                      max = efl_gfx_size_hint_max_get(layout_item->layout);
                      efl_gfx_size_hint_margin_get(layout_item->layout, &item_pad[0], &item_pad[1], &item_pad[2], &item_pad[3]);

                      if (align[0] < 0) align[0] = -1;
                      if (align[1] < 0) align[1] = -1;
                      if (align[0] > 1) align[0] = 1;
                      if (align[1] > 1) align[1] = 1;

                      if (max.w <= 0) max.w = INT_MAX;
                      if (max.h <= 0) max.h = INT_MAX;
                      if (max.w < layout_item->min.w) max.w = layout_item->min.w;
                      if (max.h < layout_item->min.h) max.h = layout_item->min.h;

                      // extra rounding up (compensate cumulative error)
                      if ((i == (pd->count - 1)) && (cur_pos - floor(cur_pos) >= 0.5))
                        rounding = 1;

                      if (horiz)
                        {
                           cx = boxx + cur_pos;
                           cy = boxy;
                           cw = layout_item->min.w + rounding + (zeroweight ? 1.0 : weight_x) * extra / weight[0];
                           ch = boxh;
                           cur_pos += cw + pad;
                        }
                      else
                        {
                           cx = boxx;
                           cy = boxy + cur_pos;
                           cw = boxw;
                           ch = layout_item->min.h + rounding + (zeroweight ? 1.0 : weight_y) * extra / weight[1];
                           cur_pos += ch + pad;
                        }

                      // horizontally
                      if (max.w < INT_MAX)
                        {
                           w = MIN(MAX(layout_item->min.w - item_pad[0] - item_pad[1], max.w), cw);
                           if (align[0] < 0)
                             {
                                // bad case: fill+max are not good together
                               x = cx + ((cw - w) * box_align[0]) + item_pad[0];
                             }
                           else
                             x = cx + ((cw - w) * align[0]) + item_pad[0];
                        }
                      else if (align[0] < 0)
                        {
                           // fill x
                          w = cw - item_pad[0] - item_pad[1];
                          x = cx + item_pad[0];
                        }
                      else
                        {
                           w = layout_item->min.w - item_pad[0] - item_pad[1];
                           x = cx + ((cw - w) * align[0]) + item_pad[0];
                        }

                      // vertically
                      if (max.h < INT_MAX)
                        {
                           h = MIN(MAX(layout_item->min.h - item_pad[2] - item_pad[3], max.h), ch);
                           if (align[1] < 0)
                             {
                               // bad case: fill+max are not good together
                               y = cy + ((ch - h) * box_align[1]) + item_pad[2];
                             }
                           else
                             y = cy + ((ch - h) * align[1]) + item_pad[2];
                        }
                      else if (align[1] < 0)
                        {
                           // fill y
                          h = ch - item_pad[2] - item_pad[3];
                          y = cy + item_pad[2];
                        }
                      else
                        {
                           h = layout_item->min.h - item_pad[2] - item_pad[3];
                           y = cy + ((ch - h) * align[1]) + item_pad[2];
                        }

                      if (horiz)
                        {
                           if (h < pd->min.h) h = pd->min.h;
                           if (h > oh) h = oh;
                        }
                      else
                        {
                           if (w < pd->min.w) w = pd->min.w;
                           if (w > ow) w = ow;
                        }

                      //        DBG("------- x=%0.f, y=%0.f, w=%0.f, h=%0.f --- ", x, y, w, h);
                      evas_object_geometry_set(layout_item->layout, (x + 0 - scr_x), (y + 0 - scr_y), w, h);

                      // layout_item->x = x;
                      // layout_item->y = y; 

                      } /* if (size) end */
              }
         }
       else if (nodedata->realized) // unrealize
         {
            for(j = 0; j != items_node->length;++j)
              {
                 layout_item = (Efl_Ui_List_LayoutItem *)items_node->pointers[j];
                 if(layout_item->layout)
                   efl_ui_list_model_unrealize(pd->modeler, layout_item);
              }
            nodedata->realized = EINA_FALSE;
            cur_pos += nodedata->min.h;
         }
       else
         {
            cur_pos += nodedata->min.h;
         }
   } /* EINA ACCESSOR FOREACH END */
   eina_accessor_free(nodes);
}

EOLIAN static void
_efl_ui_list_precise_layouter_efl_ui_list_relayout_layout_do
  (Eo *obj EINA_UNUSED, Efl_Ui_List_Precise_Layouter_Data *pd
   , Efl_Ui_List_Model *modeler, int first, Efl_Ui_List_SegArray *segarray)
{
   _initilize(obj, pd, modeler, segarray);

   pd->first = first;

   if (pd->recalc)
     {
        // cache size of new items
        pd->calc_progress = 0;
        ecore_job_del(pd->calc_job);
        pd->calc_job = ecore_job_add(_calc_size_job, obj);
        return;
     }

   _efl_ui_list_relayout_layout_do(pd);
}

#include "efl_ui_list_precise_layouter.eo.c"