summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-02-23 12:57:13 +0100
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-02-25 10:37:39 +0100
commitf1ad1559b7e1ec8e913d95d07de81e42d0434096 (patch)
tree2e163726c5e619df463a28aec80196390e51518d
parent4ccbf201fb5ca59ec74a6bc1e2854cf367b50bc5 (diff)
efl_ui_stack: use direct events instead of event_animation
event_animation of efl_canvas_object, is a little problem, we need to explictly turn it off, to do a visual state manipulation, just to attach the animation again. Further more, the animation objects are stored in static fields, which are not bound to the object. Which means, when two Efl.Ui.Stack objects are running in parrallel, the animation will look a little bit wacky, since the object is detached before the animation is ended. ref T7555 Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Differential Revision: https://phab.enlightenment.org/D8008
-rw-r--r--src/lib/elementary/efl_ui_stack.c182
-rw-r--r--src/lib/elementary/efl_ui_stack_private.h16
2 files changed, 90 insertions, 108 deletions
diff --git a/src/lib/elementary/efl_ui_stack.c b/src/lib/elementary/efl_ui_stack.c
index e4e4ed364a..45f0bed6d4 100644
--- a/src/lib/elementary/efl_ui_stack.c
+++ b/src/lib/elementary/efl_ui_stack.c
@@ -40,15 +40,6 @@ _show_content_without_anim(Efl_Ui_Stack *obj, Evas_Object *content)
40 efl_event_callback_call(obj, EFL_UI_STACK_EVENT_LOADED, 40 efl_event_callback_call(obj, EFL_UI_STACK_EVENT_LOADED,
41 &loaded_info); 41 &loaded_info);
42 42
43 Efl_Canvas_Animation *orig_show_anim =
44 efl_canvas_object_event_animation_get(content,
45 EFL_GFX_ENTITY_EVENT_SHOW);
46
47 if (orig_show_anim)
48 efl_canvas_object_event_animation_set(content,
49 EFL_GFX_ENTITY_EVENT_SHOW,
50 NULL);
51
52 evas_object_raise(content); 43 evas_object_raise(content);
53 /* efl_ui_widget_resize_object_set() calls efl_gfx_entity_visible_set() 44 /* efl_ui_widget_resize_object_set() calls efl_gfx_entity_visible_set()
54 * internally. 45 * internally.
@@ -56,10 +47,6 @@ _show_content_without_anim(Efl_Ui_Stack *obj, Evas_Object *content)
56 * setting animation and efl_gfx_entity_visible_set() is not called. */ 47 * setting animation and efl_gfx_entity_visible_set() is not called. */
57 efl_ui_widget_resize_object_set(obj, content); 48 efl_ui_widget_resize_object_set(obj, content);
58 49
59 if (orig_show_anim)
60 efl_canvas_object_event_animation_set(content,
61 EFL_GFX_ENTITY_EVENT_SHOW,
62 orig_show_anim);
63 //Activated Event 50 //Activated Event
64 Efl_Ui_Stack_Event_Activated activated_info; 51 Efl_Ui_Stack_Event_Activated activated_info;
65 activated_info.content = content; 52 activated_info.content = content;
@@ -70,20 +57,7 @@ _show_content_without_anim(Efl_Ui_Stack *obj, Evas_Object *content)
70static void 57static void
71_hide_content_without_anim(Efl_Ui_Stack *obj EINA_UNUSED, Evas_Object *content) 58_hide_content_without_anim(Efl_Ui_Stack *obj EINA_UNUSED, Evas_Object *content)
72{ 59{
73 Efl_Canvas_Animation *orig_hide_anim =
74 efl_canvas_object_event_animation_get(content,
75 EFL_GFX_ENTITY_EVENT_HIDE);
76
77 if (orig_hide_anim)
78 efl_canvas_object_event_animation_set(content,
79 EFL_GFX_ENTITY_EVENT_HIDE, NULL);
80
81 efl_gfx_entity_visible_set(content, EINA_FALSE); 60 efl_gfx_entity_visible_set(content, EINA_FALSE);
82
83 if (orig_hide_anim)
84 efl_canvas_object_event_animation_set(content,
85 EFL_GFX_ENTITY_EVENT_HIDE,
86 orig_hide_anim);
87} 61}
88 62
89static void 63static void
@@ -98,7 +72,7 @@ _content_del_cb(void *data, const Efl_Event *event EINA_UNUSED)
98} 72}
99 73
100static Content_Data * 74static Content_Data *
101_content_data_new(Eo *obj, Eo *content) 75_content_data_new(Eo *obj EINA_UNUSED, Eo *content)
102{ 76{
103 Content_Data *cd = calloc(1, sizeof(Content_Data)); 77 Content_Data *cd = calloc(1, sizeof(Content_Data));
104 if (!cd) 78 if (!cd)
@@ -107,7 +81,6 @@ _content_data_new(Eo *obj, Eo *content)
107 return NULL; 81 return NULL;
108 } 82 }
109 83
110 cd->stack = obj;
111 cd->content = content; 84 cd->content = content;
112 85
113 efl_event_callback_add(cd->content, EFL_EVENT_DEL, _content_del_cb, cd); 86 efl_event_callback_add(cd->content, EFL_EVENT_DEL, _content_del_cb, cd);
@@ -129,106 +102,92 @@ _content_data_del(Content_Data *cd)
129static void 102static void
130_anim_started_cb(void *data EINA_UNUSED, const Efl_Event *event) 103_anim_started_cb(void *data EINA_UNUSED, const Efl_Event *event)
131{ 104{
132 efl_canvas_object_freeze_events_set(event->object, EINA_TRUE); 105 efl_canvas_object_freeze_events_set(efl_animation_player_target_get(event->object), EINA_TRUE);
133
134 efl_event_callback_del(event->object, EFL_CANVAS_OBJECT_EVENT_ANIM_STARTED,
135 _anim_started_cb, NULL);
136} 106}
137 107
138static void 108static Evas_Object*
139_anim_ended_cb(void *data, const Efl_Event *event) 109_end_anim(Transit_Data *td)
140{ 110{
141 Transit_Data *td = data; 111 Efl_Canvas_Object *content = td->cd->content;
142 Efl_Canvas_Object_Animation_Event *anim_event = event->info;
143
144 //Unset animation because originally there is no animation.
145 if (!td->orig_anim)
146 efl_canvas_object_event_animation_set(event->object,
147 anim_event->event_desc, NULL);
148
149 efl_canvas_object_freeze_events_set(event->object,
150 td->freeze_events);
151 112
113 efl_canvas_object_freeze_events_set(content, td->freeze_events);
152 td->cd->on_pushing = EINA_FALSE; 114 td->cd->on_pushing = EINA_FALSE;
153 td->cd->on_popping = EINA_FALSE; 115 td->cd->on_popping = EINA_FALSE;
116 free(td);
154 117
155 if (anim_event->event_desc == EFL_GFX_ENTITY_EVENT_SHOW) 118 return content;
156 { 119}
157 //Activated Event 120
158 Efl_Ui_Stack_Event_Activated activated_info; 121static void
159 activated_info.content = event->object; 122_hide_anim_ended_cb(void *data, const Efl_Event *event EINA_UNUSED)
160 efl_event_callback_call(td->cd->stack, 123{
161 EFL_UI_STACK_EVENT_ACTIVATED, 124 Efl_Ui_Stack_Data *pd = efl_data_scope_safe_get(data, EFL_UI_STACK_CLASS);
162 &activated_info); 125 Efl_Canvas_Object *content;
163 }
164 else
165 {
166 _announce_hiding(NULL, event->object);
167 }
168 126
169 efl_event_callback_del(event->object, EFL_CANVAS_OBJECT_EVENT_ANIM_ENDED, 127 content = _end_anim(pd->hide_td);
170 _anim_ended_cb, data); 128 pd->hide_td = NULL;
171 free(data); 129 efl_gfx_entity_visible_set(content, EINA_FALSE);
130 _announce_hiding(data, content);
172} 131}
173 132
174static void 133static void
175_show_content_with_anim(Efl_Ui_Stack *obj, Content_Data *cd) 134_show_anim_ended_cb(void *data, const Efl_Event *event EINA_UNUSED)
176{ 135{
177 Efl_Canvas_Animation *orig_show_anim = 136 Efl_Ui_Stack_Data *pd = efl_data_scope_safe_get(data, EFL_UI_STACK_CLASS);
178 efl_canvas_object_event_animation_get(cd->content, 137 Efl_Canvas_Object *content;
179 EFL_GFX_ENTITY_EVENT_SHOW);
180 138
181 //Show with animation 139 content = _end_anim(pd->show_td);
182 if (!orig_show_anim) 140 pd->show_td = NULL;
183 efl_canvas_object_event_animation_set(cd->content, 141 //Activated Event
184 EFL_GFX_ENTITY_EVENT_SHOW, 142 Efl_Ui_Stack_Event_Activated activated_info;
185 show_anim); 143 activated_info.content = content;
144 efl_event_callback_call(data,
145 EFL_UI_STACK_EVENT_ACTIVATED,
146 &activated_info);
147}
148
149static void
150_show_content_with_anim(Efl_Ui_Stack *obj, Efl_Ui_Stack_Data *pd, Content_Data *cd)
151{
152 //immidiatly stop hiding animation
153 efl_player_stop(pd->show);
154 if (pd->show_td)
155 EINA_SAFETY_ERROR("td is set but it should not");
156
157 //attach new content target
158 efl_animation_player_target_set(pd->show, cd->content);
186 159
187 Transit_Data *td = calloc(1, sizeof(Transit_Data)); 160 Transit_Data *td = calloc(1, sizeof(Transit_Data));
188 td->cd = cd; 161 td->cd = cd;
189 td->orig_anim = !!(orig_show_anim);
190 td->freeze_events = 162 td->freeze_events =
191 efl_canvas_object_freeze_events_get(cd->content); 163 efl_canvas_object_freeze_events_get(cd->content);
192 164 pd->show_td = td;
193 efl_event_callback_add(cd->content,
194 EFL_CANVAS_OBJECT_EVENT_ANIM_STARTED,
195 _anim_started_cb, NULL);
196 efl_event_callback_add(cd->content,
197 EFL_CANVAS_OBJECT_EVENT_ANIM_ENDED,
198 _anim_ended_cb, td);
199 165
200 /* efl_ui_widget_resize_object_set() calls efl_gfx_entity_visible_set() 166 /* efl_ui_widget_resize_object_set() calls efl_gfx_entity_visible_set()
201 * internally. 167 * internally.
202 * Therefore, efl_ui_widget_resize_object_set() is called after 168 * Therefore, efl_ui_widget_resize_object_set() is called after
203 * setting animation and efl_gfx_entity_visible_set() is not called. */ 169 * setting animation and efl_gfx_entity_visible_set() is not called. */
204 efl_ui_widget_resize_object_set(obj, cd->content); 170 efl_ui_widget_resize_object_set(obj, cd->content);
171 efl_player_start(pd->show);
205} 172}
206 173
207static void 174static void
208_hide_content_with_anim(Efl_Ui_Stack *obj EINA_UNUSED, Content_Data *cd) 175_hide_content_with_anim(Efl_Ui_Stack *obj EINA_UNUSED, Efl_Ui_Stack_Data *pd, Content_Data *cd)
209{ 176{
210 Efl_Canvas_Animation *orig_hide_anim = 177 //immidiatly stop hiding animation
211 efl_canvas_object_event_animation_get(cd->content, 178 efl_player_stop(pd->hide);
212 EFL_GFX_ENTITY_EVENT_HIDE); 179 if (pd->hide_td)
213 //Hide with animation. 180 EINA_SAFETY_ERROR("td is set but it should not");
214 if (!orig_hide_anim) 181
215 efl_canvas_object_event_animation_set(cd->content, 182 //attach new content target
216 EFL_GFX_ENTITY_EVENT_HIDE, 183 efl_animation_player_target_set(pd->hide, cd->content);
217 hide_anim);
218 184
219 Transit_Data *td = calloc(1, sizeof(Transit_Data)); 185 Transit_Data *td = calloc(1, sizeof(Transit_Data));
220 td->cd = cd; 186 td->cd = cd;
221 td->orig_anim = !!(orig_hide_anim);
222 td->freeze_events = efl_canvas_object_freeze_events_get(cd->content); 187 td->freeze_events = efl_canvas_object_freeze_events_get(cd->content);
188 pd->hide_td = td;
223 189
224 efl_event_callback_add(cd->content, 190 efl_player_start(pd->hide);
225 EFL_CANVAS_OBJECT_EVENT_ANIM_STARTED,
226 _anim_started_cb, NULL);
227 efl_event_callback_add(cd->content,
228 EFL_CANVAS_OBJECT_EVENT_ANIM_ENDED,
229 _anim_ended_cb, td);
230
231 efl_gfx_entity_visible_set(cd->content, EINA_FALSE);
232} 191}
233 192
234EOLIAN static void 193EOLIAN static void
@@ -287,7 +246,7 @@ _efl_ui_stack_push(Eo *obj, Efl_Ui_Stack_Data *pd, Eo *content)
287 { 246 {
288 top_cd->on_pushing = EINA_TRUE; 247 top_cd->on_pushing = EINA_TRUE;
289 248
290 _hide_content_with_anim(obj, top_cd); 249 _hide_content_with_anim(obj, pd, top_cd);
291 } 250 }
292 } 251 }
293 252
@@ -298,7 +257,7 @@ _efl_ui_stack_push(Eo *obj, Efl_Ui_Stack_Data *pd, Eo *content)
298 257
299 /* Apply transition to new content. 258 /* Apply transition to new content.
300 * Show new content with animation. */ 259 * Show new content with animation. */
301 _show_content_with_anim(obj, cd); 260 _show_content_with_anim(obj, pd, cd);
302} 261}
303 262
304static void 263static void
@@ -344,7 +303,7 @@ _efl_ui_stack_pop(Eo *obj, Efl_Ui_Stack_Data *pd)
344 efl_event_callback_add(top_content, EFL_GFX_ENTITY_EVENT_HIDE, 303 efl_event_callback_add(top_content, EFL_GFX_ENTITY_EVENT_HIDE,
345 _pop_content_hide_cb, top_cd); 304 _pop_content_hide_cb, top_cd);
346 305
347 _hide_content_with_anim(obj, top_cd); 306 _hide_content_with_anim(obj, pd, top_cd);
348 } 307 }
349 } 308 }
350 309
@@ -364,7 +323,7 @@ _efl_ui_stack_pop(Eo *obj, Efl_Ui_Stack_Data *pd)
364 323
365 /* Apply transition to previous content. 324 /* Apply transition to previous content.
366 * Show previous content with animation. */ 325 * Show previous content with animation. */
367 _show_content_with_anim(obj, prev_cd); 326 _show_content_with_anim(obj, pd, prev_cd);
368 } 327 }
369 328
370 return NULL; 329 return NULL;
@@ -673,24 +632,45 @@ _efl_ui_stack_top(Eo *obj EINA_UNUSED, Efl_Ui_Stack_Data *pd)
673 return cd->content; 632 return cd->content;
674} 633}
675 634
635EFL_CALLBACKS_ARRAY_DEFINE(_anim_show_event_cb,
636 {EFL_ANIMATION_PLAYER_EVENT_STARTED, _anim_started_cb},
637 {EFL_ANIMATION_PLAYER_EVENT_ENDED, _show_anim_ended_cb},
638)
639
640EFL_CALLBACKS_ARRAY_DEFINE(_anim_hide_event_cb,
641 {EFL_ANIMATION_PLAYER_EVENT_STARTED, _anim_started_cb},
642 {EFL_ANIMATION_PLAYER_EVENT_ENDED, _hide_anim_ended_cb},
643)
644
676EOLIAN static Eo * 645EOLIAN static Eo *
677_efl_ui_stack_efl_object_constructor(Eo *obj, Efl_Ui_Stack_Data *pd EINA_UNUSED) 646_efl_ui_stack_efl_object_constructor(Eo *obj, Efl_Ui_Stack_Data *pd EINA_UNUSED)
678{ 647{
648 Efl_Canvas_Animation *sh, *hi;
679 obj = efl_constructor(efl_super(obj, MY_CLASS)); 649 obj = efl_constructor(efl_super(obj, MY_CLASS));
680 efl_canvas_object_type_set(obj, MY_CLASS_NAME); 650 efl_canvas_object_type_set(obj, MY_CLASS_NAME);
681 651
682 //Default Show Animation 652 //Default Show Animation
683 show_anim = efl_add(EFL_CANVAS_ANIMATION_ALPHA_CLASS, obj); 653 sh = show_anim = efl_add(EFL_CANVAS_ANIMATION_ALPHA_CLASS, obj);
684 efl_animation_alpha_set(show_anim, 0.0, 1.0); 654 efl_animation_alpha_set(show_anim, 0.0, 1.0);
685 efl_animation_duration_set(show_anim, 0.5); 655 efl_animation_duration_set(show_anim, 0.5);
686 efl_animation_final_state_keep_set(show_anim, EINA_TRUE); 656 efl_animation_final_state_keep_set(show_anim, EINA_TRUE);
687 657
658 pd->show = efl_add(EFL_CANVAS_ANIMATION_PLAYER_CLASS, obj);
659 efl_animation_player_animation_set(pd->show, sh);
660 efl_player_play_set(pd->show, EINA_FALSE);
661 efl_event_callback_array_add(pd->show, _anim_show_event_cb(), obj);
662
688 //Default Hide Animation 663 //Default Hide Animation
689 hide_anim = efl_add(EFL_CANVAS_ANIMATION_ALPHA_CLASS, obj); 664 hi = hide_anim = efl_add(EFL_CANVAS_ANIMATION_ALPHA_CLASS, obj);
690 efl_animation_alpha_set(hide_anim, 1.0, 0.0); 665 efl_animation_alpha_set(hide_anim, 1.0, 0.0);
691 efl_animation_duration_set(hide_anim, 0.5); 666 efl_animation_duration_set(hide_anim, 0.5);
692 efl_animation_final_state_keep_set(hide_anim, EINA_TRUE); 667 efl_animation_final_state_keep_set(hide_anim, EINA_TRUE);
693 668
669 pd->hide = efl_add(EFL_CANVAS_ANIMATION_PLAYER_CLASS, obj);
670 efl_animation_player_animation_set(pd->hide, hi);
671 efl_player_play_set(pd->hide, EINA_FALSE);
672 efl_event_callback_array_add(pd->hide, _anim_hide_event_cb(), obj);
673
694 return obj; 674 return obj;
695} 675}
696 676
diff --git a/src/lib/elementary/efl_ui_stack_private.h b/src/lib/elementary/efl_ui_stack_private.h
index dc67451d58..b6b32f8e6e 100644
--- a/src/lib/elementary/efl_ui_stack_private.h
+++ b/src/lib/elementary/efl_ui_stack_private.h
@@ -1,18 +1,12 @@
1#ifndef EFL_UI_WIDGET_STACK_H 1#ifndef EFL_UI_WIDGET_STACK_H
2#define EFL_UI_WIDGET_STACK_H 2#define EFL_UI_WIDGET_STACK_H
3 3
4typedef struct _Efl_Ui_Stack_Data Efl_Ui_Stack_Data;
5struct _Efl_Ui_Stack_Data
6{
7 Eina_Inlist *stack; /* the last item is the top item */
8};
9 4
10typedef struct _Content_Data Content_Data; 5typedef struct _Content_Data Content_Data;
11struct _Content_Data 6struct _Content_Data
12{ 7{
13 EINA_INLIST; 8 EINA_INLIST;
14 9
15 Eo *stack;
16 Eo *content; 10 Eo *content;
17 Eina_Bool on_pushing : 1; 11 Eina_Bool on_pushing : 1;
18 Eina_Bool on_popping : 1; 12 Eina_Bool on_popping : 1;
@@ -23,8 +17,16 @@ typedef struct _Transit_Data Transit_Data;
23struct _Transit_Data 17struct _Transit_Data
24{ 18{
25 Content_Data *cd; 19 Content_Data *cd;
26 Eina_Bool orig_anim;
27 Eina_Bool freeze_events; 20 Eina_Bool freeze_events;
28}; 21};
29 22
23typedef struct _Efl_Ui_Stack_Data Efl_Ui_Stack_Data;
24struct _Efl_Ui_Stack_Data
25{
26 Eina_Inlist *stack; /* the last item is the top item */
27 Efl_Canvas_Animation_Player *hide, *show;
28 Transit_Data *show_td, *hide_td;
29
30};
31
30#endif 32#endif