summaryrefslogtreecommitdiff
path: root/src/lib/elementary/efl_ui_spotlight_container.c
blob: 608aca1d3c0aeaf5142f47adeae241960cb0f09b (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
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#include <Efl_Ui.h>
#include "elm_priv.h"
#include "efl_ui_spotlight_manager_plain.eo.h"

typedef struct _Efl_Ui_Spotlight_Container_Data
{
   Eina_List *content_list;
   Eo *page_root, *event;
   struct {
      Eina_Size2D sz;
   } page_spec;
   struct {
      Efl_Ui_Widget *page;
      double pos;
   } curr;
   struct {
     int from;
     int to;
     double last_pos;
     Eina_Bool active;
   } show_request;
   struct {
     Eina_Promise *transition_done;
     Efl_Gfx_Entity *content;
   } transition_done;
   Efl_Ui_Spotlight_Manager *transition;
   Efl_Ui_Spotlight_Indicator *indicator;
   double position;
   Eina_Bool fill_width: 1;
   Eina_Bool fill_height: 1;
   Eina_Bool prevent_transition_interaction : 1;
} Efl_Ui_Spotlight_Container_Data;

#define MY_CLASS EFL_UI_SPOTLIGHT_CONTAINER_CLASS

static void
_fetch_partners(Eina_List *list, Eo *subobj, Eo **next, Eo **prev)
{
   Eina_List *node = eina_list_data_find_list(list, subobj);
   *next = eina_list_data_get(eina_list_next(node));
   *prev = eina_list_data_get(eina_list_prev(node));
}

static void _unpack(Eo *obj, Efl_Ui_Spotlight_Container_Data *pd, Efl_Gfx_Entity *subobj, int index);
static void _unpack_all(Eo *obj EINA_UNUSED, Efl_Ui_Spotlight_Container_Data *pd, Eina_Bool clear);

static int
clamp_index(Efl_Ui_Spotlight_Container_Data *pd, int index)
{
   if (index < ((int)eina_list_count(pd->content_list)) * -1)
     return -1;
   else if (index > (int)eina_list_count(pd->content_list) - 1)
     return 1;
   return 0;
}

static int
index_rollover(Efl_Ui_Spotlight_Container_Data *pd, int index)
{
   int c = eina_list_count(pd->content_list);
   if (index < c * -1)
     return 0;
   else if (index > c - 1)
     return c - 1;
   else if (index < 0)
     return index + c;
   return index;
}

static void
_transition_end(Eo *obj EINA_UNUSED, Efl_Ui_Spotlight_Container_Data *pd)
{
   Efl_Ui_Spotlight_Transition_Event ev;

   if (pd->prevent_transition_interaction) return;

   if (pd->transition_done.content)
     {
        Eina_Value v = eina_value_object_init(pd->transition_done.content);
        //first store the fields, then NULL them, then resolve the situation, otherwise we might get trapped in a endless recursion
        Eina_Promise *p = pd->transition_done.transition_done;
        Eo *content = pd->transition_done.content;
        pd->transition_done.transition_done = NULL;
        pd->transition_done.content = NULL;
        efl_pack_unpack(obj, content);
        eina_promise_resolve(p , v);
     }

   ev.from = pd->show_request.from;
   ev.to = pd->show_request.to;
   efl_event_callback_call(obj, EFL_UI_SPOTLIGHT_EVENT_TRANSITION_END, &ev);
   pd->show_request.active = EINA_FALSE;
   pd->show_request.from = -1;
   pd->show_request.to = -1;
}

static void
_transition_start(Eo *obj EINA_UNUSED, Efl_Ui_Spotlight_Container_Data *pd, int from, int to, double progress)
{
   Efl_Ui_Spotlight_Transition_Event ev;

   if (pd->prevent_transition_interaction) return;

   if (pd->show_request.active)
     _transition_end(obj, pd);

   pd->show_request.active = EINA_TRUE;
   pd->show_request.from = from;
   pd->show_request.to = to;
   pd->show_request.last_pos = progress;
   ev.from = pd->show_request.from;
   ev.to = pd->show_request.to;
   efl_event_callback_call(obj, EFL_UI_SPOTLIGHT_EVENT_TRANSITION_START, &ev);
}

static void
_position_set(Eo *obj EINA_UNUSED, Efl_Ui_Spotlight_Container_Data *pd, double progress)
{
   if (progress < -1.0) progress = -1.0;
   if (progress > eina_list_count(pd->content_list)) progress = eina_list_count(pd->content_list);
   if (pd->indicator)
     {
        efl_ui_spotlight_indicator_position_update(pd->indicator, progress);
     }
   pd->position = progress;
}

static void
_transition_event_emission(Eo *obj EINA_UNUSED, Efl_Ui_Spotlight_Container_Data *pd)
{
   if (pd->show_request.active)
     {
        if ((pd->show_request.to != -1 || pd->show_request.from != -1) &&
            fabs(pd->show_request.last_pos - pd->show_request.to) < fabs(pd->position - pd->show_request.to))
          {
             //abort event here, movement is not in the direction we request
             pd->show_request.to = -1;
             _transition_end(obj, pd);
          }
        if (pd->position == pd->show_request.to)
          {
             //successfully there
             _transition_end(obj, pd);
          }
     }
   else
     {
        //the progress changed without a show_request beeing active. instaciate a new one
        _transition_start(obj, pd, -1, -1, pd->position);
     }
}

static void
_resize_cb(void *data, const Efl_Event *ev)
{
   Efl_Ui_Spotlight_Container_Data *pd = data;
   Eina_Size2D sz;

   sz = efl_gfx_entity_size_get(ev->object);

   if (pd->fill_width) pd->page_spec.sz.w = sz.w;
   if (pd->fill_height) pd->page_spec.sz.h = sz.h;

   if (pd->transition)
     efl_ui_spotlight_manager_size_set(pd->transition, pd->page_spec.sz);
}

EOLIAN static Eo *
_efl_ui_spotlight_container_efl_object_constructor(Eo *obj,
                                     Efl_Ui_Spotlight_Container_Data *pd)
{
   ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, NULL);

   if (!elm_widget_theme_klass_get(obj))
     elm_widget_theme_klass_set(obj, "pager");

   obj = efl_constructor(efl_super(obj, MY_CLASS));

   if (elm_widget_theme_object_set(obj, wd->resize_obj,
                                       elm_widget_theme_klass_get(obj),
                                       elm_widget_theme_element_get(obj),
                                       elm_widget_theme_style_get(obj)) == EFL_UI_THEME_APPLY_ERROR_GENERIC)
     CRI("Failed to set layout!");

   pd->position = -1;
   pd->curr.page = NULL;
   pd->curr.pos = 0.0;

   pd->transition = NULL;
   pd->indicator = NULL;

   pd->fill_width = EINA_TRUE;
   pd->fill_height = EINA_TRUE;

   efl_ui_spotlight_size_set(obj, EINA_SIZE2D(-1, -1));

   elm_widget_can_focus_set(obj, EINA_FALSE);

   pd->page_root = efl_add(EFL_CANVAS_GROUP_CLASS, evas_object_evas_get(obj));
   efl_content_set(efl_part(obj, "efl.page_root"), pd->page_root);

   efl_event_callback_add(pd->page_root, EFL_GFX_ENTITY_EVENT_SIZE_CHANGED, _resize_cb, pd);

   pd->event = efl_add(EFL_CANVAS_RECTANGLE_CLASS,
                       evas_object_evas_get(obj));
   evas_object_color_set(pd->event, 0, 0, 0, 0);
   evas_object_repeat_events_set(pd->event, EINA_TRUE);
   efl_content_set(efl_part(obj, "efl.event"), pd->event);

   return obj;
}

EOLIAN static Efl_Object*
_efl_ui_spotlight_container_efl_object_finalize(Eo *obj, Efl_Ui_Spotlight_Container_Data *pd EINA_UNUSED)
{
   Efl_Ui_Spotlight_Manager *manager;

   obj = efl_finalize(efl_super(obj, MY_CLASS));

   manager = efl_ui_spotlight_manager_get(obj);
   //set a view manager in case nothing is here
   if (!manager)
     {
         efl_ui_spotlight_manager_set(obj, efl_new(EFL_UI_SPOTLIGHT_MANAGER_PLAIN_CLASS));
     }
   else
     {
        efl_ui_spotlight_manager_animation_enabled_set(manager, EINA_TRUE);
     }

   return obj;
}

EOLIAN static void
_efl_ui_spotlight_container_efl_object_invalidate(Eo *obj,
                                    Efl_Ui_Spotlight_Container_Data *pd)
{
   _unpack_all(obj, pd, EINA_TRUE);
   efl_invalidate(efl_super(obj, MY_CLASS));
}

EOLIAN static int
_efl_ui_spotlight_container_efl_container_content_count(Eo *obj EINA_UNUSED,
                                          Efl_Ui_Spotlight_Container_Data *pd)
{
   return eina_list_count(pd->content_list);
}

static void
_child_inv(void *data, const Efl_Event *ev)
{
   Efl_Ui_Spotlight_Container_Data *pd = efl_data_scope_get(data, MY_CLASS);
   int index = eina_list_data_idx(pd->content_list, ev->object);
   _unpack(data, pd, ev->object, index);
}

static Eina_Bool
_register_child(Eo *obj EINA_UNUSED, Efl_Ui_Spotlight_Container_Data *pd, Efl_Gfx_Entity *subobj)
{
   EINA_SAFETY_ON_NULL_RETURN_VAL(subobj, EINA_FALSE);
   if (eina_list_data_find(pd->content_list, subobj))
     {
        ERR("Object %p is already part of this!", subobj);
        return EINA_FALSE;
     }
   if (!efl_ui_widget_sub_object_add(obj, subobj))
     return EINA_FALSE;

   efl_event_callback_add(subobj, EFL_EVENT_INVALIDATE, _child_inv, obj);

   return EINA_TRUE;
}

static void
_update_internals(Eo *obj EINA_UNUSED, Efl_Ui_Spotlight_Container_Data *pd, Efl_Gfx_Entity *subobj EINA_UNUSED, int index)
{
   pd->prevent_transition_interaction = EINA_TRUE;
   if (pd->transition)
     efl_ui_spotlight_manager_content_add(pd->transition, subobj, index);
   if (pd->indicator)
     efl_ui_spotlight_indicator_content_add(pd->indicator, subobj, index);
   pd->prevent_transition_interaction = EINA_FALSE;
   if (eina_list_count(pd->content_list) == 1)
     efl_ui_spotlight_active_element_set(obj, subobj);
}

EOLIAN static Eina_Bool
_efl_ui_spotlight_container_efl_pack_linear_pack_begin(Eo *obj EINA_UNUSED,
                                         Efl_Ui_Spotlight_Container_Data *pd,
                                         Efl_Gfx_Entity *subobj)
{
   if (!_register_child(obj, pd, subobj)) return EINA_FALSE;
   pd->content_list = eina_list_prepend(pd->content_list, subobj);
   _update_internals(obj, pd, subobj, 0);
   return EINA_TRUE;
}

EOLIAN static Eina_Bool
_efl_ui_spotlight_container_efl_pack_linear_pack_end(Eo *obj EINA_UNUSED,
                                       Efl_Ui_Spotlight_Container_Data *pd,
                                       Efl_Gfx_Entity *subobj)
{
   if (!_register_child(obj, pd, subobj)) return EINA_FALSE;
   pd->content_list = eina_list_append(pd->content_list, subobj);
   _update_internals(obj, pd, subobj, eina_list_count(pd->content_list) - 1);
   return EINA_TRUE;
}

EOLIAN static Eina_Bool
_efl_ui_spotlight_container_efl_pack_linear_pack_before(Eo *obj EINA_UNUSED,
                                          Efl_Ui_Spotlight_Container_Data *pd,
                                          Efl_Gfx_Entity *subobj,
                                          const Efl_Gfx_Entity *existing)
{
   int index = eina_list_data_idx(pd->content_list, (void *)existing);
   if (existing)
     EINA_SAFETY_ON_FALSE_RETURN_VAL(index >= 0, EINA_FALSE);

   if (!_register_child(obj, pd, subobj)) return EINA_FALSE;
   pd->content_list = eina_list_prepend_relative(pd->content_list, subobj, existing);
   _update_internals(obj, pd, subobj, index);
   return EINA_TRUE;
}

EOLIAN static Eina_Bool
_efl_ui_spotlight_container_efl_pack_linear_pack_after(Eo *obj EINA_UNUSED,
                                         Efl_Ui_Spotlight_Container_Data *pd,
                                         Efl_Gfx_Entity *subobj,
                                         const Efl_Gfx_Entity *existing)
{
   int index = eina_list_data_idx(pd->content_list, (void *)existing);
   if (existing)
     EINA_SAFETY_ON_FALSE_RETURN_VAL(index >= 0, EINA_FALSE);

   if (!_register_child(obj, pd, subobj)) return EINA_FALSE;
   pd->content_list = eina_list_append_relative(pd->content_list, subobj, existing);
   _update_internals(obj, pd, subobj, index + 1);
   return EINA_TRUE;
}

EOLIAN static Eina_Bool
_efl_ui_spotlight_container_efl_pack_linear_pack_at(Eo *obj,
                                      Efl_Ui_Spotlight_Container_Data *pd,
                                      Efl_Gfx_Entity *subobj,
                                      int index)
{
   Efl_Gfx_Entity *existing = NULL;

   if (!_register_child(obj, pd, subobj)) return EINA_FALSE;
   int clamp = clamp_index(pd, index);
   int pass_index = -1;
   if (clamp == 0)
     {
        existing = eina_list_nth(pd->content_list, index_rollover(pd, index));
        pd->content_list = eina_list_prepend_relative(
           pd->content_list, subobj, existing);
     }
   else if (clamp == 1)
     {
        pd->content_list = eina_list_append(pd->content_list, subobj);
        pass_index = eina_list_count(pd->content_list);
     }
   else
     {
        pd->content_list = eina_list_prepend(pd->content_list, subobj);
        pass_index = 0;
     }
   _update_internals(obj, pd, subobj, pass_index);

   return EINA_TRUE;
}

EOLIAN static Efl_Gfx_Entity *
_efl_ui_spotlight_container_efl_pack_linear_pack_content_get(Eo *obj EINA_UNUSED,
                                               Efl_Ui_Spotlight_Container_Data *pd,
                                               int index)
{
   return eina_list_nth(pd->content_list, index_rollover(pd, index));
}

EOLIAN static int
_efl_ui_spotlight_container_efl_pack_linear_pack_index_get(Eo *obj EINA_UNUSED,
                                             Efl_Ui_Spotlight_Container_Data *pd,
                                             const Efl_Gfx_Entity *subobj)
{
   return eina_list_data_idx(pd->content_list, (void *)subobj);
}

EOLIAN static void
_efl_ui_spotlight_container_active_element_set(Eo *obj EINA_UNUSED,
                               Efl_Ui_Spotlight_Container_Data *pd,
                               Efl_Ui_Widget *new_page)
{
   int before = -1;
   int index;

   if (pd->curr.page)
     before = efl_pack_index_get(obj, pd->curr.page);
   index = efl_pack_index_get(obj, new_page);

   EINA_SAFETY_ON_FALSE_RETURN(index != -1);

   pd->show_request.last_pos = efl_pack_index_get(obj, pd->curr.page);
   pd->show_request.from = efl_pack_index_get(obj, pd->curr.page);
   pd->show_request.to = index;

   if (pd->show_request.active && pd->show_request.from == -1 && pd->show_request.to)
     pd->show_request.to = index; //we just edit this here, a user animation will end when the progress is at the goal.
   else
     {
        _transition_start(obj, pd, before, index, before);
     }

   pd->curr.page = new_page;
   efl_ui_spotlight_manager_switch_to(pd->transition, before, index);
}

EOLIAN static Efl_Ui_Widget*
_efl_ui_spotlight_container_active_element_get(const Eo *obj EINA_UNUSED,
                               Efl_Ui_Spotlight_Container_Data *pd)
{
   return pd->curr.page;
}

EOLIAN Eina_Size2D
_efl_ui_spotlight_container_spotlight_size_get(const Eo *obj EINA_UNUSED,
                            Efl_Ui_Spotlight_Container_Data *pd)
{
   return pd->page_spec.sz;
}

EOLIAN static void
_efl_ui_spotlight_container_spotlight_size_set(Eo *obj,
                            Efl_Ui_Spotlight_Container_Data *pd,
                            Eina_Size2D sz)
{
   Eina_Size2D size;
   if (sz.w < -1 || sz.h < -1) return;

   pd->page_spec.sz = sz;
   pd->fill_width = sz.w == -1 ? EINA_TRUE : EINA_FALSE;
   pd->fill_height = sz.h == -1 ? EINA_TRUE : EINA_FALSE;

   size = efl_gfx_entity_size_get(obj);
   if (pd->fill_height)
     pd->page_spec.sz.h = size.h;
   if (pd->fill_width)
     pd->page_spec.sz.w = size.w;

   if (pd->transition)
     efl_ui_spotlight_manager_size_set(pd->transition, pd->page_spec.sz);
}

static void
_unpack_all(Eo *obj EINA_UNUSED,
            Efl_Ui_Spotlight_Container_Data *pd,
            Eina_Bool clear)
{
   pd->curr.page = NULL;

   while(pd->content_list)
     {
        Eo *content = eina_list_data_get(pd->content_list);

        if (clear)
          efl_del(content);
        else
          _unpack(obj, pd, content, 0);
     }
}

EOLIAN static Eina_Bool
_efl_ui_spotlight_container_efl_pack_pack_clear(Eo *obj EINA_UNUSED,
                                  Efl_Ui_Spotlight_Container_Data *pd)
{
   _unpack_all(obj, pd, EINA_TRUE);

   return EINA_TRUE;
}

EOLIAN static Eina_Bool
_efl_ui_spotlight_container_efl_pack_unpack_all(Eo *obj EINA_UNUSED,
                                  Efl_Ui_Spotlight_Container_Data *pd)
{
   _unpack_all(obj, pd, EINA_FALSE);

   return EINA_TRUE;
}

static void
_unpack(Eo *obj,
        Efl_Ui_Spotlight_Container_Data *pd,
        Efl_Gfx_Entity *subobj,
        int index)
{
   int early_curr_page = efl_pack_index_get(obj, pd->curr.page);
   Eina_Bool deletion_of_active = (subobj == pd->curr.page);
   Efl_Ui_Widget *next, *prev;

   _fetch_partners(pd->content_list, subobj, &next, &prev);
   pd->content_list = eina_list_remove(pd->content_list, subobj);
   _elm_widget_sub_object_redirect_to_top(obj, subobj);

   if (!efl_alive_get(obj)) return;

   if (pd->transition)
     efl_ui_spotlight_manager_content_del(pd->transition, subobj, index);
   if (pd->indicator)
     efl_ui_spotlight_indicator_content_del(pd->indicator, subobj, index);

   //we deleted the current index
   if (deletion_of_active)
     {
        if (eina_list_count(pd->content_list) == 0)
          {
             pd->curr.page = NULL;
          }
        else
          {
             //when we delete the active index and we are not updating the index,
             // then force a update, so the same sort of animation is triggered from the right direction
             if (early_curr_page == efl_pack_index_get(obj, prev))
               pd->curr.page = eina_list_nth(pd->content_list, early_curr_page - 1);

             if (prev)
               efl_ui_spotlight_active_element_set(obj, prev);
             else
               efl_ui_spotlight_active_element_set(obj, next);
          }
     }

   //position has updated
   if (deletion_of_active &&
       pd->indicator && !pd->transition)
     efl_ui_spotlight_indicator_position_update(pd->indicator, efl_pack_index_get(obj, pd->curr.page));

   efl_event_callback_del(subobj, EFL_EVENT_INVALIDATE, _child_inv, obj);
}

EOLIAN static Eina_Bool
_efl_ui_spotlight_container_efl_pack_unpack(Eo *obj,
                              Efl_Ui_Spotlight_Container_Data *pd,
                              Efl_Gfx_Entity *subobj)
{
   if (!subobj) return EINA_FALSE;

   int index = eina_list_data_idx(pd->content_list, subobj);
   if (index == -1)
     {
        ERR("Item %p is not part of this container", subobj);
        return EINA_FALSE;
     }

   _unpack(obj, pd, subobj, index);

   return EINA_TRUE;
}

EOLIAN static Efl_Gfx_Entity *
_efl_ui_spotlight_container_efl_pack_linear_pack_unpack_at(Eo *obj,
                                             Efl_Ui_Spotlight_Container_Data *pd,
                                             int index)
{
   Efl_Gfx_Entity *subobj = eina_list_nth(pd->content_list, index_rollover(pd, index_rollover(pd, index)));

   _unpack(obj, pd, subobj, index);

   return subobj;
}

EOLIAN static Eina_Bool
_efl_ui_spotlight_container_efl_pack_pack(Eo *obj, Efl_Ui_Spotlight_Container_Data *pd EINA_UNUSED, Efl_Gfx_Entity *subobj)
{
   return efl_pack_begin(obj, subobj);
}

EOLIAN static Eina_Iterator*
_efl_ui_spotlight_container_efl_container_content_iterate(Eo *obj EINA_UNUSED, Efl_Ui_Spotlight_Container_Data *pd)
{
  return eina_list_iterator_new(pd->content_list);
}

static void
_pos_updated(void *data, const Efl_Event *event)
{
   Efl_Ui_Spotlight_Container_Data *pd = efl_data_scope_get(data, MY_CLASS);
   double progress = *((double*)event->info);
   //ignore this here, this could result in unintendet transition,start / end calls
   if (EINA_DBL_EQ(progress, pd->position))
     return;
   _position_set(data, pd, progress);
   _transition_event_emission(data, pd);
}

EOLIAN static void
_efl_ui_spotlight_container_spotlight_manager_set(Eo *obj, Efl_Ui_Spotlight_Container_Data *pd, Efl_Ui_Spotlight_Manager *transition)
{
   if (!transition)
     pd->transition = efl_add(EFL_UI_SPOTLIGHT_MANAGER_PLAIN_CLASS, obj);
   else
     EINA_SAFETY_ON_FALSE_RETURN(efl_isa(transition, EFL_UI_SPOTLIGHT_MANAGER_CLASS));

   if (pd->transition)
     {
        efl_ui_spotlight_manager_bind(pd->transition, NULL, NULL);
        efl_del(pd->transition);
     }

   pd->transition = transition;

   if (pd->transition)
     {
        EINA_SAFETY_ON_FALSE_RETURN(efl_ownable_get(pd->transition));
        efl_parent_set(pd->transition, obj);
        //the api indicates that the caller passes ownership to this function, so we need to unref here
        efl_unref(pd->transition);
        //disable animation when not finalized yet, this help reducing the overhead of scheduling a animation that will not be displayed
        efl_ui_spotlight_manager_animation_enabled_set(pd->transition, efl_finalized_get(obj));
        efl_ui_spotlight_manager_bind(pd->transition, obj,
          pd->page_root);
        efl_ui_spotlight_manager_size_set(pd->transition, pd->page_spec.sz);
        efl_event_callback_add(pd->transition, EFL_UI_SPOTLIGHT_MANAGER_EVENT_POS_UPDATE, _pos_updated, obj);
     }

}

EOLIAN static Efl_Ui_Spotlight_Manager*
_efl_ui_spotlight_container_spotlight_manager_get(const Eo *obj EINA_UNUSED, Efl_Ui_Spotlight_Container_Data *pd)
{
   if (efl_isa(pd->transition, EFL_UI_SPOTLIGHT_MANAGER_PLAIN_CLASS))
     return NULL;
   else
     return pd->transition;
}

EOLIAN static void
_efl_ui_spotlight_container_indicator_set(Eo *obj, Efl_Ui_Spotlight_Container_Data *pd, Efl_Ui_Spotlight_Indicator *indicator)
{
   if (pd->indicator)
     {
        efl_ui_spotlight_indicator_bind(pd->indicator, obj);
        efl_del(pd->indicator);
     }
   pd->indicator = indicator;
   if (pd->indicator)
     {
        EINA_SAFETY_ON_FALSE_RETURN(efl_ownable_get(pd->indicator));
        efl_parent_set(pd->indicator, obj);
        //the api indicates that the caller passes ownership to this function, so we need to unref here
        efl_unref(pd->indicator);
        efl_ui_spotlight_indicator_bind(pd->indicator, obj);
        if (pd->position != -1)
          efl_ui_spotlight_indicator_position_update(pd->indicator, pd->position);
     }
}

EOLIAN static Efl_Ui_Spotlight_Indicator*
_efl_ui_spotlight_container_indicator_get(const Eo *obj EINA_UNUSED, Efl_Ui_Spotlight_Container_Data *pd)
{
   return pd->indicator;
}

EOLIAN static void
_efl_ui_spotlight_container_push(Eo *obj, Efl_Ui_Spotlight_Container_Data *pd EINA_UNUSED, Efl_Gfx_Entity *view)
{
   if (efl_ui_spotlight_active_element_get(obj))
     {
        if (!efl_pack_before(obj, view, efl_ui_spotlight_active_element_get(obj)))
          return;
     }
   else
     {
        if (!efl_pack_begin(obj, view))
          return;
     }

   efl_ui_spotlight_active_element_set(obj, view);
}

static Eina_Value
_delete_obj(void *data EINA_UNUSED, const Eina_Value value, const Eina_Future *dead_future EINA_UNUSED)
{
   efl_del(eina_value_object_get(&value));

   return EINA_VALUE_EMPTY;
}

EOLIAN static Eina_Future*
_efl_ui_spotlight_container_pop(Eo *obj, Efl_Ui_Spotlight_Container_Data *pd, Eina_Bool del)
{
   Eina_Future *transition_done;
   Eina_Value v;
   int new_index;
   int count;
   Eo *content;

   count = (int)eina_list_count(pd->content_list);

   if (count == 0) return NULL;

   content = efl_ui_spotlight_active_element_get(obj);

   //pop() unpacks content without transition if there is one content.
   if (count == 1)
     {
        efl_pack_unpack(obj, content);
        pd->curr.page = NULL;

        if (del)
          {
             efl_del(content);
             v = EINA_VALUE_EMPTY;
          }
        else
          {
             v = eina_value_object_init(content);
          }
        return efl_loop_future_resolved(obj, v);
     }

   new_index = efl_pack_index_get(obj, efl_ui_spotlight_active_element_get(obj)) + 1;
   if (new_index >= count)
     new_index -= 2;

   pd->transition_done.content = content;
   pd->transition_done.transition_done = efl_loop_promise_new(obj);

   transition_done = eina_future_new(pd->transition_done.transition_done);
   if (del)
     transition_done = eina_future_then(transition_done, _delete_obj, NULL);

   efl_ui_spotlight_active_element_set(obj, efl_pack_content_get(obj, new_index));

   return transition_done;
}


#include "efl_ui_spotlight_container.eo.c"