summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-08-18 20:24:02 +0200
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-08-18 20:24:02 +0200
commit8d35a283b0f20fbcab42d32b565d8bb064573e22 (patch)
treedb3c8e99081039fd3b7d62a99a15f651154c4e75
parent6e58aa151d8ecb4ba7aeed3b339bf697007aa70d (diff)
-rw-r--r--src/lib/elementary/efl_ui_collection.c94
1 files changed, 17 insertions, 77 deletions
diff --git a/src/lib/elementary/efl_ui_collection.c b/src/lib/elementary/efl_ui_collection.c
index a7f42ef3a8..a4907a0a5a 100644
--- a/src/lib/elementary/efl_ui_collection.c
+++ b/src/lib/elementary/efl_ui_collection.c
@@ -21,65 +21,26 @@ typedef struct {
21 unsigned int last_index; 21 unsigned int last_index;
22 const Eina_List *current; 22 const Eina_List *current;
23 Eina_List **items; 23 Eina_List **items;
24 Eina_Array *cache;
24} Fast_Accessor; 25} Fast_Accessor;
25 26
26static const Eina_List* 27static const Eina_List*
27_fast_accessor_get_at(Fast_Accessor *accessor, unsigned int idx) 28_fast_accessor_get_at(Fast_Accessor *accessor, unsigned int idx)
28{ 29{
29 const Eina_List *over; 30 if (!accessor->cache)
30 unsigned int middle;
31 unsigned int i;
32
33 if (idx >= eina_list_count(*accessor->items))
34 return NULL;
35
36 if (accessor->last_index == idx)
37 over = accessor->current;
38 else if (idx > accessor->last_index)
39 {
40 /* After current position. */
41 middle = ((eina_list_count(*accessor->items) - accessor->last_index))/2;
42
43 if (idx > middle)
44 /* Go backward from the end. */
45 for (i = eina_list_count(*accessor->items) - 1,
46 over = eina_list_last(*accessor->items);
47 i > idx && over;
48 --i, over = eina_list_prev(over))
49 ;
50 else
51 /* Go forward from current. */
52 for (i = accessor->last_index, over = accessor->current;
53 i < idx && over;
54 ++i, over = eina_list_next(over))
55 ;
56 }
57 else
58 { 31 {
59 /* Before current position. */ 32 Eina_List *n;
60 middle = accessor->last_index/2; 33 Eo *o;
61
62 if (idx > middle)
63 /* Go backward from current. */
64 for (i = accessor->last_index, over = accessor->current;
65 i > idx && over;
66 --i, over = eina_list_prev(over))
67 ;
68 else
69 /* Go forward from start. */
70 for (i = 0, over = *accessor->items;
71 i < idx && over;
72 ++i, over = eina_list_next(over))
73 ;
74 }
75
76 if (!over)
77 return NULL;
78 34
79 accessor->last_index = idx; 35 accessor->cache = eina_array_new(100);
80 accessor->current = over;
81 36
82 return over; 37 EINA_LIST_FOREACH(*accessor->items, n, o)
38 {
39 eina_array_push(accessor->cache, n);
40 printf("%p\n", o);
41 }
42 }
43 return eina_array_data_get(accessor->cache, idx);
83} 44}
84 45
85static void 46static void
@@ -94,32 +55,9 @@ _fast_accessor_init(Fast_Accessor *accessor, Eina_List **items)
94static void 55static void
95_fast_accessor_remove(Fast_Accessor *accessor, const Eina_List *removed_elem) 56_fast_accessor_remove(Fast_Accessor *accessor, const Eina_List *removed_elem)
96{ 57{
97 if (accessor->current == removed_elem) 58 if (accessor->cache)
98 { 59 eina_array_free(accessor->cache);
99 Eina_List *next; 60 accessor->cache = NULL;
100 Eina_List *prev;
101
102 next = eina_list_next(removed_elem);
103 prev = eina_list_prev(removed_elem);
104 if (next)
105 {
106 accessor->current = next;
107 accessor->last_index ++;
108 }
109 else if (prev)
110 {
111 accessor->current = prev;
112 accessor->last_index --;
113 }
114 else
115 {
116 //everything >= length is invalid, and we need that.
117 accessor->last_index = eina_list_count(*accessor->items);
118 accessor->current = NULL;
119 }
120
121 }
122
123} 61}
124 62
125#define MY_CLASS EFL_UI_COLLECTION_CLASS 63#define MY_CLASS EFL_UI_COLLECTION_CLASS
@@ -587,6 +525,8 @@ register_item(Eo *obj, Efl_Ui_Collection_Data *pd, Efl_Ui_Item *item)
587 efl_canvas_group_member_add(pd->pan, item); 525 efl_canvas_group_member_add(pd->pan, item);
588 efl_event_callback_array_add(item, active_item(), obj); 526 efl_event_callback_array_add(item, active_item(), obj);
589 efl_ui_mirrored_set(item, efl_ui_mirrored_get(obj)); 527 efl_ui_mirrored_set(item, efl_ui_mirrored_get(obj));
528 _fast_accessor_remove(&pd->obj_accessor, NULL);
529 _fast_accessor_remove(&pd->size_accessor, NULL);
590 530
591 return EINA_TRUE; 531 return EINA_TRUE;
592} 532}